From 50cf2f561f10e0ff88d767a4f03c4d48ec530115 Mon Sep 17 00:00:00 2001 From: Ales Erjavec Date: Wed, 6 Nov 2019 10:58:00 +0100 Subject: [PATCH] Move common code to _applyEnableMenu --- pyqtgraph/graphicsItems/ViewBox/ViewBox.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/pyqtgraph/graphicsItems/ViewBox/ViewBox.py b/pyqtgraph/graphicsItems/ViewBox/ViewBox.py index a12eb519..27e64b56 100644 --- a/pyqtgraph/graphicsItems/ViewBox/ViewBox.py +++ b/pyqtgraph/graphicsItems/ViewBox/ViewBox.py @@ -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): """