Minor updates:

GraphicsObject - corrected bug in viewPos() method
  WidgetGroup - allow bound methods in interfaces
  parametertree - fixed crash when calling remove from context menu
This commit is contained in:
Luke Campagnola 2012-03-19 23:02:29 -04:00
parent f80b73b173
commit 48929a2aa6
4 changed files with 28 additions and 5 deletions

View File

@ -255,7 +255,14 @@ class WidgetGroup(QtCore.QObject):
if getFunc is None:
return None
## 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]
## 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))

View File

@ -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)

View File

@ -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)

View File

@ -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)