PlotItem: Fix enableMenu setting when passing a viewbox (#1496)

* PlotItem: enableMenu setting when passing a viewbox
This commit is contained in:
Dennis Göries 2021-01-13 05:34:14 +01:00 committed by GitHub
parent 386dcf8180
commit 2affe322ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 3 deletions

View File

@ -134,12 +134,14 @@ class PlotItem(GraphicsWidget):
self.setLayout(self.layout)
self.layout.setHorizontalSpacing(0)
self.layout.setVerticalSpacing(0)
if viewBox is None:
viewBox = ViewBox(parent=self)
viewBox = ViewBox(parent=self, enableMenu=enableMenu)
self.vb = viewBox
self.vb.sigStateChanged.connect(self.viewStateChanged)
self.setMenuEnabled(enableMenu, enableMenu) ## en/disable plotitem and viewbox menus
# Enable or disable plotItem menu
self.setMenuEnabled(enableMenu, None)
if name is not None:
self.vb.register(name)

View File

@ -21,3 +21,36 @@ def test_PlotItem_shared_axis_items(orientation):
with pytest.raises(RuntimeError):
pi2.setAxisItems({orientation: ax1})
def test_plotitem_menu_initialize():
"""Test the menu initialization of the plotitem"""
item = pg.PlotItem()
assert item.menuEnabled() is True
viewbox = item.vb
assert viewbox is not None
assert viewbox.menu is not None
assert viewbox.menuEnabled() is True
item = pg.PlotItem(enableMenu=False)
assert item.menuEnabled() is False
viewbox = item.vb
assert viewbox is not None
assert viewbox.menu is None
assert viewbox.menuEnabled() is False
viewbox = pg.ViewBox()
item = pg.PlotItem(viewBox=viewbox, enableMenu=False)
assert item.menuEnabled() is False
viewbox = item.vb
assert viewbox is not None
assert viewbox.menu is not None
assert viewbox.menuEnabled() is True
viewbox = pg.ViewBox(enableMenu=False)
item = pg.PlotItem(viewBox=viewbox)
assert item.menuEnabled() is True
viewbox = item.vb
assert viewbox is not None
assert viewbox.menu is None
assert viewbox.menuEnabled() is False