python-lottie  0.6.11+devcecd248
A framework to work with lottie files and telegram animated stickers (tgs)
timeline_widget.py
Go to the documentation of this file.
1 from PyQt5.QtGui import QIcon
2 from PyQt5.QtCore import Qt, QTimer
3 from PyQt5.QtCore import pyqtSignal as Signal
4 from PyQt5.QtCore import pyqtSlot as Slot
5 from PyQt5.QtWidgets import *
6 
7 
8 class TimelineWidget(QWidget):
9  frame_changed = Signal(int)
10 
11  def __init__(self):
12  super().__init__()
13  layout_slider = QHBoxLayout()
14  layout_slider.setContentsMargins(0, 0, 0, 0)
15  self.setLayout(layout_slider)
16  self.button_play = QPushButton()
17  self.button_play.setCheckable(True)
18  self.button_play.toggled.connect(self.play_toggle)
19  layout_slider.addWidget(self.button_play)
20  self.slider = QSlider(Qt.Horizontal)
21  layout_slider.addWidget(self.slider)
22  self.slider_spin = QSpinBox()
23  layout_slider.addWidget(self.slider_spin)
24  self.slider.valueChanged.connect(self.slider_spin.setValue)
25  self.slider_spin.valueChanged.connect(self.slider.setValue)
26  self.slider.valueChanged.connect(self.frame_changed)
27 
28  self.framerate = 60
29  self.timer = QTimer(self)
30  self.timer.timeout.connect(self._next_frame)
31  self.stop()
32 
33  self._min = 0
34  self._max = 99
35 
36  def set_min_max(self, min, max):
37  self._min = min
38  self._max = max
39  self.slider.setMinimum(min)
40  self.slider.setMaximum(max)
41  self.slider_spin.setMinimum(min)
42  self.slider_spin.setMaximum(max)
43 
44  @Slot(int)
45  def set_frame(self, frame):
46  self.slider.setValue(frame)
47 
48  @property
49  def frame(self):
50  return self.slider.value()
51 
52  def _next_frame(self):
53  nf = self.frame + 1
54  if nf > self._max:
55  nf = self._min
56  self.slider.setValue(nf)
57 
58  @Slot()
59  def stop(self):
60  self.timer.stop()
61  self.button_play.setIcon(QIcon.fromTheme("media-playback-start"))
62  self.button_play.setText("Play")
63  self.button_play.setChecked(False)
64 
65  @Slot()
66  def play(self):
67  if not self.isEnabled():
68  self.stop()
69  return
70 
71  self.button_play.setIcon(QIcon.fromTheme("media-playback-stop"))
72  self.button_play.setText("Stop")
73 
74  self.timer.start(1000/self.fps)
75 
76  @Slot(bool)
77  def play_toggle(self, play):
78  if play:
79  self.play()
80  else:
81  self.stop()
lottie.gui.timeline_widget.TimelineWidget.button_play
button_play
Definition: timeline_widget.py:16
lottie.gui.timeline_widget.TimelineWidget.__init__
def __init__(self)
Definition: timeline_widget.py:11
lottie.gui.timeline_widget.TimelineWidget._min
_min
Definition: timeline_widget.py:33
lottie.gui.timeline_widget.TimelineWidget.frame_changed
frame_changed
Definition: timeline_widget.py:9
lottie.gui.timeline_widget.TimelineWidget.frame
def frame(self)
Definition: timeline_widget.py:49
lottie.gui.timeline_widget.TimelineWidget.slider
slider
Definition: timeline_widget.py:20
lottie.gui.timeline_widget.TimelineWidget.slider_spin
slider_spin
Definition: timeline_widget.py:22
lottie.gui.timeline_widget.TimelineWidget._max
_max
Definition: timeline_widget.py:34
lottie.gui.timeline_widget.TimelineWidget.framerate
framerate
Definition: timeline_widget.py:28
lottie.gui.timeline_widget.TimelineWidget
Definition: timeline_widget.py:8
lottie.gui.timeline_widget.TimelineWidget._next_frame
def _next_frame(self)
Definition: timeline_widget.py:52
lottie.gui.timeline_widget.TimelineWidget.set_min_max
def set_min_max(self, min, max)
Definition: timeline_widget.py:36
lottie.gui.timeline_widget.TimelineWidget.play_toggle
def play_toggle(self, play)
Definition: timeline_widget.py:77
lottie.gui.timeline_widget.TimelineWidget.timer
timer
Definition: timeline_widget.py:29
lottie.gui.timeline_widget.TimelineWidget.stop
def stop(self)
Definition: timeline_widget.py:59
QtGui
lottie.gui.timeline_widget.TimelineWidget.set_frame
def set_frame(self, frame)
Definition: timeline_widget.py:45
QtWidgets
lottie.gui.timeline_widget.TimelineWidget.play
def play(self)
Definition: timeline_widget.py:66