Fix: updateDecimate should not unhide intentionaly hidden curves (#1973)
* Update PlotItem.py make update decimate to not unhide curves when items added/removed, while preserving the Max Traces well behaviour * Update PlotItem.py fix typo * Update PlotItem.py fix: typo with self as argument * give better name for the function which handles MaxTraces checkstate change rename it to _handle_max_traces_toggle * add doc string to updateDecimation * add test for PlotItem for external curve visibility control check if hidden curve would stay hidden when adding or removing other items. * remove additional empty line between methods
This commit is contained in:
parent
2a66460afc
commit
745b04baa5
@ -240,7 +240,7 @@ class PlotItem(GraphicsWidget):
|
||||
self.ctrl.avgParamList.itemClicked.connect(self.avgParamListClicked)
|
||||
self.ctrl.averageGroup.toggled.connect(self.avgToggled)
|
||||
|
||||
self.ctrl.maxTracesCheck.toggled.connect(self.updateDecimation)
|
||||
self.ctrl.maxTracesCheck.toggled.connect(self._handle_max_traces_toggle)
|
||||
self.ctrl.forgetTracesCheck.toggled.connect(self.updateDecimation)
|
||||
self.ctrl.maxTracesSpin.valueChanged.connect(self.updateDecimation)
|
||||
|
||||
@ -1002,10 +1002,27 @@ class PlotItem(GraphicsWidget):
|
||||
|
||||
def clipToViewMode(self):
|
||||
return self.ctrl.clipToViewCheck.isChecked()
|
||||
|
||||
|
||||
def _handle_max_traces_toggle(self, check_state):
|
||||
if check_state:
|
||||
self.updateDecimation()
|
||||
else:
|
||||
for curve in self.curves:
|
||||
curve.show()
|
||||
|
||||
def updateDecimation(self):
|
||||
"""Reduce or increase number of visible curves depending from Max Traces spinner value
|
||||
if Max Traces is checked in the context menu. Destroy not visible curves if forget traces
|
||||
is checked. This function is called in most cases automaticaly when Max Traces GUI elements
|
||||
are triggered. Also it is auto-called when state of PlotItem is updated, state restored
|
||||
or new items being added/removed.
|
||||
|
||||
This can cause unexpected/conflicting state of curve visibility (or destruction) if curve
|
||||
visibilities are controlled externaly. In case of external control it is adviced to disable
|
||||
the Max Traces checkbox (or context menu) to prevent user from the unexpected
|
||||
curve state change."""
|
||||
if not self.ctrl.maxTracesCheck.isChecked():
|
||||
numCurves = len(self.curves)
|
||||
return
|
||||
else:
|
||||
numCurves = self.ctrl.maxTracesSpin.value()
|
||||
|
||||
|
@ -54,6 +54,18 @@ def test_PlotItem_maxTraces():
|
||||
assert curve1 not in item.curves, "curve1 should not be in the item's curves"
|
||||
|
||||
|
||||
def test_PlotItem_preserve_external_visibility_control():
|
||||
item = pg.PlotItem()
|
||||
curve1 = pg.PlotDataItem(np.random.normal(size=10))
|
||||
curve2 = pg.PlotDataItem(np.random.normal(size=10))
|
||||
item.addItem(curve1)
|
||||
curve1.hide()
|
||||
item.addItem(curve2)
|
||||
assert not curve1.isVisible()
|
||||
item.removeItem(curve2)
|
||||
assert not curve1.isVisible()
|
||||
|
||||
|
||||
def test_plotitem_menu_initialize():
|
||||
"""Test the menu initialization of the plotitem"""
|
||||
item = pg.PlotItem()
|
||||
|
Loading…
Reference in New Issue
Block a user