deprecate GraphicsObject::parentChanged method#2420
Conversation
|
The detection only works for the simplest case where the method is at the last level in an inheritance hierarchy. |
|
Based on a search of the repo, #1991 led me to https://github.com/sem-geologist/HussariX/blob/master/lib/ui/CustomPGWidgets.py#L98 which has a class that subclasses |
|
@sem-geologist has been active in the issue tracker here before; hopefully this ping will get their attention |
|
The detection would think that CustomScaleBar doesn't use the deprecated method parentChanged, not knowing whether any parent class does override. It would then call self.parentChanged_() which would correctly invoke ScaleBar::parentChanged_(). It works in this case only because the parent (pyqtgraph) class was updated to use parentChanged_(). |
|
Hi @pijyoi Thanks for the PR!. The diff looks good to me, but I'm a little hung up on the name, |
1212d30 to
f6487c2
Compare
|
A contrived example where the current detection technique fails. import pyqtgraph as pg
from pyqtgraph.Qt import QtCore
class CustomParent(pg.GraphicsObject):
def __init__(self):
pg.GraphicsObject.__init__(self)
self.text = "OLD PARENT"
def boundingRect(self):
return QtCore.QRectF(0, 0, 100, 100)
def paint(self, p, *args):
p.setPen(pg.mkPen('w'))
p.drawText(0, 50, self.text)
def parentChanged(self):
self.text = "NEW PARENT"
class CustomChild(CustomParent):
def __init__(self):
CustomParent.__init__(self)
self.text = "CHILD"
pg.mkQApp()
pw = pg.PlotWidget()
pw.show()
custom = CustomChild()
pw.addItem(custom)
pg.exec() |
|
Maybe I have the wrong attitude about this, but I'm not so concerned about catching every usage of this method... this method is buried fairly deep in the library, and I wouldn't imagine that many end-users overwriting it... Anyway, I'm fine w/ the current code diff. |
QGraphicsObject has a signal named parentChanged
f6487c2 to
9b8add7
Compare
|
I am generally unfamiliar with all the viewbox machinery. The docstring for Maybe merge this "breaking" change after 0.13.0? |
|
Since we just released 0.13.0, let's merge this one! Thanks for your work here @pijyoi |
QGraphicsObject has a signal named
parentChanged.Although Qt bindings "permit" a method name to be the same as a Qt signal name, it may not be a good idea to make use of this "feature".
This "feature" has been broken before: #2132
It also relies on the inheritance order of the parent classes of
GraphicsObject.This PR renames the method name while emitting a deprecation warning if it detects that the old name is being used by user sub-classes.
One way to test out this PR is to modify
examples/customGraphicsItem.py.By adding the following method:
We can verify that running this example with
python -Wdefaultemits a deprecation warning.