pyloid 0.13.0__py3-none-any.whl → 0.14.0__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- pyloid/api.py +85 -2
- pyloid/browser_window.py +1190 -0
- pyloid/filewatcher.py +137 -9
- pyloid/js_api/event_api.py +25 -0
- pyloid/js_api/window_api.py +166 -0
- pyloid/monitor.py +602 -77
- pyloid/pyloid.py +661 -892
- pyloid/timer.py +222 -38
- pyloid/tray.py +30 -0
- pyloid/utils.py +55 -6
- {pyloid-0.13.0.dist-info → pyloid-0.14.0.dist-info}/METADATA +1 -1
- pyloid-0.14.0.dist-info/RECORD +17 -0
- pyloid-0.13.0.dist-info/RECORD +0 -14
- {pyloid-0.13.0.dist-info → pyloid-0.14.0.dist-info}/LICENSE +0 -0
- {pyloid-0.13.0.dist-info → pyloid-0.14.0.dist-info}/WHEEL +0 -0
pyloid/timer.py
CHANGED
@@ -1,28 +1,80 @@
|
|
1
|
-
from PySide6.QtCore import QTimer, QObject
|
1
|
+
from PySide6.QtCore import QTimer, QObject, Qt
|
2
2
|
|
3
3
|
class PyloidTimer(QObject):
|
4
4
|
def __init__(self):
|
5
|
+
"""
|
6
|
+
Constructor for the PyloidTimer class.
|
7
|
+
|
8
|
+
This class is based on PySide6's QTimer and allows for easy creation and management of various types of timers.
|
9
|
+
"""
|
5
10
|
super().__init__()
|
6
11
|
self.timers = {}
|
7
12
|
|
8
13
|
def start_periodic_timer(self, interval, callback):
|
9
14
|
"""
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
15
|
+
Starts a periodic timer.
|
16
|
+
|
17
|
+
This function starts a timer that repeatedly executes the callback function at the given interval.
|
18
|
+
|
19
|
+
Parameters
|
20
|
+
----------
|
21
|
+
interval : int
|
22
|
+
Interval in milliseconds
|
23
|
+
callback : function
|
24
|
+
Callback function to execute
|
25
|
+
|
26
|
+
Returns
|
27
|
+
-------
|
28
|
+
int
|
29
|
+
Timer ID
|
30
|
+
|
31
|
+
Example
|
32
|
+
-------
|
33
|
+
```python
|
34
|
+
from pyloid.timer import PyloidTimer
|
35
|
+
|
36
|
+
timer_manager = PyloidTimer()
|
37
|
+
|
38
|
+
def print_hello():
|
39
|
+
print("Hello!")
|
40
|
+
|
41
|
+
# Start a timer that prints "Hello!" every 2 seconds
|
42
|
+
timer_id = timer_manager.start_periodic_timer(2000, print_hello)
|
43
|
+
```
|
16
44
|
"""
|
17
45
|
return self._create_timer(interval, callback, single_shot=False, auto_remove=False)
|
18
46
|
|
19
47
|
def start_single_shot_timer(self, delay, callback):
|
20
48
|
"""
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
49
|
+
Starts a single-shot timer.
|
50
|
+
|
51
|
+
This function starts a timer that executes the callback function once after the given delay.
|
52
|
+
|
53
|
+
Parameters
|
54
|
+
----------
|
55
|
+
delay : int
|
56
|
+
Delay in milliseconds
|
57
|
+
callback : function
|
58
|
+
Callback function to execute
|
59
|
+
|
60
|
+
Returns
|
61
|
+
-------
|
62
|
+
int
|
63
|
+
Timer ID
|
64
|
+
|
65
|
+
Example
|
66
|
+
-------
|
67
|
+
```python
|
68
|
+
from pyloid.timer import PyloidTimer
|
69
|
+
|
70
|
+
timer_manager = PyloidTimer()
|
71
|
+
|
72
|
+
def delayed_message():
|
73
|
+
print("5 seconds have passed!")
|
74
|
+
|
75
|
+
# Start a single-shot timer that prints a message after 5 seconds
|
76
|
+
timer_id = timer_manager.start_single_shot_timer(5000, delayed_message)
|
77
|
+
```
|
26
78
|
"""
|
27
79
|
return self._create_timer(delay, callback, single_shot=True, auto_remove=True)
|
28
80
|
|
@@ -48,9 +100,25 @@ class PyloidTimer(QObject):
|
|
48
100
|
|
49
101
|
def stop_timer(self, timer_id):
|
50
102
|
"""
|
51
|
-
|
52
|
-
|
53
|
-
|
103
|
+
Stops the timer with the specified ID.
|
104
|
+
|
105
|
+
This function stops the timer corresponding to the given timer ID and removes it from the timer list.
|
106
|
+
|
107
|
+
Parameters
|
108
|
+
----------
|
109
|
+
timer_id : int
|
110
|
+
ID of the timer to stop
|
111
|
+
|
112
|
+
Example
|
113
|
+
-------
|
114
|
+
```python
|
115
|
+
from pyloid.timer import PyloidTimer
|
116
|
+
|
117
|
+
timer_manager = PyloidTimer()
|
118
|
+
|
119
|
+
# Stop the timer using its ID
|
120
|
+
timer_manager.stop_timer(timer_id)
|
121
|
+
```
|
54
122
|
"""
|
55
123
|
if timer_id in self.timers:
|
56
124
|
self.timers[timer_id].stop()
|
@@ -58,19 +126,62 @@ class PyloidTimer(QObject):
|
|
58
126
|
|
59
127
|
def is_timer_active(self, timer_id):
|
60
128
|
"""
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
129
|
+
Checks if the timer with the specified ID is active.
|
130
|
+
|
131
|
+
This function returns whether the timer corresponding to the given timer ID is currently active.
|
132
|
+
|
133
|
+
Parameters
|
134
|
+
----------
|
135
|
+
timer_id : int
|
136
|
+
ID of the timer to check
|
137
|
+
|
138
|
+
Returns
|
139
|
+
-------
|
140
|
+
bool
|
141
|
+
True if the timer is active, False otherwise
|
142
|
+
|
143
|
+
Example
|
144
|
+
-------
|
145
|
+
```python
|
146
|
+
from pyloid.timer import PyloidTimer
|
147
|
+
|
148
|
+
timer_manager = PyloidTimer()
|
149
|
+
|
150
|
+
if timer_manager.is_timer_active(timer_id):
|
151
|
+
print("The timer is still running.")
|
152
|
+
else:
|
153
|
+
print("The timer has stopped.")
|
154
|
+
```
|
65
155
|
"""
|
66
156
|
return timer_id in self.timers and self.timers[timer_id].isActive()
|
67
157
|
|
68
158
|
def get_remaining_time(self, timer_id):
|
69
159
|
"""
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
160
|
+
Returns the remaining time of the timer with the specified ID.
|
161
|
+
|
162
|
+
This function returns the remaining time of the timer corresponding to the given timer ID in milliseconds.
|
163
|
+
|
164
|
+
Parameters
|
165
|
+
----------
|
166
|
+
timer_id : int
|
167
|
+
ID of the timer to check
|
168
|
+
|
169
|
+
Returns
|
170
|
+
-------
|
171
|
+
int or None
|
172
|
+
Remaining time in milliseconds, or None if the timer does not exist
|
173
|
+
|
174
|
+
Example
|
175
|
+
-------
|
176
|
+
```python
|
177
|
+
from pyloid.timer import PyloidTimer
|
178
|
+
|
179
|
+
timer_manager = PyloidTimer()
|
180
|
+
|
181
|
+
remaining_time = timer_manager.get_remaining_time(timer_id)
|
182
|
+
if remaining_time is not None:
|
183
|
+
print(f"{remaining_time}ms remaining.")
|
184
|
+
```
|
74
185
|
"""
|
75
186
|
if timer_id in self.timers:
|
76
187
|
return self.timers[timer_id].remainingTime()
|
@@ -78,33 +189,106 @@ class PyloidTimer(QObject):
|
|
78
189
|
|
79
190
|
def set_interval(self, timer_id, interval):
|
80
191
|
"""
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
192
|
+
Sets the interval of the timer with the specified ID.
|
193
|
+
|
194
|
+
This function sets a new interval for the timer corresponding to the given timer ID.
|
195
|
+
|
196
|
+
Parameters
|
197
|
+
----------
|
198
|
+
timer_id : int
|
199
|
+
ID of the timer to set
|
200
|
+
interval : int
|
201
|
+
New interval in milliseconds
|
202
|
+
|
203
|
+
Example
|
204
|
+
-------
|
205
|
+
```python
|
206
|
+
from pyloid.timer import PyloidTimer
|
207
|
+
|
208
|
+
timer_manager = PyloidTimer()
|
209
|
+
|
210
|
+
# Change the timer interval to 3 seconds
|
211
|
+
timer_manager.set_interval(timer_id, 3000)
|
212
|
+
```
|
85
213
|
"""
|
86
214
|
if timer_id in self.timers:
|
87
215
|
self.timers[timer_id].setInterval(interval)
|
88
216
|
|
89
217
|
def start_precise_periodic_timer(self, interval, callback):
|
90
218
|
"""
|
91
|
-
|
219
|
+
Starts a precise periodic timer.
|
220
|
+
|
221
|
+
This function starts a timer that repeatedly executes the callback function at precise intervals.
|
92
222
|
|
93
|
-
|
94
|
-
|
95
|
-
|
223
|
+
Note
|
224
|
+
----
|
225
|
+
Precise timers consume more CPU resources.
|
226
|
+
|
227
|
+
Parameters
|
228
|
+
----------
|
229
|
+
interval : int
|
230
|
+
Interval in milliseconds
|
231
|
+
callback : function
|
232
|
+
Callback function to execute
|
233
|
+
|
234
|
+
Returns
|
235
|
+
-------
|
236
|
+
int
|
237
|
+
Timer ID
|
238
|
+
|
239
|
+
Example
|
240
|
+
-------
|
241
|
+
```python
|
242
|
+
from pyloid.timer import PyloidTimer
|
243
|
+
|
244
|
+
timer_manager = PyloidTimer()
|
245
|
+
|
246
|
+
def precise_task():
|
247
|
+
print("Executing precise task")
|
248
|
+
|
249
|
+
# Start a precise periodic timer with a 100ms interval
|
250
|
+
precise_timer_id = timer_manager.start_precise_periodic_timer(100, precise_task)
|
251
|
+
```
|
96
252
|
"""
|
97
|
-
return self._create_timer_with_type(interval, callback,
|
253
|
+
return self._create_timer_with_type(interval, callback, Qt.TimerType.PreciseTimer)
|
98
254
|
|
99
255
|
def start_coarse_periodic_timer(self, interval, callback):
|
100
256
|
"""
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
257
|
+
Starts a coarse periodic timer.
|
258
|
+
|
259
|
+
This function starts a timer that repeatedly executes the callback function at coarse intervals.
|
260
|
+
|
261
|
+
Note
|
262
|
+
----
|
263
|
+
Coarse timers consume less CPU resources.
|
264
|
+
|
265
|
+
Parameters
|
266
|
+
----------
|
267
|
+
interval : int
|
268
|
+
Interval in milliseconds
|
269
|
+
callback : function
|
270
|
+
Callback function to execute
|
271
|
+
|
272
|
+
Returns
|
273
|
+
-------
|
274
|
+
int
|
275
|
+
Timer ID
|
276
|
+
|
277
|
+
Example
|
278
|
+
-------
|
279
|
+
```python
|
280
|
+
from pyloid.timer import PyloidTimer
|
281
|
+
|
282
|
+
timer_manager = PyloidTimer()
|
283
|
+
|
284
|
+
def coarse_task():
|
285
|
+
print("Executing coarse task")
|
286
|
+
|
287
|
+
# Start a coarse periodic timer with a 500ms interval
|
288
|
+
coarse_timer_id = timer_manager.start_coarse_periodic_timer(500, coarse_task)
|
289
|
+
```
|
106
290
|
"""
|
107
|
-
return self._create_timer_with_type(interval, callback,
|
291
|
+
return self._create_timer_with_type(interval, callback, Qt.TimerType.CoarseTimer)
|
108
292
|
|
109
293
|
def _create_timer_with_type(self, interval, callback, timer_type, auto_remove=False):
|
110
294
|
timer = QTimer(self)
|
pyloid/tray.py
CHANGED
@@ -3,6 +3,36 @@ from PySide6.QtWidgets import QSystemTrayIcon
|
|
3
3
|
|
4
4
|
|
5
5
|
class TrayEvent(Enum):
|
6
|
+
"""
|
7
|
+
TrayEvent is an enumeration class representing events related to the system tray icon.
|
8
|
+
|
9
|
+
Enumeration Members
|
10
|
+
-------------------
|
11
|
+
DoubleClick : Event that occurs when the tray icon is double-clicked
|
12
|
+
MiddleClick : Event that occurs when the tray icon is clicked with the middle button
|
13
|
+
RightClick : Event that occurs when the tray icon is right-clicked (context menu)
|
14
|
+
LeftClick : Event that occurs when the tray icon is left-clicked
|
15
|
+
Unknown : Unknown event
|
16
|
+
|
17
|
+
Usage Example
|
18
|
+
-------------
|
19
|
+
```python
|
20
|
+
from pyloid import Pyloid, TrayEvent
|
21
|
+
|
22
|
+
app = Pyloid(app_name="Pyloid-App")
|
23
|
+
|
24
|
+
app.set_tray_icon("icons/icon.ico")
|
25
|
+
|
26
|
+
app.set_tray_actions(
|
27
|
+
{
|
28
|
+
TrayEvent.DoubleClick: lambda: print("Tray icon was double-clicked."),
|
29
|
+
TrayEvent.MiddleClick: lambda: print("Tray icon was middle-clicked."),
|
30
|
+
TrayEvent.RightClick: lambda: print("Tray icon was right-clicked."),
|
31
|
+
TrayEvent.LeftClick: lambda: print("Tray icon was left-clicked."),
|
32
|
+
}
|
33
|
+
)
|
34
|
+
```
|
35
|
+
"""
|
6
36
|
DoubleClick = QSystemTrayIcon.ActivationReason.DoubleClick
|
7
37
|
MiddleClick = QSystemTrayIcon.ActivationReason.MiddleClick
|
8
38
|
RightClick = QSystemTrayIcon.ActivationReason.Context
|
pyloid/utils.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import sys
|
2
2
|
import os
|
3
|
+
import platform
|
3
4
|
from typing import Optional
|
4
5
|
|
5
6
|
|
@@ -8,8 +9,20 @@ def get_production_path() -> Optional[str]:
|
|
8
9
|
Returns the path to the resource files in a production environment.
|
9
10
|
If running as a regular Python script, returns None.
|
10
11
|
|
11
|
-
Returns
|
12
|
-
|
12
|
+
Returns
|
13
|
+
-------
|
14
|
+
str | None
|
15
|
+
The path to the resource files if in a production environment,
|
16
|
+
otherwise None.
|
17
|
+
|
18
|
+
Examples
|
19
|
+
--------
|
20
|
+
>>> from pyloid.utils import get_production_path
|
21
|
+
>>> path = get_production_path()
|
22
|
+
>>> if path:
|
23
|
+
>>> print(f"Production path: {path}")
|
24
|
+
>>> else:
|
25
|
+
>>> print("Not in a production environment.")
|
13
26
|
"""
|
14
27
|
if getattr(sys, 'frozen', False):
|
15
28
|
# If built with PyInstaller
|
@@ -18,12 +31,48 @@ def get_production_path() -> Optional[str]:
|
|
18
31
|
# If running as a regular Python script
|
19
32
|
return None
|
20
33
|
|
21
|
-
|
22
|
-
def is_production():
|
34
|
+
def is_production() -> bool:
|
23
35
|
"""
|
24
36
|
Checks if the current environment is a production environment.
|
25
37
|
|
26
|
-
Returns
|
27
|
-
|
38
|
+
Returns
|
39
|
+
-------
|
40
|
+
bool
|
41
|
+
True if in a production environment, False otherwise.
|
42
|
+
|
43
|
+
Examples
|
44
|
+
--------
|
45
|
+
>>> from pyloid.utils import is_production
|
46
|
+
>>> if is_production():
|
47
|
+
>>> print("Running in production environment.")
|
48
|
+
>>> else:
|
49
|
+
>>> print("Not in production environment.")
|
28
50
|
"""
|
29
51
|
return getattr(sys, 'frozen', False)
|
52
|
+
|
53
|
+
|
54
|
+
def get_platform() -> str:
|
55
|
+
"""
|
56
|
+
Returns the name of the current system's platform.
|
57
|
+
|
58
|
+
This function uses `platform.system()` to return the name of the current operating system.
|
59
|
+
|
60
|
+
Returns
|
61
|
+
-------
|
62
|
+
"Windows" | "Darwin" | "Linux"
|
63
|
+
- "Windows" for Windows systems
|
64
|
+
- "Darwin" for macOS systems
|
65
|
+
- "Linux" for Linux systems
|
66
|
+
|
67
|
+
Examples
|
68
|
+
--------
|
69
|
+
>>> from pyloid.utils import get_platform
|
70
|
+
>>> platform_name = get_platform()
|
71
|
+
>>> print(platform_name)
|
72
|
+
Windows
|
73
|
+
"""
|
74
|
+
return platform.system()
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
pyloid/__init__.py,sha256=OOPhOKNQVmAM8hnfTeE7lHzxb8LsFNcgegBAvDrA-vY,293
|
2
|
+
pyloid/api.py,sha256=waOHddz-rmeTxTvMWRH7Dq24RTKkkJpLw55Ava--TWw,2204
|
3
|
+
pyloid/autostart.py,sha256=K7DQYl4LHItvPp0bt1V9WwaaZmVSTeGvadkcwG-KKrI,3899
|
4
|
+
pyloid/browser_window.py,sha256=dMdmMTMqgAp2wViGZqZmUO4J5_GtNkYSQ_BCpq65ybo,37543
|
5
|
+
pyloid/custom/titlebar.py,sha256=itzK9pJbZMQ7BKca9kdbuHMffurrw15UijR6OU03Xsk,3894
|
6
|
+
pyloid/filewatcher.py,sha256=3M5zWVUf1OhlkWJcDFC8ZA9agO4Q-U8WdgGpy6kaVz0,4601
|
7
|
+
pyloid/js_api/event_api.py,sha256=_52yyBonqecmMvJpFW7OMNi_jX8Nrteqw_kI6r-DGG0,951
|
8
|
+
pyloid/js_api/window_api.py,sha256=JDAFIMMiw75PNcyO8_163PJdRY-dvFNBO3IN0TA-Xsw,5383
|
9
|
+
pyloid/monitor.py,sha256=nmcoOmlHeTysrZVT5mmL92ASbqMg8aH-hQg35qKWi0M,27540
|
10
|
+
pyloid/pyloid.py,sha256=e_5G4wdkhZchPiwgydo2w5IIIpj-ZP8ge4ZQp9lmcXs,37889
|
11
|
+
pyloid/timer.py,sha256=RqMsChFUd93cxMVgkHWiIKrci0QDTBgJSTULnAtYT8M,8712
|
12
|
+
pyloid/tray.py,sha256=D12opVEc2wc2T4tK9epaN1oOdeziScsIVNM2uCN7C-A,1710
|
13
|
+
pyloid/utils.py,sha256=VGZE2liY8_AElEqxVe1YLbk3fWlcAevpRc6oOTTgi-U,1927
|
14
|
+
pyloid-0.14.0.dist-info/LICENSE,sha256=F96EzotgWhhpnQTW2TcdoqrMDir1jyEo6H915tGQ-QE,11524
|
15
|
+
pyloid-0.14.0.dist-info/METADATA,sha256=QhNFQVNOyvDMqwD2QIz4RMpdxP_QUWkimmLaUsPO_jE,3634
|
16
|
+
pyloid-0.14.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
17
|
+
pyloid-0.14.0.dist-info/RECORD,,
|
pyloid-0.13.0.dist-info/RECORD
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
pyloid/__init__.py,sha256=OOPhOKNQVmAM8hnfTeE7lHzxb8LsFNcgegBAvDrA-vY,293
|
2
|
-
pyloid/api.py,sha256=whgfvPr1A6iwZ1Ewo-0FnOUNnt1K58c-P7YjzuQHcUM,194
|
3
|
-
pyloid/autostart.py,sha256=K7DQYl4LHItvPp0bt1V9WwaaZmVSTeGvadkcwG-KKrI,3899
|
4
|
-
pyloid/custom/titlebar.py,sha256=itzK9pJbZMQ7BKca9kdbuHMffurrw15UijR6OU03Xsk,3894
|
5
|
-
pyloid/filewatcher.py,sha256=n8N56D65le5TpsgxXb7z-FO_0lqv4UYD4yGq_UuMrAs,1285
|
6
|
-
pyloid/monitor.py,sha256=fqDnZ_7dpxVZLVJ5gCluDRY2USrQ5YL_fw1AnYivhsk,12741
|
7
|
-
pyloid/pyloid.py,sha256=Fj60bHP6x9_GPCxWSB97t21VwzdDjQmhf_RIWzc4_k0,53585
|
8
|
-
pyloid/timer.py,sha256=1bYhqte3rV77vaeMUkcTgmx2ux7FtCqLCx9lIC2-COg,4360
|
9
|
-
pyloid/tray.py,sha256=rXgdkvzGxtie_EIcTSA7fjuta4nJk5THhNkGFcfv5Ew,634
|
10
|
-
pyloid/utils.py,sha256=DQerZWU_0o8dHcJ5y3yXf9i5OXn7KQZqU-hVBq3uPUA,711
|
11
|
-
pyloid-0.13.0.dist-info/LICENSE,sha256=F96EzotgWhhpnQTW2TcdoqrMDir1jyEo6H915tGQ-QE,11524
|
12
|
-
pyloid-0.13.0.dist-info/METADATA,sha256=q61MnQEpscRzhp5cQDk33lKSBgTCLm5xJ5-nX5L2o7w,3634
|
13
|
-
pyloid-0.13.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
14
|
-
pyloid-0.13.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|