Move common code to _applyEnableMenu

This commit is contained in:
Ales Erjavec 2019-11-06 10:58:00 +01:00
parent a84953530f
commit 50cf2f561f

View File

@ -321,13 +321,7 @@ class ViewBox(GraphicsWidget):
self.state.update(state)
if self.state['enableMenu'] and self.menu is None:
self.menu = ViewBoxMenu(self)
self.updateViewLists()
elif not self.state['enableMenu'] and self.menu is not None:
self.menu.setParent(None)
self.menu = None
self._applyMenuEnabled()
self.updateViewRange()
self.sigStateChanged.emit(self)
@ -381,16 +375,20 @@ class ViewBox(GraphicsWidget):
def setMenuEnabled(self, enableMenu=True):
self.state['enableMenu'] = enableMenu
self._applyMenuEnabled()
self.sigStateChanged.emit(self)
def menuEnabled(self):
return self.state.get('enableMenu', True)
def _applyMenuEnabled(self):
enableMenu = self.state.get("enableMenu", True)
if enableMenu and self.menu is None:
self.menu = ViewBoxMenu(self)
self.updateViewLists()
elif not enableMenu and self.menu is not None:
self.menu.setParent(None)
self.menu = None
self.sigStateChanged.emit(self)
def menuEnabled(self):
return self.state.get('enableMenu', True)
def addItem(self, item, ignoreBounds=False):
"""