enforce enableMenu in ViewBox

This commit is contained in:
danielhrisca 2019-01-16 17:04:06 +02:00
parent 2e69b9c5e6
commit 5a53539be0

View File

@ -208,7 +208,10 @@ class ViewBox(GraphicsWidget):
self.setAspectLocked(lockAspect)
self.border = fn.mkPen(border)
if enableMenu:
self.menu = ViewBoxMenu(self)
else:
self.menu = None
self.register(name)
if name is None:
@ -315,6 +318,13 @@ class ViewBox(GraphicsWidget):
del state['linkedViews']
self.state.update(state)
if self.state['enableMenu'] and self.menu is None:
self.menu = ViewBoxMenu(self)
self.updateViewLists()
else:
self.menu = None
self.updateViewRange()
self.sigStateChanged.emit(self)
@ -368,6 +378,13 @@ class ViewBox(GraphicsWidget):
def setMenuEnabled(self, enableMenu=True):
self.state['enableMenu'] = enableMenu
if enableMenu:
if self.menu is None:
self.menu = ViewBoxMenu(self)
self.updateViewLists()
else:
self.menu.setParent(None)
self.menu = None
self.sigStateChanged.emit(self)
def menuEnabled(self):
@ -1146,6 +1163,7 @@ class ViewBox(GraphicsWidget):
def raiseContextMenu(self, ev):
menu = self.getMenu(ev)
if menu is not None:
self.scene().addParentContextMenus(self, menu, ev)
menu.popup(ev.screenPos().toPoint())
@ -1566,6 +1584,7 @@ class ViewBox(GraphicsWidget):
if self in nv:
nv.remove(self)
if self.menu is not None:
self.menu.setViewList(nv)
for ax in [0,1]: