-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPTimer.py
33 lines (26 loc) · 860 Bytes
/
PTimer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from PyQt5.QtCore import QTimer
class PTimer(QTimer):
def __init__(self, parent=None, func=None):
super().__init__(parent)
self.duration = -1
self.tick_count = -1
if func:
self.timeout.connect(func)
self.timeout.connect(self.decrease_tick)
self.func = None
def setDuration(self, duration):
self.duration = duration
def setTickCount(self, count):
self.tick_count = count
def start(self, p_int=None):
super().start(p_int)
if self.duration > 0:
QTimer.singleShot(self.duration, self.stop)
def connect_to_stop(self, func):
self.func = func
def decrease_tick(self):
self.tick_count = self.tick_count - 1
if self.tick_count == 0:
self.stop()
if self.func:
self.func()