pyloid 0.20.2__py3-none-any.whl → 0.20.2.dev2__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,255 +1,255 @@
1
- from typing import TYPE_CHECKING, Optional
2
-
3
- from ..api import PyloidAPI, Bridge
4
- from PySide6.QtCore import QByteArray, QBuffer, QIODeviceBase
5
- import base64
6
-
7
- if TYPE_CHECKING:
8
- from ..pyloid import Pyloid
9
-
10
- class WindowAPI(PyloidAPI):
11
- # def __init__(self, window_id: str, app: 'Pyloid'):
12
- # super().__init__()
13
- # self.window_id: str = window_id
14
- # self.app: 'Pyloid' = app
15
-
16
- @Bridge(result=str)
17
- def getWindowId(self):
18
- """Returns the current window ID."""
19
- return self.window_id
20
-
21
- @Bridge(result=dict)
22
- def getWindowProperties(self):
23
- """Returns the properties of the window."""
24
- window = self.app.get_window_by_id(self.window_id)
25
- window_properties = window.get_window_properties()
26
- return window_properties
27
-
28
- @Bridge()
29
- def close(self):
30
- """Closes the window."""
31
- window = self.app.get_window_by_id(self.window_id)
32
- if window:
33
- window.close()
34
-
35
- @Bridge()
36
- def hide(self):
37
- """Hides the window."""
38
- window = self.app.get_window_by_id(self.window_id)
39
- if window:
40
- window.hide()
41
-
42
- @Bridge()
43
- def show(self):
44
- """Shows and focuses the window."""
45
- window = self.app.get_window_by_id(self.window_id)
46
- if window:
47
- window.show()
48
-
49
- @Bridge()
50
- def focus(self):
51
- """Focuses the window."""
52
- window = self.app.get_window_by_id(self.window_id)
53
- if window:
54
- window.focus()
55
-
56
- @Bridge()
57
- def showAndFocus(self):
58
- """Shows and focuses the window."""
59
- window = self.app.get_window_by_id(self.window_id)
60
- if window:
61
- window.show_and_focus()
62
-
63
- @Bridge()
64
- def fullscreen(self):
65
- """Enters fullscreen mode."""
66
- window = self.app.get_window_by_id(self.window_id)
67
- if window:
68
- window.fullscreen()
69
-
70
- @Bridge()
71
- def toggleFullscreen(self):
72
- """Toggles fullscreen mode for the window."""
73
- window = self.app.get_window_by_id(self.window_id)
74
- if window:
75
- window.toggle_fullscreen()
76
-
77
- @Bridge()
78
- def minimize(self):
79
- """Minimizes the window."""
80
- window = self.app.get_window_by_id(self.window_id)
81
- if window:
82
- window.minimize()
83
-
84
- @Bridge()
85
- def maximize(self):
86
- """Maximizes the window."""
87
- window = self.app.get_window_by_id(self.window_id)
88
- if window:
89
- window.maximize()
90
-
91
- @Bridge()
92
- def unmaximize(self):
93
- """Restores the window to its normal state."""
94
- window = self.app.get_window_by_id(self.window_id)
95
- if window:
96
- window.unmaximize()
97
-
98
- @Bridge()
99
- def toggleMaximize(self):
100
- """Toggles the maximized state of the window."""
101
- window = self.app.get_window_by_id(self.window_id)
102
- if window:
103
- window.toggle_maximize()
104
-
105
- @Bridge(result=bool)
106
- def isFullscreen(self):
107
- """Returns True if the window is fullscreen."""
108
- window = self.app.get_window_by_id(self.window_id)
109
- return window.is_fullscreen()
110
-
111
- @Bridge(result=bool)
112
- def isMaximized(self):
113
- """Returns True if the window is maximized."""
114
- window = self.app.get_window_by_id(self.window_id)
115
- return window.is_maximized()
116
-
117
- @Bridge(str)
118
- def setTitle(self, title: str):
119
- """Sets the title of the window."""
120
- window = self.app.get_window_by_id(self.window_id)
121
- if window:
122
- window.set_title(title)
123
-
124
- @Bridge(int, int)
125
- def setSize(self, width: int, height: int):
126
- """Sets the size of the window."""
127
- window = self.app.get_window_by_id(self.window_id)
128
- if window:
129
- window.set_size(width, height)
130
-
131
- @Bridge(int, int)
132
- def setPosition(self, x: int, y: int):
133
- """Sets the position of the window."""
134
- window = self.app.get_window_by_id(self.window_id)
135
- if window:
136
- window.set_position(x, y)
137
-
138
- @Bridge(bool)
139
- def setFrame(self, frame: bool):
140
- """Sets the frame of the window."""
141
- window = self.app.get_window_by_id(self.window_id)
142
- if window:
143
- window.set_frame(frame)
144
-
145
- @Bridge(bool)
146
- def setContextMenu(self, context_menu: bool):
147
- """Sets the context menu of the window."""
148
- window = self.app.get_window_by_id(self.window_id)
149
- if window:
150
- window.set_context_menu(context_menu)
151
-
152
- @Bridge(bool)
153
- def setDevTools(self, enable: bool):
154
- """Sets the developer tools of the window."""
155
- window = self.app.get_window_by_id(self.window_id)
156
- if window:
157
- window.set_dev_tools(enable)
158
-
159
- @Bridge(str, result=Optional[str])
160
- def capture(self, save_path: str) -> Optional[str]:
161
- """Captures the current window."""
162
- window = self.app.get_window_by_id(self.window_id)
163
- if window:
164
- return window.capture(save_path)
165
- return None
166
-
167
- @Bridge(result=bool)
168
- def getFrame(self):
169
- """Returns whether the window has a frame."""
170
- window = self.app.get_window_by_id(self.window_id)
171
- return window.frame if window else False
172
-
173
- @Bridge(result=bool)
174
- def getContextMenu(self):
175
- """Returns whether the window has a context menu."""
176
- window = self.app.get_window_by_id(self.window_id)
177
- return window.context_menu if window else False
178
-
179
- @Bridge(result=bool)
180
- def getDevTools(self):
181
- """Returns whether the window has developer tools."""
182
- window = self.app.get_window_by_id(self.window_id)
183
- return window.dev_tools if window else False
184
-
185
- @Bridge(result=str)
186
- def getTitle(self):
187
- """Returns the title of the window."""
188
- window = self.app.get_window_by_id(self.window_id)
189
- return window.title if window else ""
190
-
191
- @Bridge(result=dict)
192
- def getSize(self):
193
- """Returns the size of the window."""
194
- window = self.app.get_window_by_id(self.window_id)
195
- return (
196
- {"width": window.width, "height": window.height}
197
- if window
198
- else {"width": 0, "height": 0}
199
- )
200
-
201
- @Bridge(result=dict)
202
- def getPosition(self):
203
- """Returns the position of the window."""
204
- window = self.app.get_window_by_id(self.window_id)
205
- return {"x": window.x, "y": window.y} if window else {"x": 0, "y": 0}
206
-
207
- @Bridge()
208
- def startSystemDrag(self):
209
- """Starts the system drag."""
210
- window = self.app.get_window_by_id(self.window_id)
211
- if window:
212
- window.web_view.start_system_drag()
213
-
214
- ###############################################################
215
- # Clipboard
216
- ###############################################################
217
-
218
- @Bridge(str)
219
- def setClipboardText(self, text: str):
220
- """Sets the text to the clipboard."""
221
- self.app.set_clipboard_text(text)
222
-
223
- @Bridge(result=str)
224
- def getClipboardText(self):
225
- """Gets the text from the clipboard."""
226
- return self.app.get_clipboard_text()
227
-
228
- @Bridge(str, str)
229
- def setClipboardImage(self, image_path: str, format: str):
230
- """Sets the image to the clipboard."""
231
- self.app.set_clipboard_image(image_path, format)
232
-
233
- @Bridge(result=str)
234
- def getClipboardImage(self):
235
- """클립보드의 이미지를 Base64 인코딩된 데이터 URL로 반환합니다."""
236
- image = self.app.get_clipboard_image() # QImage 반환 가정
237
- if image and not image.isNull():
238
- # QImage를 바이트 배열로 변환
239
- byte_array = QByteArray()
240
- buffer = QBuffer(byte_array)
241
- buffer.open(QIODeviceBase.WriteOnly)
242
- image.save(buffer, "PNG") # PNG 형식으로 저장
243
-
244
- # Base64로 인코딩
245
- base64_data = byte_array.toBase64().data().decode()
246
- return f"data:image/png;base64,{base64_data}"
247
- return ""
248
-
249
- ###########################################################################################
250
- # Quit
251
- ###########################################################################################
252
- @Bridge()
253
- def quit(self):
254
- """Quits the application."""
255
- self.app.quit()
1
+ from typing import TYPE_CHECKING, Optional
2
+
3
+ from ..api import PyloidAPI, Bridge
4
+ from PySide6.QtCore import QByteArray, QBuffer, QIODeviceBase
5
+ import base64
6
+
7
+ if TYPE_CHECKING:
8
+ from ..pyloid import Pyloid
9
+
10
+ class WindowAPI(PyloidAPI):
11
+ # def __init__(self, window_id: str, app: 'Pyloid'):
12
+ # super().__init__()
13
+ # self.window_id: str = window_id
14
+ # self.app: 'Pyloid' = app
15
+
16
+ @Bridge(result=str)
17
+ def getWindowId(self):
18
+ """Returns the current window ID."""
19
+ return self.window_id
20
+
21
+ @Bridge(result=dict)
22
+ def getWindowProperties(self):
23
+ """Returns the properties of the window."""
24
+ window = self.app.get_window_by_id(self.window_id)
25
+ window_properties = window.get_window_properties()
26
+ return window_properties
27
+
28
+ @Bridge()
29
+ def close(self):
30
+ """Closes the window."""
31
+ window = self.app.get_window_by_id(self.window_id)
32
+ if window:
33
+ window.close()
34
+
35
+ @Bridge()
36
+ def hide(self):
37
+ """Hides the window."""
38
+ window = self.app.get_window_by_id(self.window_id)
39
+ if window:
40
+ window.hide()
41
+
42
+ @Bridge()
43
+ def show(self):
44
+ """Shows and focuses the window."""
45
+ window = self.app.get_window_by_id(self.window_id)
46
+ if window:
47
+ window.show()
48
+
49
+ @Bridge()
50
+ def focus(self):
51
+ """Focuses the window."""
52
+ window = self.app.get_window_by_id(self.window_id)
53
+ if window:
54
+ window.focus()
55
+
56
+ @Bridge()
57
+ def showAndFocus(self):
58
+ """Shows and focuses the window."""
59
+ window = self.app.get_window_by_id(self.window_id)
60
+ if window:
61
+ window.show_and_focus()
62
+
63
+ @Bridge()
64
+ def fullscreen(self):
65
+ """Enters fullscreen mode."""
66
+ window = self.app.get_window_by_id(self.window_id)
67
+ if window:
68
+ window.fullscreen()
69
+
70
+ @Bridge()
71
+ def toggleFullscreen(self):
72
+ """Toggles fullscreen mode for the window."""
73
+ window = self.app.get_window_by_id(self.window_id)
74
+ if window:
75
+ window.toggle_fullscreen()
76
+
77
+ @Bridge()
78
+ def minimize(self):
79
+ """Minimizes the window."""
80
+ window = self.app.get_window_by_id(self.window_id)
81
+ if window:
82
+ window.minimize()
83
+
84
+ @Bridge()
85
+ def maximize(self):
86
+ """Maximizes the window."""
87
+ window = self.app.get_window_by_id(self.window_id)
88
+ if window:
89
+ window.maximize()
90
+
91
+ @Bridge()
92
+ def unmaximize(self):
93
+ """Restores the window to its normal state."""
94
+ window = self.app.get_window_by_id(self.window_id)
95
+ if window:
96
+ window.unmaximize()
97
+
98
+ @Bridge()
99
+ def toggleMaximize(self):
100
+ """Toggles the maximized state of the window."""
101
+ window = self.app.get_window_by_id(self.window_id)
102
+ if window:
103
+ window.toggle_maximize()
104
+
105
+ @Bridge(result=bool)
106
+ def isFullscreen(self):
107
+ """Returns True if the window is fullscreen."""
108
+ window = self.app.get_window_by_id(self.window_id)
109
+ return window.is_fullscreen()
110
+
111
+ @Bridge(result=bool)
112
+ def isMaximized(self):
113
+ """Returns True if the window is maximized."""
114
+ window = self.app.get_window_by_id(self.window_id)
115
+ return window.is_maximized()
116
+
117
+ @Bridge(str)
118
+ def setTitle(self, title: str):
119
+ """Sets the title of the window."""
120
+ window = self.app.get_window_by_id(self.window_id)
121
+ if window:
122
+ window.set_title(title)
123
+
124
+ @Bridge(int, int)
125
+ def setSize(self, width: int, height: int):
126
+ """Sets the size of the window."""
127
+ window = self.app.get_window_by_id(self.window_id)
128
+ if window:
129
+ window.set_size(width, height)
130
+
131
+ @Bridge(int, int)
132
+ def setPosition(self, x: int, y: int):
133
+ """Sets the position of the window."""
134
+ window = self.app.get_window_by_id(self.window_id)
135
+ if window:
136
+ window.set_position(x, y)
137
+
138
+ @Bridge(bool)
139
+ def setFrame(self, frame: bool):
140
+ """Sets the frame of the window."""
141
+ window = self.app.get_window_by_id(self.window_id)
142
+ if window:
143
+ window.set_frame(frame)
144
+
145
+ @Bridge(bool)
146
+ def setContextMenu(self, context_menu: bool):
147
+ """Sets the context menu of the window."""
148
+ window = self.app.get_window_by_id(self.window_id)
149
+ if window:
150
+ window.set_context_menu(context_menu)
151
+
152
+ @Bridge(bool)
153
+ def setDevTools(self, enable: bool):
154
+ """Sets the developer tools of the window."""
155
+ window = self.app.get_window_by_id(self.window_id)
156
+ if window:
157
+ window.set_dev_tools(enable)
158
+
159
+ @Bridge(str, result=Optional[str])
160
+ def capture(self, save_path: str) -> Optional[str]:
161
+ """Captures the current window."""
162
+ window = self.app.get_window_by_id(self.window_id)
163
+ if window:
164
+ return window.capture(save_path)
165
+ return None
166
+
167
+ @Bridge(result=bool)
168
+ def getFrame(self):
169
+ """Returns whether the window has a frame."""
170
+ window = self.app.get_window_by_id(self.window_id)
171
+ return window.frame if window else False
172
+
173
+ @Bridge(result=bool)
174
+ def getContextMenu(self):
175
+ """Returns whether the window has a context menu."""
176
+ window = self.app.get_window_by_id(self.window_id)
177
+ return window.context_menu if window else False
178
+
179
+ @Bridge(result=bool)
180
+ def getDevTools(self):
181
+ """Returns whether the window has developer tools."""
182
+ window = self.app.get_window_by_id(self.window_id)
183
+ return window.dev_tools if window else False
184
+
185
+ @Bridge(result=str)
186
+ def getTitle(self):
187
+ """Returns the title of the window."""
188
+ window = self.app.get_window_by_id(self.window_id)
189
+ return window.title if window else ""
190
+
191
+ @Bridge(result=dict)
192
+ def getSize(self):
193
+ """Returns the size of the window."""
194
+ window = self.app.get_window_by_id(self.window_id)
195
+ return (
196
+ {"width": window.width, "height": window.height}
197
+ if window
198
+ else {"width": 0, "height": 0}
199
+ )
200
+
201
+ @Bridge(result=dict)
202
+ def getPosition(self):
203
+ """Returns the position of the window."""
204
+ window = self.app.get_window_by_id(self.window_id)
205
+ return {"x": window.x, "y": window.y} if window else {"x": 0, "y": 0}
206
+
207
+ @Bridge()
208
+ def startSystemDrag(self):
209
+ """Starts the system drag."""
210
+ window = self.app.get_window_by_id(self.window_id)
211
+ if window:
212
+ window.web_view.start_system_drag()
213
+
214
+ ###############################################################
215
+ # Clipboard
216
+ ###############################################################
217
+
218
+ @Bridge(str)
219
+ def setClipboardText(self, text: str):
220
+ """Sets the text to the clipboard."""
221
+ self.app.set_clipboard_text(text)
222
+
223
+ @Bridge(result=str)
224
+ def getClipboardText(self):
225
+ """Gets the text from the clipboard."""
226
+ return self.app.get_clipboard_text()
227
+
228
+ @Bridge(str, str)
229
+ def setClipboardImage(self, image_path: str, format: str):
230
+ """Sets the image to the clipboard."""
231
+ self.app.set_clipboard_image(image_path, format)
232
+
233
+ @Bridge(result=str)
234
+ def getClipboardImage(self):
235
+ """클립보드의 이미지를 Base64 인코딩된 데이터 URL로 반환합니다."""
236
+ image = self.app.get_clipboard_image() # QImage 반환 가정
237
+ if image and not image.isNull():
238
+ # QImage를 바이트 배열로 변환
239
+ byte_array = QByteArray()
240
+ buffer = QBuffer(byte_array)
241
+ buffer.open(QIODeviceBase.WriteOnly)
242
+ image.save(buffer, "PNG") # PNG 형식으로 저장
243
+
244
+ # Base64로 인코딩
245
+ base64_data = byte_array.toBase64().data().decode()
246
+ return f"data:image/png;base64,{base64_data}"
247
+ return ""
248
+
249
+ ###########################################################################################
250
+ # Quit
251
+ ###########################################################################################
252
+ @Bridge()
253
+ def quit(self):
254
+ """Quits the application."""
255
+ self.app.quit()