From 48929a2aa673e8574680f04b5928614e21797691 Mon Sep 17 00:00:00 2001 From: Luke Campagnola <> Date: Mon, 19 Mar 2012 23:02:29 -0400 Subject: [PATCH] Minor updates: GraphicsObject - corrected bug in viewPos() method WidgetGroup - allow bound methods in interfaces parametertree - fixed crash when calling remove from context menu --- WidgetGroup.py | 19 +++++++++++++++++-- graphicsItems/GraphicsItemMethods.py | 2 +- parametertree/Parameter.py | 4 ++++ parametertree/ParameterItem.py | 8 ++++++-- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/WidgetGroup.py b/WidgetGroup.py index 32b952e6..48a3778e 100644 --- a/WidgetGroup.py +++ b/WidgetGroup.py @@ -255,7 +255,14 @@ class WidgetGroup(QtCore.QObject): if getFunc is None: return None - val = getFunc(w) + ## if the getter function provided in the interface is a bound method, + ## then just call the method directly. Otherwise, pass in the widget as the first arg + ## to the function. + if inspect.ismethod(getFunc) and getFunc.im_self is not None: + val = getFunc() + else: + val = getFunc(w) + if self.scales[w] is not None: val /= self.scales[w] #if isinstance(val, QtCore.QString): @@ -273,7 +280,15 @@ class WidgetGroup(QtCore.QObject): setFunc = WidgetGroup.classes[type(w)][2] else: setFunc = w.widgetGroupInterface()[2] - setFunc(w, v) + + ## if the setter function provided in the interface is a bound method, + ## then just call the method directly. Otherwise, pass in the widget as the first arg + ## to the function. + if inspect.ismethod(setFunc) and setFunc.im_self is not None: + setFunc(v) + else: + setFunc(w, v) + #name = self.widgetList[w] #if name in self.cache and (self.cache[name] != v1): #print "%s: Cached value %s != set value %s" % (name, str(self.cache[name]), str(v1)) diff --git a/graphicsItems/GraphicsItemMethods.py b/graphicsItems/GraphicsItemMethods.py index 0d8e9fca..ca9c7a43 100644 --- a/graphicsItems/GraphicsItemMethods.py +++ b/graphicsItems/GraphicsItemMethods.py @@ -229,7 +229,7 @@ class GraphicsItemMethods(object): return Point(QtGui.QGraphicsObject.pos(self)) def viewPos(self): - return self.mapToView(self.pos()) + return self.mapToView(self.mapFromParent(self.pos())) #def itemChange(self, change, value): #ret = QtGui.QGraphicsObject.itemChange(self, change, value) diff --git a/parametertree/Parameter.py b/parametertree/Parameter.py index 39edb880..e10147fd 100644 --- a/parametertree/Parameter.py +++ b/parametertree/Parameter.py @@ -284,6 +284,10 @@ class Parameter(QtCore.QObject): for ch in self.childs[:]: self.removeChild(ch) + def children(self): + ## warning -- this overrides QObject.children + return self.childs[:] + def parentChanged(self, parent): self._parent = parent self.sigParentChanged.emit(self, parent) diff --git a/parametertree/ParameterItem.py b/parametertree/ParameterItem.py index 605e6317..7c0db075 100644 --- a/parametertree/ParameterItem.py +++ b/parametertree/ParameterItem.py @@ -38,7 +38,7 @@ class ParameterItem(QtGui.QTreeWidgetItem): flags |= QtCore.Qt.ItemIsEditable self.contextMenu.addAction('Rename').triggered.connect(self.editName) if opts.get('removable', False): - self.contextMenu.addAction("Remove").triggered.connect(self.param.remove) + self.contextMenu.addAction("Remove").triggered.connect(self.requestRemove) ## handle movable / dropEnabled options if opts.get('movable', False): @@ -144,5 +144,9 @@ class ParameterItem(QtGui.QTreeWidgetItem): """Called when this item has been selected (sel=True) OR deselected (sel=False)""" pass - + def requestRemove(self): + ## called when remove is selected from the context menu. + ## we need to delay removal until the action is complete + ## since destroying the menu in mid-action will cause a crash. + QtCore.QTimer.singleShot(0, self.param.remove)