diff --git a/qtawesome/animation.py b/qtawesome/animation.py index 711cdc86..f041a9fd 100644 --- a/qtawesome/animation.py +++ b/qtawesome/animation.py @@ -3,9 +3,12 @@ class Spin: - def __init__(self, parent_widget, interval=10, step=1): + def __init__(self, parent_widget, interval=10, step=1, autostart=True): self.parent_widget = parent_widget - self.interval, self.step = interval, step + self.interval = interval + self.step = step + self.autostart = autostart + self.info = {} def _update(self): @@ -25,7 +28,8 @@ def setup(self, icon_painter, painter, rect): timer = QTimer(self.parent_widget) timer.timeout.connect(self._update) self.info[self.parent_widget] = [timer, 0, self.step] - timer.start(self.interval) + if self.autostart: + timer.start(self.interval) else: timer, angle, self.step = self.info[self.parent_widget] x_center = rect.width() * 0.5 @@ -34,6 +38,14 @@ def setup(self, icon_painter, painter, rect): painter.rotate(angle) painter.translate(-x_center, -y_center) + def start(self): + timer: QTimer = self.info[self.parent_widget][0] + timer.start(self.interval) + + def stop(self): + timer: QTimer = self.info[self.parent_widget][0] + timer.stop() + class Pulse(Spin):