Skip to content

Commit

Permalink
rework the handling of UpdateMode
Browse files Browse the repository at this point in the history
  • Loading branch information
t20100 authored and payno committed May 20, 2019
1 parent 13c4491 commit f91825e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 33 deletions.
3 changes: 1 addition & 2 deletions examples/plotStats.py
Expand Up @@ -46,7 +46,6 @@
from silx.gui.colors import Colormap
from silx.gui.plot import Plot1D
from silx.gui.plot.stats.stats import StatBase
from silx.gui.plot.StatsWidget import UpdateMode
from silx.gui.utils import concurrent
import random
import threading
Expand Down Expand Up @@ -133,7 +132,7 @@ def main(argv):
parser.add_argument(
'--update-mode',
default='manual',
help='update mode to display (manual or automatic)')
help='update mode to display (manual or auto)')

options = parser.parse_args(argv[1:])

Expand Down
47 changes: 16 additions & 31 deletions silx/gui/plot/StatsWidget.py
Expand Up @@ -56,8 +56,8 @@

@enum.unique
class UpdateMode(_Enum):
AUTO = 0
MANUAL = 1
AUTO = 'auto'
MANUAL = 'manual'


# Helper class to handle specific calls to PlotWidget and SceneWidget
Expand Down Expand Up @@ -515,28 +515,21 @@ def _skipPlotItemChangedEvent(self, event):
return event in self.__default_skipped_events

def setUpdateMode(self, mode):
"""
"""Set the way to update the displayed statistics.
:param mode: mode requested for update
:type mode: Union[str, `.UpdateMode`]
:type mode: Union[str,UpdateMode]
"""
_mode = mode
if type(mode) is str:
try:
_mode = getattr(UpdateMode, _mode)
except:
raise ValueError('Unrecognized update mode', mode,
'valid update mode are', UpdateMode.members())
assert _mode in UpdateMode
if _mode != self._updateMode:
self._updateMode = _mode
mode = UpdateMode.from_value(mode)
if mode != self._updateMode:
self._updateMode = mode
self._updateModeHasChanged()

def getUpdateMode(self):
"""
"""Returns update mode (See :meth:`setUpdateMode`).
:return: update mode
:rtype: `.UpdateMode`
:rtype: UpdateMode
"""
return self._updateMode

Expand Down Expand Up @@ -957,35 +950,27 @@ def _modeChanged(self, mode):
self.sigUpdateModeChanged.emit(mode)

def setUpdateMode(self, mode):
"""
"""Set the way to update the displayed statistics.
:param mode: mode requested for update
:type mode: Union[str, `.UpdateMode`]
:type mode: Union[str,UpdateMode]
"""
assert isinstance(mode, (UpdateMode, str))
_mode = mode
if type(mode) is str:
if mode.lower() in ('auto', 'automatic'):
_mode = UpdateMode.AUTO
elif mode.lower() == 'manual':
_mode = UpdateMode.MANUAL
else:
raise ValueError('mode', mode, 'is not recognized')
mode = UpdateMode.from_value(mode)

if _mode is UpdateMode.AUTO:
if mode is UpdateMode.AUTO:
if not self._autoRB.isChecked():
self._autoRB.setChecked(True)
elif _mode is UpdateMode.MANUAL:
elif mode is UpdateMode.MANUAL:
if not self._manualRB.isChecked():
self._manualRB.setChecked(True)
else:
raise ValueError('mode', mode, 'is not recognized')

def getUpdateMode(self):
"""
"""Returns update mode (See :meth:`setUpdateMode`).
:return: the active update mode
:rtype: `.UpdateMode`
:rtype: UpdateMode
"""
if self._manualRB.isChecked():
return UpdateMode.MANUAL
Expand Down

0 comments on commit f91825e

Please sign in to comment.