Commit 23a0d6d7 authored by Antony Lee's avatar Antony Lee
Browse files

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.
parent 5b905cde
......@@ -489,7 +489,7 @@ class GraphicsScene(QtGui.QGraphicsScene):
#return v
#else:
#return widget
def addParentContextMenus(self, item, menu, event):
"""
Can be called by any item in the scene to expand its context menu to include parent context menus.
......@@ -519,30 +519,21 @@ class GraphicsScene(QtGui.QGraphicsScene):
event The original event that triggered the menu to appear.
============== ==================================================
"""
#items = self.itemsNearEvent(ev)
menusToAdd = []
while item is not self:
item = item.parentItem()
if item is None:
item = self
if not hasattr(item, "getContextMenus"):
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:
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 menusToAdd:
menu.addSeparator()
for m in menusToAdd:
if isinstance(m, QtGui.QMenu):
menu.addMenu(m)
......
......@@ -617,9 +617,6 @@ class NodeGraphicsItem(GraphicsObject):
def getMenu(self):
return self.menu
def getContextMenus(self, event):
return [self.menu]
def raiseContextMenu(self, ev):
menu = self.scene().addParentContextMenus(self, self.getMenu(), ev)
......
......@@ -436,10 +436,6 @@ class TerminalGraphicsItem(GraphicsObject):
def toggleMulti(self):
multi = self.menu.multiAct.isChecked()
self.term.setMultiValue(multi)
## probably never need this
#def getContextMenus(self, ev):
#return [self.getMenu()]
def removeSelf(self):
self.term.node().removeTerminal(self.term)
......
......@@ -585,3 +585,6 @@ class GraphicsItem(object):
#def update(self):
#self._qtBaseClass.update(self)
#print "Update:", self
def getContextMenus(self, event):
return [self.getMenu()] if hasattr(self, "getMenu") else []
......@@ -1202,11 +1202,7 @@ class Handle(UIGraphicsItem):
def getMenu(self):
return self.menu
def getContextMenus(self, event):
return [self.menu]
def raiseContextMenu(self, ev):
menu = self.scene().addParentContextMenus(self, self.getMenu(), ev)
......
......@@ -1064,12 +1064,7 @@ class ViewBox(GraphicsWidget):
return self.menu
def getContextMenus(self, event):
if self.menuEnabled():
return self.menu.subMenus()
else:
return None
#return [self.getMenu(event)]
return self.menu.actions() if self.menuEnabled() else []
def mouseDragEvent(self, ev, axis=None):
## if axis is specified, event will only affect that axis.
......
......@@ -88,22 +88,6 @@ class ViewBoxMenu(QtGui.QMenu):
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):
self.exportMethods = methods
self.export.clear()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment