Use actions of ViewBox's contextMenu in full menu.
The main change is on `ViewBox.getContextMenus`, which now returns an up-to-date of actions that `GraphicsScene.addParentContextMenus` can use. Also, `getContextMenus` was given a default implementation in the base class (falling back on `getMenu` if defined), and some cleanup was done.
This commit is contained in:
parent
5b905cde8b
commit
23a0d6d7c0
@ -520,27 +520,18 @@ class GraphicsScene(QtGui.QGraphicsScene):
|
|||||||
============== ==================================================
|
============== ==================================================
|
||||||
"""
|
"""
|
||||||
|
|
||||||
#items = self.itemsNearEvent(ev)
|
|
||||||
menusToAdd = []
|
menusToAdd = []
|
||||||
while item is not self:
|
while item is not self:
|
||||||
item = item.parentItem()
|
item = item.parentItem()
|
||||||
|
|
||||||
if item is None:
|
if item is None:
|
||||||
item = self
|
item = self
|
||||||
|
subMenus = item.getContextMenus(event) or []
|
||||||
|
if isinstance(subMenus, list): ## so that some items (like FlowchartViewBox) can return multiple menus
|
||||||
|
menusToAdd.extend(subMenus)
|
||||||
|
else:
|
||||||
|
menusToAdd.append(subMenus)
|
||||||
|
|
||||||
if not hasattr(item, "getContextMenus"):
|
if menusToAdd:
|
||||||
continue
|
|
||||||
|
|
||||||
subMenus = item.getContextMenus(event)
|
|
||||||
if subMenus is None:
|
|
||||||
continue
|
|
||||||
if type(subMenus) is not list: ## so that some items (like FlowchartViewBox) can return multiple menus
|
|
||||||
subMenus = [subMenus]
|
|
||||||
|
|
||||||
for sm in subMenus:
|
|
||||||
menusToAdd.append(sm)
|
|
||||||
|
|
||||||
if len(menusToAdd) > 0:
|
|
||||||
menu.addSeparator()
|
menu.addSeparator()
|
||||||
|
|
||||||
for m in menusToAdd:
|
for m in menusToAdd:
|
||||||
|
@ -618,9 +618,6 @@ class NodeGraphicsItem(GraphicsObject):
|
|||||||
def getMenu(self):
|
def getMenu(self):
|
||||||
return self.menu
|
return self.menu
|
||||||
|
|
||||||
def getContextMenus(self, event):
|
|
||||||
return [self.menu]
|
|
||||||
|
|
||||||
def raiseContextMenu(self, ev):
|
def raiseContextMenu(self, ev):
|
||||||
menu = self.scene().addParentContextMenus(self, self.getMenu(), ev)
|
menu = self.scene().addParentContextMenus(self, self.getMenu(), ev)
|
||||||
pos = ev.screenPos()
|
pos = ev.screenPos()
|
||||||
|
@ -437,10 +437,6 @@ class TerminalGraphicsItem(GraphicsObject):
|
|||||||
multi = self.menu.multiAct.isChecked()
|
multi = self.menu.multiAct.isChecked()
|
||||||
self.term.setMultiValue(multi)
|
self.term.setMultiValue(multi)
|
||||||
|
|
||||||
## probably never need this
|
|
||||||
#def getContextMenus(self, ev):
|
|
||||||
#return [self.getMenu()]
|
|
||||||
|
|
||||||
def removeSelf(self):
|
def removeSelf(self):
|
||||||
self.term.node().removeTerminal(self.term)
|
self.term.node().removeTerminal(self.term)
|
||||||
|
|
||||||
|
@ -585,3 +585,6 @@ class GraphicsItem(object):
|
|||||||
#def update(self):
|
#def update(self):
|
||||||
#self._qtBaseClass.update(self)
|
#self._qtBaseClass.update(self)
|
||||||
#print "Update:", self
|
#print "Update:", self
|
||||||
|
|
||||||
|
def getContextMenus(self, event):
|
||||||
|
return [self.getMenu()] if hasattr(self, "getMenu") else []
|
||||||
|
@ -1203,10 +1203,6 @@ class Handle(UIGraphicsItem):
|
|||||||
def getMenu(self):
|
def getMenu(self):
|
||||||
return self.menu
|
return self.menu
|
||||||
|
|
||||||
|
|
||||||
def getContextMenus(self, event):
|
|
||||||
return [self.menu]
|
|
||||||
|
|
||||||
def raiseContextMenu(self, ev):
|
def raiseContextMenu(self, ev):
|
||||||
menu = self.scene().addParentContextMenus(self, self.getMenu(), ev)
|
menu = self.scene().addParentContextMenus(self, self.getMenu(), ev)
|
||||||
|
|
||||||
|
@ -1064,12 +1064,7 @@ class ViewBox(GraphicsWidget):
|
|||||||
return self.menu
|
return self.menu
|
||||||
|
|
||||||
def getContextMenus(self, event):
|
def getContextMenus(self, event):
|
||||||
if self.menuEnabled():
|
return self.menu.actions() if self.menuEnabled() else []
|
||||||
return self.menu.subMenus()
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
#return [self.getMenu(event)]
|
|
||||||
|
|
||||||
|
|
||||||
def mouseDragEvent(self, ev, axis=None):
|
def mouseDragEvent(self, ev, axis=None):
|
||||||
## if axis is specified, event will only affect that axis.
|
## if axis is specified, event will only affect that axis.
|
||||||
|
@ -88,22 +88,6 @@ class ViewBoxMenu(QtGui.QMenu):
|
|||||||
|
|
||||||
self.updateState()
|
self.updateState()
|
||||||
|
|
||||||
#def copy(self):
|
|
||||||
#m = QtGui.QMenu()
|
|
||||||
#for sm in self.subMenus():
|
|
||||||
#if isinstance(sm, QtGui.QMenu):
|
|
||||||
#m.addMenu(sm)
|
|
||||||
#else:
|
|
||||||
#m.addAction(sm)
|
|
||||||
#m.setTitle(self.title())
|
|
||||||
#return m
|
|
||||||
|
|
||||||
def subMenus(self):
|
|
||||||
if not self.valid:
|
|
||||||
self.updateState()
|
|
||||||
return [self.viewAll] + self.axes + [self.leftMenu]
|
|
||||||
|
|
||||||
|
|
||||||
def setExportMethods(self, methods):
|
def setExportMethods(self, methods):
|
||||||
self.exportMethods = methods
|
self.exportMethods = methods
|
||||||
self.export.clear()
|
self.export.clear()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user