diff options
Diffstat (limited to 'silx/gui/plot/StatsWidget.py')
-rw-r--r-- | silx/gui/plot/StatsWidget.py | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/silx/gui/plot/StatsWidget.py b/silx/gui/plot/StatsWidget.py index 5e2dc58..52b7e5c 100644 --- a/silx/gui/plot/StatsWidget.py +++ b/silx/gui/plot/StatsWidget.py @@ -424,7 +424,7 @@ class _StatsWidgetBase(object): if self._displayOnlyActItem: connections.append( - (self._plotWrapper.sigCurrentChanged, self._updateItemObserve)) + (self._plotWrapper.sigCurrentChanged, self._updateCurrentItem)) else: connections += [ (self._plotWrapper.sigItemAdded, self._addItem), @@ -441,6 +441,11 @@ class _StatsWidgetBase(object): """Reload table depending on mode""" raise NotImplementedError('Base class') + def _updateCurrentItem(self, *args): + """specific callback for the sigCurrentChanged and with the + _displayOnlyActItem option.""" + raise NotImplementedError('Base class') + def _updateStats(self, item): """Update displayed information for given plot item @@ -643,8 +648,6 @@ class StatsTable(_StatsWidgetBase, TableWidget): def _updateItemObserve(self, *args): """Reload table depending on mode""" - if self.getUpdateMode() is UpdateMode.MANUAL: - return self._removeAllItems() # Get selected or all items from the plot @@ -657,6 +660,27 @@ class StatsTable(_StatsWidgetBase, TableWidget): for item in items: self._addItem(item) + def _updateCurrentItem(self, *args): + """specific callback for the sigCurrentChanged and with the + _displayOnlyActItem option. + + Behavior: create the tableItems if does not exists. + If exists, update it only when we are in 'auto' mode""" + if self.getUpdateMode() is UpdateMode.MANUAL: + # when sigCurrentChanged is giving the current item + if len(args) > 0 and isinstance(args[0], (plotitems.Curve, plotitems.Histogram, plotitems.ImageData, plotitems.Scatter)): + item = args[0] + tableItems = self._itemToTableItems(item) + # if the table does not exists yet + if len(tableItems) == 0: + self._updateItemObserve() + else: + # in this case no current item + self._updateItemObserve(args) + else: + # auto mode + self._updateItemObserve(args) + def _plotCurrentChanged(self, current): """Handle change of current item and update selection in table @@ -1323,6 +1347,7 @@ class _BaseLineStatsWidget(_StatsWidgetBase, qt.QWidget): def setStats(self, statsHandler): """Set which stats to display and the associated formatting. + :param StatsHandler statsHandler: Set the statistics to be displayed and how to format them using """ @@ -1391,6 +1416,9 @@ class _BaseLineStatsWidget(_StatsWidgetBase, qt.QWidget): _item = items[0] if len(items) is 1 else None self._setItem(_item) + def _updateCurrentItem(self): + self._updateItemObserve() + def _createLayout(self): """create an instance of the main QLayout""" raise NotImplementedError('Base class') @@ -1541,12 +1569,12 @@ class BasicGridStatsWidget(qt.QWidget): only visible ones. :param int statsPerLine: number of statistic to be displayed per line - .. snapshotqt:: img/_BasicGridStatsWidget.png + .. snapshotqt:: img/BasicGridStatsWidget.png :width: 600px :align: center from silx.gui.plot import Plot1D - from silx.gui.plot.StatsWidget import _BasicGridStatsWidget + from silx.gui.plot.StatsWidget import BasicGridStatsWidget plot = Plot1D() x = range(100) @@ -1554,7 +1582,7 @@ class BasicGridStatsWidget(qt.QWidget): plot.addCurve(x, y, legend='curve_0') plot.setActiveCurve('curve_0') - widget = _BasicGridStatsWidget(plot=plot, kind='curve') + widget = BasicGridStatsWidget(plot=plot, kind='curve') widget.show() """ |