Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def work(self):
# if loop_mode is once and we are already on the last frame,
# return to the first frame... (so the user can keep hitting once)
if self.loop_mode == LoopMode.ONCE:
if self.step > 0 and self.current >= self.max_point - 1:
self.frame_requested.emit(self.axis, self.min_point)
elif self.step < 0 and self.current <= self.min_point + 1:
self.frame_requested.emit(self.axis, self.max_point)
self.timer.singleShot(self.interval, self.advance)
else:
# immediately advance one frame
self.advance()
self.started.emit()
IndexError
If ``axis`` requested is out of the range of the dims
IndexError
If ``frame_range`` is provided and out of the range of the dims
ValueError
If ``frame_range`` is provided and range[0] >= range[1]
"""
# doing manual check here to avoid issue in StringEnum
# see https://github.com/napari/napari/issues/754
if loop_mode is not None:
_modes = [str(mode) for mode in LoopMode]
if loop_mode not in _modes:
raise ValueError(
f'loop_mode must be one of {_modes}. Got: {loop_mode}'
)
loop_mode = LoopMode(loop_mode)
if axis >= len(self.dims.range):
raise IndexError('axis argument out of range')
if self.is_playing:
if self._animation_worker.axis == axis:
self.slider_widgets[axis]._update_play_settings(
fps, loop_mode, frame_range
)
return
else:
self.stop()
# we want to avoid playing a dimension that does not have a slider
# (like X or Y, or a third dimension in volume view.)
if self._displayed_sliders[axis]:
def advance(self):
"""Advance the current frame in the animation.
Takes dims scale into account and restricts the animation to the
requested frame_range, if entered.
"""
self.current += self.step * self.dimsrange[2]
if self.current < self.min_point:
if (
self.loop_mode == LoopMode.BACK_AND_FORTH
): # 'loop_back_and_forth'
self.step *= -1
self.current = self.min_point + self.step * self.dimsrange[2]
elif self.loop_mode == LoopMode.LOOP: # 'loop'
self.current = self.max_point + self.current - self.min_point
else: # loop_mode == 'once'
return self.finish()
elif self.current >= self.max_point:
if (
self.loop_mode == LoopMode.BACK_AND_FORTH
): # 'loop_back_and_forth'
self.step *= -1
self.current = (
self.max_point + 2 * self.step * self.dimsrange[2]
)
elif self.loop_mode == LoopMode.LOOP: # 'loop'
# minspin.setValue(dimsrange[0])
# minspin.valueChanged.connect(self.set_minframe)
# self.popup.form_layout.insertRow(
# 1, QLabel('start frame:', parent=self.popup), minspin
# )
# maxspin = QDoubleSpinBox(self.popup)
# maxspin.setAlignment(Qt.AlignCenter)
# maxspin.setValue(dimsrange[1] * dimsrange[2])
# maxspin.valueChanged.connect(self.set_maxframe)
# self.popup.form_layout.insertRow(
# 2, QLabel('end frame:', parent=self.popup), maxspin
# )
mode_combo = QComboBox(self.popup)
mode_combo.addItems([str(i).replace('_', ' ') for i in LoopMode])
self.popup.form_layout.insertRow(
2, QLabel('play mode:', parent=self.popup), mode_combo
)
mode_combo.setCurrentText(str(self.mode))
self.mode_combo = mode_combo
lambda x: self.__class__.loop_mode.fset(
self, LoopMode(x.replace(' ', '_'))
)
frame_range: tuple | list
If specified, will constrain animation to loop [first, last] frames
Raises
------
IndexError
If ``axis`` requested is out of the range of the dims
IndexError
If ``frame_range`` is provided and out of the range of the dims
ValueError
If ``frame_range`` is provided and range[0] >= range[1]
"""
# doing manual check here to avoid issue in StringEnum
# see https://github.com/napari/napari/issues/754
if loop_mode is not None:
_modes = [str(mode) for mode in LoopMode]
if loop_mode not in _modes:
raise ValueError(
f'loop_mode must be one of {_modes}. Got: {loop_mode}'
)
loop_mode = LoopMode(loop_mode)
if axis >= len(self.dims.range):
raise IndexError('axis argument out of range')
if self.is_playing:
if self._animation_worker.axis == axis:
self.slider_widgets[axis]._update_play_settings(
fps, loop_mode, frame_range
)
return
else:
def __init__(self, dims, axis, reverse=False, fps=10, mode=LoopMode.LOOP):
super().__init__()
self.dims = dims
self.axis = axis
self.reverse = reverse
self.fps = fps
self.mode = mode
self.setProperty('reverse', str(reverse)) # for styling
self.setProperty('playing', 'False') # for styling
# build popup modal form
self.popup = QtPopup(self)
fpsspin = QtCustomDoubleSpinBox(self.popup)
fpsspin.setAlignment(Qt.AlignCenter)
fpsspin.setValue(self.fps)
if hasattr(fpsspin, 'setStepType'):
def set_loop_mode(self, mode):
self.loop_mode = LoopMode(mode)