Skip to content

Commit

Permalink
Add API to start/stop animations to the Spin class
Browse files Browse the repository at this point in the history
This also adds a kwarg to decide if the animation should be
automatically started (in some situations that's not desired).
  • Loading branch information
ccordoba12 committed Dec 7, 2023
1 parent d1371a7 commit 025e59b
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions qtawesome/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand All @@ -34,8 +38,21 @@ 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):

def __init__(self, parent_widget):
super().__init__(parent_widget, interval=300, step=45)
def __init__(self, parent_widget, autostart=True):
super().__init__(
parent_widget,
interval=300,
step=45,
autostart=autostart
)

0 comments on commit 025e59b

Please sign in to comment.