Merge pull request #814 from danielhrisca/enforce_enableMenu

enforce enableMenu in ViewBox
This commit is contained in:
Ogi Moore 2019-05-23 23:22:52 -07:00 committed by GitHub
commit 66604593c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -208,7 +208,10 @@ class ViewBox(GraphicsWidget):
self.setAspectLocked(lockAspect) self.setAspectLocked(lockAspect)
self.border = fn.mkPen(border) self.border = fn.mkPen(border)
if enableMenu:
self.menu = ViewBoxMenu(self) self.menu = ViewBoxMenu(self)
else:
self.menu = None
self.register(name) self.register(name)
if name is None: if name is None:
@ -315,6 +318,13 @@ class ViewBox(GraphicsWidget):
del state['linkedViews'] del state['linkedViews']
self.state.update(state) 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.updateViewRange()
self.sigStateChanged.emit(self) self.sigStateChanged.emit(self)
@ -368,6 +378,13 @@ class ViewBox(GraphicsWidget):
def setMenuEnabled(self, enableMenu=True): def setMenuEnabled(self, enableMenu=True):
self.state['enableMenu'] = enableMenu 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) self.sigStateChanged.emit(self)
def menuEnabled(self): def menuEnabled(self):
@ -1149,6 +1166,7 @@ class ViewBox(GraphicsWidget):
def raiseContextMenu(self, ev): def raiseContextMenu(self, ev):
menu = self.getMenu(ev) menu = self.getMenu(ev)
if menu is not None:
self.scene().addParentContextMenus(self, menu, ev) self.scene().addParentContextMenus(self, menu, ev)
menu.popup(ev.screenPos().toPoint()) menu.popup(ev.screenPos().toPoint())
@ -1569,6 +1587,7 @@ class ViewBox(GraphicsWidget):
if self in nv: if self in nv:
nv.remove(self) nv.remove(self)
if self.menu is not None:
self.menu.setViewList(nv) self.menu.setViewList(nv)
for ax in [0,1]: for ax in [0,1]: