pyloid 0.10.2__py3-none-any.whl → 0.11.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pyloid/__init__.py CHANGED
@@ -2,5 +2,6 @@ from .pyloid import Pyloid
2
2
  from .api import PyloidAPI, Bridge
3
3
  from .utils import get_production_path, is_production
4
4
  from .tray import TrayEvent
5
+ from .timer import PyloidTimer
5
6
 
6
- __all__ = ['Pyloid', 'PyloidAPI', 'Bridge', 'get_production_path', 'is_production', 'TrayEvent']
7
+ __all__ = ['Pyloid', 'PyloidAPI', 'Bridge', 'get_production_path', 'is_production', 'TrayEvent', 'PyloidTimer']
pyloid/timer.py ADDED
@@ -0,0 +1,123 @@
1
+ from PySide6.QtCore import QTimer, QObject
2
+
3
+ class PyloidTimer(QObject):
4
+ def __init__(self):
5
+ super().__init__()
6
+ self.timers = {}
7
+
8
+ def start_periodic_timer(self, interval, callback):
9
+ """
10
+ 주기적으로 실행되는 타이머를 시작합니다.
11
+
12
+ :param interval: 밀리초 단위의 간격
13
+ :param callback: 실행할 콜백 함수
14
+ :param auto_remove: 타이머 중지 시 자동 삭제 여부
15
+ :return: 타이머 ID
16
+ """
17
+ return self._create_timer(interval, callback, single_shot=False, auto_remove=False)
18
+
19
+ def start_single_shot_timer(self, delay, callback):
20
+ """
21
+ 한 번만 실행되는 타이머를 시작합니다.
22
+
23
+ :param delay: 밀리초 단위의 지연 시간
24
+ :param callback: 실행할 콜백 함수
25
+ :return: 타이머 ID
26
+ """
27
+ return self._create_timer(delay, callback, single_shot=True, auto_remove=True)
28
+
29
+ def _create_timer(self, interval, callback, single_shot=False, auto_remove=False):
30
+ timer = QTimer(self)
31
+ timer.setInterval(interval)
32
+ timer.setSingleShot(single_shot)
33
+
34
+ if auto_remove or single_shot:
35
+ timer.timeout.connect(lambda: self._timer_finished(callback, id(timer)))
36
+ else:
37
+ timer.timeout.connect(callback)
38
+
39
+ timer.start()
40
+
41
+ timer_id = id(timer)
42
+ self.timers[timer_id] = timer
43
+ return timer_id
44
+
45
+ def _timer_finished(self, callback, timer_id):
46
+ callback()
47
+ self.stop_timer(timer_id)
48
+
49
+ def stop_timer(self, timer_id):
50
+ """
51
+ 지정된 ID의 타이머를 중지합니다.
52
+
53
+ :param timer_id: 중지할 타이머의 ID
54
+ """
55
+ if timer_id in self.timers:
56
+ self.timers[timer_id].stop()
57
+ del self.timers[timer_id]
58
+
59
+ def is_timer_active(self, timer_id):
60
+ """
61
+ 지정된 ID의 타이머가 활성 상태인지 확인합니다.
62
+
63
+ :param timer_id: 확인할 타이머의 ID
64
+ :return: 타이머가 활성 상태이면 True, 그렇지 않으면 False
65
+ """
66
+ return timer_id in self.timers and self.timers[timer_id].isActive()
67
+
68
+ def get_remaining_time(self, timer_id):
69
+ """
70
+ 지정된 ID의 타이머의 남은 시간을 반환합니다.
71
+
72
+ :param timer_id: 확인할 타이머의 ID
73
+ :return: 남은 시간 (밀리초), 타이머가 없으면 None
74
+ """
75
+ if timer_id in self.timers:
76
+ return self.timers[timer_id].remainingTime()
77
+ return None
78
+
79
+ def set_interval(self, timer_id, interval):
80
+ """
81
+ 지정된 ID의 타이머의 간격을 설정합니다.
82
+
83
+ :param timer_id: 설정할 타이머의 ID
84
+ :param interval: 새로운 간격 (밀리초)
85
+ """
86
+ if timer_id in self.timers:
87
+ self.timers[timer_id].setInterval(interval)
88
+
89
+ def start_precise_periodic_timer(self, interval, callback):
90
+ """
91
+ 정밀한 주기적 타이머를 시작합니다.
92
+
93
+ :param interval: 밀리초 단위의 간격
94
+ :param callback: 실행할 콜백 함수
95
+ :return: 타이머 ID
96
+ """
97
+ return self._create_timer_with_type(interval, callback, QTimer.TimerType.PreciseTimer)
98
+
99
+ def start_coarse_periodic_timer(self, interval, callback):
100
+ """
101
+ 덜 정밀한 주기적 타이머를 시작합니다.
102
+
103
+ :param interval: 밀리초 단위의 간격
104
+ :param callback: 실행할 콜백 함수
105
+ :return: 타이머 ID
106
+ """
107
+ return self._create_timer_with_type(interval, callback, QTimer.TimerType.CoarseTimer)
108
+
109
+ def _create_timer_with_type(self, interval, callback, timer_type, auto_remove=False):
110
+ timer = QTimer(self)
111
+ timer.setInterval(interval)
112
+ timer.setTimerType(timer_type)
113
+
114
+ if auto_remove:
115
+ timer.timeout.connect(lambda: self._timer_finished(callback, id(timer)))
116
+ else:
117
+ timer.timeout.connect(callback)
118
+
119
+ timer.start()
120
+
121
+ timer_id = id(timer)
122
+ self.timers[timer_id] = timer
123
+ return timer_id
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyloid
3
- Version: 0.10.2
3
+ Version: 0.11.0
4
4
  Summary:
