Merge pull request #1063 from ales-erjavec/view-box-enable-menu-fix
Fix: AttributeError in ViewBox.setEnableMenu
This commit is contained in:
commit
a8d1a84870
@ -322,12 +322,7 @@ class ViewBox(GraphicsWidget):
|
||||
|
||||
self.state.update(state)
|
||||
|
||||
if self.state['enableMenu'] and self.menu is None:
|
||||
self.menu = ViewBoxMenu(self)
|
||||
self.updateViewLists()
|
||||
else:
|
||||
self.menu = None
|
||||
|
||||
self._applyMenuEnabled()
|
||||
self.updateViewRange()
|
||||
self.sigStateChanged.emit(self)
|
||||
|
||||
@ -381,18 +376,21 @@ 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._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
|
||||
|
||||
def addItem(self, item, ignoreBounds=False):
|
||||
"""
|
||||
Add a QGraphicsItem to this view. The view will include this item when determining how to set its range
|
||||
|
@ -74,6 +74,14 @@ def test_ViewBox():
|
||||
win.close()
|
||||
|
||||
|
||||
def test_ViewBox_setMenuEnabled():
|
||||
init_viewbox()
|
||||
vb.setMenuEnabled(True)
|
||||
assert vb.menu is not None
|
||||
vb.setMenuEnabled(False)
|
||||
assert vb.menu is None
|
||||
|
||||
|
||||
skipreason = "Skipping this test until someone has time to fix it."
|
||||
@pytest.mark.skipif(True, reason=skipreason)
|
||||
def test_limits_and_resize():
|
||||
|
Loading…
Reference in New Issue
Block a user