pyloid 0.9.5__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.
pylonic/monitor.py ADDED
@@ -0,0 +1,372 @@
1
+ from PySide6.QtGui import QScreen
2
+ from typing import Optional, Callable
3
+
4
+ class Monitor():
5
+ def __init__(self, index: int, screen: QScreen):
6
+ super().__init__()
7
+ self.index = index
8
+ self.screen = screen
9
+
10
+ def capture(self, save_path: str, x: Optional[int] = None, y: Optional[int] = None, width: Optional[int] = None, height: Optional[int] = None):
11
+ """
12
+ Captures the entire desktop screen.
13
+
14
+ :param save_path: Path to save the captured image. If not specified, it will be saved in the current directory.
15
+ :return: Path of the saved image
16
+ """
17
+ try:
18
+ screenshot = self.screen.grabWindow(0, x, y, width, height)
19
+ screenshot.save(save_path)
20
+ return save_path
21
+
22
+ except Exception as e:
23
+ print(f"Error occurred while capturing the desktop: {e}")
24
+ return None
25
+
26
+ def info(self):
27
+ """
28
+ Returns monitor information.
29
+
30
+ :return: Dictionary containing monitor information
31
+ """
32
+ monitor = self.screen
33
+
34
+ monitor_data = {
35
+ "index": self.index,
36
+ "name": monitor.name(),
37
+ "manufacturer": monitor.manufacturer(),
38
+ "model": monitor.model(),
39
+ "serial_number": monitor.serialNumber(),
40
+ "x": monitor.geometry().x(),
41
+ "y": monitor.geometry().y(),
42
+ "width": monitor.size().width(),
43
+ "height": monitor.size().height(),
44
+ "is_primary": self.is_primary(),
45
+ "geometry": {
46
+ "x": monitor.geometry().x(),
47
+ "y": monitor.geometry().y(),
48
+ "width": monitor.geometry().width(),
49
+ "height": monitor.geometry().height(),
50
+ },
51
+ "size": {
52
+ "width": monitor.size().width(),
53
+ "height": monitor.size().height(),
54
+ },
55
+ "available_geometry": {
56
+ "x": monitor.availableGeometry().x(),
57
+ "y": monitor.availableGeometry().y(),
58
+ "width": monitor.availableGeometry().width(),
59
+ "height": monitor.availableGeometry().height(),
60
+ },
61
+ "available_size": {
62
+ "width": monitor.availableSize().width(),
63
+ "height": monitor.availableSize().height(),
64
+ },
65
+ "virtual_geometry":{
66
+ "x": monitor.virtualGeometry().x(),
67
+ "y": monitor.virtualGeometry().y(),
68
+ "width": monitor.virtualGeometry().width(),
69
+ "height": monitor.virtualGeometry().height(),
70
+ },
71
+ "virtual_size": {
72
+ "width": monitor.virtualSize().width(),
73
+ "height": monitor.virtualSize().height(),
74
+ },
75
+ "available_virtual_geometry": {
76
+ "x": monitor.availableVirtualGeometry().x(),
77
+ "y": monitor.availableVirtualGeometry().y(),
78
+ "width": monitor.availableVirtualGeometry().width(),
79
+ "height": monitor.availableVirtualGeometry().height(),
80
+ },
81
+ "available_virtual_size": {
82
+ "width": monitor.availableVirtualSize().width(),
83
+ "height": monitor.availableVirtualSize().height(),
84
+ },
85
+ "physical_size": {
86
+ "width": monitor.physicalSize().width(),
87
+ "height": monitor.physicalSize().height(),
88
+ },
89
+ "depth": monitor.depth(),
90
+ "device_pixel_ratio": monitor.devicePixelRatio(),
91
+ "logical_dots_per_inch": monitor.logicalDotsPerInch(),
92
+ "logical_dots_per_inch_x": monitor.logicalDotsPerInchX(),
93
+ "logical_dots_per_inch_y": monitor.logicalDotsPerInchY(),
94
+ "orientation": monitor.orientation().name,
95
+ "physical_dots_per_inch": monitor.physicalDotsPerInch(),
96
+ "physical_dots_per_inch_x": monitor.physicalDotsPerInchX(),
97
+ "physical_dots_per_inch_y": monitor.physicalDotsPerInchY(),
98
+ "refresh_rate": monitor.refreshRate(),
99
+ }
100
+
101
+ return monitor_data
102
+
103
+ def is_primary(self) -> bool:
104
+ """
105
+ Checks if the given monitor is the primary monitor.
106
+
107
+ :return: True if the primary monitor, False otherwise
108
+ """
109
+ return self.index == 0
110
+
111
+ def size(self) -> dict:
112
+ """
113
+ Returns the size of the monitor.
114
+
115
+ :return: Size of the monitor
116
+ """
117
+ monitor = self.screen
118
+ return {
119
+ "width": monitor.size().width(),
120
+ "height": monitor.size().height(),
121
+ },
122
+
123
+ def geometry(self) -> dict:
124
+ """
125
+ Returns the geometry of the monitor.
126
+
127
+ :return: Geometry of the monitor
128
+ """
129
+ monitor = self.screen
130
+ return {
131
+ "x": monitor.geometry().x(),
132
+ "y": monitor.geometry().y(),
133
+ "width": monitor.geometry().width(),
134
+ "height": monitor.geometry().height(),
135
+ }
136
+
137
+ def available_geometry(self) -> dict:
138
+ """
139
+ Returns the available geometry of the monitor.
140
+
141
+ :return: Available geometry of the monitor
142
+ """
143
+ monitor = self.screen
144
+ return {
145
+ "x": monitor.availableGeometry().x(),
146
+ "y": monitor.availableGeometry().y(),
147
+ "width": monitor.availableGeometry().width(),
148
+ "height": monitor.availableGeometry().height(),
149
+ }
150
+
151
+ def available_size(self) -> dict:
152
+ """
153
+ Returns the available size of the monitor.
154
+
155
+ :return: Available size of the monitor
156
+ """
157
+ monitor = self.screen
158
+ return {
159
+ "width": monitor.availableSize().width(),
160
+ "height": monitor.availableSize().height(),
161
+ }
162
+
163
+ def virtual_geometry(self) -> dict:
164
+ """
165
+ Returns the virtual geometry of the monitor.
166
+
167
+ :return: Virtual geometry of the monitor
168
+ """
169
+ monitor = self.screen
170
+ return {
171
+ "x": monitor.virtualGeometry().x(),
172
+ "y": monitor.virtualGeometry().y(),
173
+ "width": monitor.virtualGeometry().width(),
174
+ "height": monitor.virtualGeometry().height(),
175
+ }
176
+
177
+ def virtual_size(self) -> dict:
178
+ """
179
+ Returns the virtual size of the monitor.
180
+
181
+ :return: Virtual size of the monitor
182
+ """
183
+ monitor = self.screen
184
+ return {
185
+ "width": monitor.virtualSize().width(),
186
+ "height": monitor.virtualSize().height(),
187
+ }
188
+
189
+ def available_virtual_geometry(self) -> dict:
190
+ """
191
+ Returns the available virtual geometry of the monitor.
192
+
193
+ :return: Available virtual geometry of the monitor
194
+ """
195
+ monitor = self.screen
196
+ return {
197
+ "x": monitor.availableVirtualGeometry().x(),
198
+ "y": monitor.availableVirtualGeometry().y(),
199
+ "width": monitor.availableVirtualGeometry().width(),
200
+ "height": monitor.availableVirtualGeometry().height(),
201
+ }
202
+
203
+ def available_virtual_size(self) -> dict:
204
+ """
205
+ Returns the available virtual size of the monitor.
206
+
207
+ :return: Available virtual size of the monitor
208
+ """
209
+ monitor = self.screen
210
+ return {
211
+ "width": monitor.availableVirtualSize().width(),
212
+ "height": monitor.availableVirtualSize().height(),
213
+ }
214
+
215
+ def physical_size(self) -> dict:
216
+ """
217
+ Returns the physical size of the monitor.
218
+
219
+ :return: Physical size of the monitor
220
+ """
221
+ monitor = self.screen
222
+ return {
223
+ "width": monitor.physicalSize().width(),
224
+ "height": monitor.physicalSize().height(),
225
+ }
226
+
227
+ def depth(self) -> int:
228
+ """
229
+ Returns the depth of the monitor.
230
+
231
+ :return: Depth of the monitor
232
+ """
233
+ monitor = self.screen
234
+ return monitor.depth()
235
+
236
+ def device_pixel_ratio(self) -> float:
237
+ """
238
+ Returns the device pixel ratio of the monitor.
239
+
240
+ :return: Device pixel ratio of the monitor
241
+ """
242
+ monitor = self.screen
243
+ return monitor.devicePixelRatio()
244
+
245
+ def logical_dots_per_inch(self) -> float:
246
+ """
247
+ Returns the logical dots per inch of the monitor.
248
+
249
+ :return: Logical dots per inch of the monitor
250
+ """
251
+ monitor = self.screen
252
+ return monitor.logicalDotsPerInch()
253
+
254
+ def logical_dots_per_inch_x(self) -> float:
255
+ """
256
+ Returns the logical dots per inch X of the monitor.
257
+
258
+ :return: Logical dots per inch X of the monitor
259
+ """
260
+ monitor = self.screen
261
+ return monitor.logicalDotsPerInchX()
262
+
263
+ def logical_dots_per_inch_y(self) -> float:
264
+ """
265
+ Returns the logical dots per inch Y of the monitor.
266
+
267
+ :return: Logical dots per inch Y of the monitor
268
+ """
269
+ monitor = self.screen
270
+ return monitor.logicalDotsPerInchY()
271
+
272
+ def orientation(self) -> str:
273
+ """
274
+ Returns the orientation of the monitor.
275
+
276
+ :return: Orientation of the monitor
277
+ """
278
+ monitor = self.screen
279
+ return monitor.orientation().name
280
+
281
+ def physical_dots_per_inch(self) -> float:
282
+ """
283
+ Returns the physical dots per inch of the monitor.
284
+
285
+ :return: Physical dots per inch of the monitor
286
+ """
287
+ monitor = self.screen
288
+ return monitor.physicalDotsPerInch()
289
+
290
+ def physical_dots_per_inch_x(self) -> float:
291
+ """
292
+ Returns the physical dots per inch X of the monitor.
293
+
294
+ :return: Physical dots per inch X of the monitor
295
+ """
296
+ monitor = self.screen
297
+ return monitor.physicalDotsPerInchX()
298
+
299
+ def physical_dots_per_inch_y(self) -> float:
300
+ """
301
+ Returns the physical dots per inch Y of the monitor.
302
+
303
+ :return: Physical dots per inch Y of the monitor
304
+ """
305
+ monitor = self.screen
306
+ return monitor.physicalDotsPerInchY()
307
+
308
+ def refresh_rate(self) -> float:
309
+ """
310
+ Returns the refresh rate of the monitor.
311
+
312
+ :return: Refresh rate of the monitor
313
+ """
314
+ monitor = self.screen
315
+ return monitor.refreshRate()
316
+
317
+ def manufacturer(self) -> str:
318
+ """
319
+ Returns the manufacturer of the monitor.
320
+
321
+ :return: Manufacturer of the monitor
322
+ """
323
+ monitor = self.screen
324
+ return monitor.manufacturer()
325
+
326
+ def model(self) -> str:
327
+ """
328
+ Returns the model of the monitor.
329
+
330
+ :return: Model of the monitor
331
+ """
332
+ monitor = self.screen
333
+ return monitor.model()
334
+
335
+ def name(self) -> str:
336
+ """
337
+ Returns the name of the monitor.
338
+
339
+ :return: Name of the monitor
340
+ """
341
+ monitor = self.screen
342
+ return monitor.name()
343
+
344
+ def serial_number(self) -> str:
345
+ """
346
+ Returns the serial number of the monitor.
347
+
348
+ :return: Serial number of the monitor
349
+ """
350
+ monitor = self.screen
351
+ return monitor.serialNumber()
352
+
353
+ def geometry_changed(self, callback: Callable):
354
+ """
355
+ Returns the event that occurs when the geometry of the monitor changes.
356
+ """
357
+ monitor = self.screen
358
+ monitor.geometryChanged.connect(callback)
359
+
360
+ def orientation_changed(self, callback: Callable):
361
+ """
362
+ Returns the event that occurs when the orientation of the monitor changes.
363
+ """
364
+ monitor = self.screen
365
+ monitor.orientationChanged.connect(callback)
366
+
367
+ def refresh_rate_changed(self, callback: Callable):
368
+ """
369
+ Returns the event that occurs when the refresh rate of the monitor changes.
370
+ """
371
+ monitor = self.screen
372
+ monitor.refreshRateChanged.connect(callback)