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 Nov 22, 2023
1 parent d1371a7 commit ea8c2c0
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 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,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):

Expand Down

0 comments on commit ea8c2c0

Please sign in to comment.