5
5
  Author: aesthetics-of-record
6
6
  Author-email: 111675679+aesthetics-of-record@users.noreply.github.com
@@ -1,12 +1,13 @@
1
- pyloid/__init__.py,sha256=98jn3uaX1hB0aZCmFFLYBIswGmauIBHNYX2ZXQC4KjA,246
1
+ pyloid/__init__.py,sha256=OOPhOKNQVmAM8hnfTeE7lHzxb8LsFNcgegBAvDrA-vY,293
2
2
  pyloid/api.py,sha256=whgfvPr1A6iwZ1Ewo-0FnOUNnt1K58c-P7YjzuQHcUM,194
3
3
  pyloid/autostart.py,sha256=K7DQYl4LHItvPp0bt1V9WwaaZmVSTeGvadkcwG-KKrI,3899
4
4
  pyloid/filewatcher.py,sha256=n8N56D65le5TpsgxXb7z-FO_0lqv4UYD4yGq_UuMrAs,1285
5
5
  pyloid/monitor.py,sha256=fqDnZ_7dpxVZLVJ5gCluDRY2USrQ5YL_fw1AnYivhsk,12741
6
6
  pyloid/pyloid.py,sha256=s3oES8HVgW53mYxizUzcVIYDNOhMADuEkYKuv5IlBtQ,40459
7
+ pyloid/timer.py,sha256=1bYhqte3rV77vaeMUkcTgmx2ux7FtCqLCx9lIC2-COg,4360
7
8
  pyloid/tray.py,sha256=rXgdkvzGxtie_EIcTSA7fjuta4nJk5THhNkGFcfv5Ew,634
8
9
  pyloid/utils.py,sha256=DQerZWU_0o8dHcJ5y3yXf9i5OXn7KQZqU-hVBq3uPUA,711
9
- pyloid-0.10.2.dist-info/LICENSE,sha256=F96EzotgWhhpnQTW2TcdoqrMDir1jyEo6H915tGQ-QE,11524
10
- pyloid-0.10.2.dist-info/METADATA,sha256=wnzUpr44CzzouCGHgoVKsDVHWnbE1QY1E1tHZ4TpK9Y,6068
11
- pyloid-0.10.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
12
- pyloid-0.10.2.dist-info/RECORD,,
10
+ pyloid-0.11.0.dist-info/LICENSE,sha256=F96EzotgWhhpnQTW2TcdoqrMDir1jyEo6H915tGQ-QE,11524
11
+ pyloid-0.11.0.dist-info/METADATA,sha256=jb38fxpq61DXAil2tQwTRVXtl5300UAMImmNOCi9jmU,6068
12
+ pyloid-0.11.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
13
+ pyloid-0.11.0.dist-info/RECORD,,