pyloid 0.22.1__py3-none-any.whl → 0.23.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/browser_window.py +156 -84
- pyloid/js_api/base.py +234 -8
- pyloid/js_api/window_api.py +9 -52
- pyloid/pyloid.py +477 -18
- pyloid/rpc.py +339 -0
- pyloid/store.py +172 -0
- pyloid/url_interceptor.py +24 -0
- {pyloid-0.22.1.dist-info → pyloid-0.23.0.dist-info}/LICENSE +1 -1
- {pyloid-0.22.1.dist-info → pyloid-0.23.0.dist-info}/METADATA +4 -1
- {pyloid-0.22.1.dist-info → pyloid-0.23.0.dist-info}/RECORD +11 -8
- {pyloid-0.22.1.dist-info → pyloid-0.23.0.dist-info}/WHEEL +0 -0
pyloid/js_api/base.py
CHANGED
@@ -1,29 +1,255 @@
|
|
1
|
+
from typing import TYPE_CHECKING, Optional
|
2
|
+
|
1
3
|
from ..api import PyloidAPI, Bridge
|
4
|
+
from PySide6.QtCore import QByteArray, QBuffer, QIODeviceBase
|
5
|
+
import base64
|
6
|
+
from ..utils import get_platform, is_production, get_production_path
|
7
|
+
|
8
|
+
if TYPE_CHECKING:
|
9
|
+
from ..pyloid import Pyloid
|
10
|
+
|
2
11
|
|
3
12
|
class BaseAPI(PyloidAPI):
|
4
|
-
def __init__(self, window_id: str, data: dict):
|
13
|
+
def __init__(self, window_id: str, data: dict, app: "Pyloid"):
|
5
14
|
super().__init__()
|
6
15
|
self.window_id: str = window_id
|
7
16
|
self.data: dict = data
|
17
|
+
self.app: "Pyloid" = app
|
8
18
|
|
9
19
|
@Bridge(result=dict)
|
10
20
|
def getData(self):
|
11
21
|
"""Returns the shared data of the application."""
|
12
22
|
return self.data
|
13
|
-
|
23
|
+
|
24
|
+
@Bridge()
|
25
|
+
def startSystemDrag(self):
|
26
|
+
"""Starts the system drag."""
|
27
|
+
window = self.app.get_window_by_id(self.window_id)
|
28
|
+
if window:
|
29
|
+
window._window.web_view.start_system_drag()
|
30
|
+
|
14
31
|
@Bridge(result=str)
|
15
32
|
def getWindowId(self):
|
16
33
|
"""Returns the current window ID."""
|
17
34
|
return self.window_id
|
18
|
-
|
35
|
+
|
36
|
+
@Bridge(result=dict)
|
37
|
+
def getWindowProperties(self):
|
38
|
+
"""Returns the properties of the window."""
|
39
|
+
window = self.app.get_window_by_id(self.window_id)
|
40
|
+
window_properties = window.get_window_properties()
|
41
|
+
return window_properties
|
42
|
+
|
19
43
|
@Bridge()
|
20
|
-
def
|
21
|
-
"""
|
44
|
+
def close(self):
|
45
|
+
"""Closes the window."""
|
22
46
|
window = self.app.get_window_by_id(self.window_id)
|
23
47
|
if window:
|
24
|
-
window.
|
25
|
-
|
48
|
+
window.close()
|
49
|
+
|
50
|
+
@Bridge()
|
51
|
+
def hide(self):
|
52
|
+
"""Hides the window."""
|
53
|
+
window = self.app.get_window_by_id(self.window_id)
|
54
|
+
if window:
|
55
|
+
window.hide()
|
56
|
+
|
57
|
+
@Bridge()
|
58
|
+
def show(self):
|
59
|
+
"""Shows and focuses the window."""
|
60
|
+
window = self.app.get_window_by_id(self.window_id)
|
61
|
+
if window:
|
62
|
+
window.show()
|
63
|
+
|
64
|
+
@Bridge()
|
65
|
+
def focus(self):
|
66
|
+
"""Focuses the window."""
|
67
|
+
window = self.app.get_window_by_id(self.window_id)
|
68
|
+
if window:
|
69
|
+
window.focus()
|
70
|
+
|
71
|
+
@Bridge()
|
72
|
+
def showAndFocus(self):
|
73
|
+
"""Shows and focuses the window."""
|
74
|
+
window = self.app.get_window_by_id(self.window_id)
|
75
|
+
if window:
|
76
|
+
window.show_and_focus()
|
77
|
+
|
78
|
+
@Bridge()
|
79
|
+
def fullscreen(self):
|
80
|
+
"""Enters fullscreen mode."""
|
81
|
+
window = self.app.get_window_by_id(self.window_id)
|
82
|
+
if window:
|
83
|
+
window.fullscreen()
|
84
|
+
|
85
|
+
@Bridge()
|
86
|
+
def toggleFullscreen(self):
|
87
|
+
"""Toggles fullscreen mode for the window."""
|
88
|
+
window = self.app.get_window_by_id(self.window_id)
|
89
|
+
if window:
|
90
|
+
window.toggle_fullscreen()
|
91
|
+
|
92
|
+
@Bridge()
|
93
|
+
def minimize(self):
|
94
|
+
"""Minimizes the window."""
|
95
|
+
window = self.app.get_window_by_id(self.window_id)
|
96
|
+
if window:
|
97
|
+
window.minimize()
|
98
|
+
|
99
|
+
@Bridge()
|
100
|
+
def maximize(self):
|
101
|
+
"""Maximizes the window."""
|
102
|
+
window = self.app.get_window_by_id(self.window_id)
|
103
|
+
if window:
|
104
|
+
window.maximize()
|
105
|
+
|
106
|
+
@Bridge()
|
107
|
+
def unmaximize(self):
|
108
|
+
"""Restores the window to its normal state."""
|
109
|
+
window = self.app.get_window_by_id(self.window_id)
|
110
|
+
if window:
|
111
|
+
window.unmaximize()
|
112
|
+
|
113
|
+
@Bridge()
|
114
|
+
def toggleMaximize(self):
|
115
|
+
"""Toggles the maximized state of the window."""
|
116
|
+
window = self.app.get_window_by_id(self.window_id)
|
117
|
+
if window:
|
118
|
+
window.toggle_maximize()
|
119
|
+
|
120
|
+
@Bridge(result=bool)
|
121
|
+
def isFullscreen(self):
|
122
|
+
"""Returns True if the window is fullscreen."""
|
123
|
+
window = self.app.get_window_by_id(self.window_id)
|
124
|
+
return window.is_fullscreen()
|
125
|
+
|
126
|
+
@Bridge(result=bool)
|
127
|
+
def isMaximized(self):
|
128
|
+
"""Returns True if the window is maximized."""
|
129
|
+
window = self.app.get_window_by_id(self.window_id)
|
130
|
+
return window.is_maximized()
|
131
|
+
|
132
|
+
@Bridge(str)
|
133
|
+
def setTitle(self, title: str):
|
134
|
+
"""Sets the title of the window."""
|
135
|
+
window = self.app.get_window_by_id(self.window_id)
|
136
|
+
if window:
|
137
|
+
window.set_title(title)
|
138
|
+
|
139
|
+
@Bridge(int, int)
|
140
|
+
def setSize(self, width: int, height: int):
|
141
|
+
"""Sets the size of the window."""
|
142
|
+
window = self.app.get_window_by_id(self.window_id)
|
143
|
+
if window:
|
144
|
+
window.set_size(width, height)
|
145
|
+
|
146
|
+
@Bridge(int, int)
|
147
|
+
def setPosition(self, x: int, y: int):
|
148
|
+
"""Sets the position of the window."""
|
149
|
+
window = self.app.get_window_by_id(self.window_id)
|
150
|
+
if window:
|
151
|
+
window.set_position(x, y)
|
152
|
+
|
153
|
+
@Bridge(bool)
|
154
|
+
def setFrame(self, frame: bool):
|
155
|
+
"""Sets the frame of the window."""
|
156
|
+
window = self.app.get_window_by_id(self.window_id)
|
157
|
+
if window:
|
158
|
+
window.set_frame(frame)
|
159
|
+
|
160
|
+
@Bridge(result=bool)
|
161
|
+
def getFrame(self):
|
162
|
+
"""Returns whether the window has a frame."""
|
163
|
+
window = self.app.get_window_by_id(self.window_id)
|
164
|
+
return window.frame if window else False
|
165
|
+
|
166
|
+
@Bridge(result=str)
|
167
|
+
def getTitle(self):
|
168
|
+
"""Returns the title of the window."""
|
169
|
+
window = self.app.get_window_by_id(self.window_id)
|
170
|
+
return window.title if window else ""
|
171
|
+
|
172
|
+
@Bridge(result=dict)
|
173
|
+
def getSize(self):
|
174
|
+
"""Returns the size of the window."""
|
175
|
+
window = self.app.get_window_by_id(self.window_id)
|
176
|
+
return (
|
177
|
+
{"width": window.width, "height": window.height}
|
178
|
+
if window
|
179
|
+
else {"width": 0, "height": 0}
|
180
|
+
)
|
181
|
+
|
182
|
+
@Bridge(result=dict)
|
183
|
+
def getPosition(self):
|
184
|
+
"""Returns the position of the window."""
|
185
|
+
window = self.app.get_window_by_id(self.window_id)
|
186
|
+
return {"x": window.x, "y": window.y} if window else {"x": 0, "y": 0}
|
187
|
+
|
188
|
+
###############################################################
|
189
|
+
# Clipboard
|
190
|
+
###############################################################
|
191
|
+
|
192
|
+
@Bridge(str)
|
193
|
+
def setClipboardText(self, text: str):
|
194
|
+
"""Sets the text to the clipboard."""
|
195
|
+
self.app.set_clipboard_text(text)
|
196
|
+
|
197
|
+
@Bridge(result=str)
|
198
|
+
def getClipboardText(self):
|
199
|
+
"""Gets the text from the clipboard."""
|
200
|
+
return self.app.get_clipboard_text()
|
201
|
+
|
202
|
+
@Bridge(str, str)
|
203
|
+
def setClipboardImage(self, image_path: str, format: str):
|
204
|
+
"""Sets the image to the clipboard."""
|
205
|
+
self.app.set_clipboard_image(image_path, format)
|
206
|
+
|
207
|
+
@Bridge(result=str)
|
208
|
+
def getClipboardImage(self):
|
209
|
+
"""Returns the clipboard image as a Base64 encoded data URL."""
|
210
|
+
image = self.app.get_clipboard_image() # Assuming it returns QImage
|
211
|
+
if image and not image.isNull():
|
212
|
+
# Convert QImage to byte array
|
213
|
+
byte_array = QByteArray()
|
214
|
+
buffer = QBuffer(byte_array)
|
215
|
+
buffer.open(QIODeviceBase.WriteOnly)
|
216
|
+
image.save(buffer, "PNG") # Save in PNG format
|
217
|
+
|
218
|
+
# Encode to Base64
|
219
|
+
base64_data = byte_array.toBase64().data().decode()
|
220
|
+
return f"data:image/png;base64,{base64_data}"
|
221
|
+
return ""
|
222
|
+
|
223
|
+
###########################################################################################
|
224
|
+
# Quit
|
225
|
+
###########################################################################################
|
26
226
|
@Bridge()
|
27
227
|
def quit(self):
|
28
228
|
"""Quits the application."""
|
29
|
-
self.app.quit()
|
229
|
+
self.app.quit()
|
230
|
+
|
231
|
+
###########################################################################################
|
232
|
+
# Utils
|
233
|
+
###########################################################################################
|
234
|
+
@Bridge(result=str)
|
235
|
+
def getPlatform(self):
|
236
|
+
"""Returns the platform of the application.
|
237
|
+
|
238
|
+
Returns
|
239
|
+
-------
|
240
|
+
str
|
241
|
+
The platform of the application (windows, linux, macos)
|
242
|
+
"""
|
243
|
+
return get_platform()
|
244
|
+
|
245
|
+
@Bridge(result=bool)
|
246
|
+
def isProduction(self):
|
247
|
+
"""Returns True if the application is in production mode."""
|
248
|
+
return is_production()
|
249
|
+
|
250
|
+
@Bridge(str, result=str)
|
251
|
+
def getProductionPath(self, path: str):
|
252
|
+
"""Returns the production path of the application."""
|
253
|
+
return get_production_path(path)
|
254
|
+
|
255
|
+
|
pyloid/js_api/window_api.py
CHANGED
@@ -7,11 +7,12 @@
|
|
7
7
|
# if TYPE_CHECKING:
|
8
8
|
# from ..pyloid import Pyloid
|
9
9
|
|
10
|
+
|
10
11
|
# class WindowAPI(PyloidAPI):
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
12
|
+
# def __init__(self, window_id: str, app: "Pyloid"):
|
13
|
+
# super().__init__()
|
14
|
+
# self.window_id: str = window_id
|
15
|
+
# self.app: "Pyloid" = app
|
15
16
|
|
16
17
|
# @Bridge(result=str)
|
17
18
|
# def getWindowId(self):
|
@@ -107,7 +108,7 @@
|
|
107
108
|
# """Returns True if the window is fullscreen."""
|
108
109
|
# window = self.app.get_window_by_id(self.window_id)
|
109
110
|
# return window.is_fullscreen()
|
110
|
-
|
111
|
+
|
111
112
|
# @Bridge(result=bool)
|
112
113
|
# def isMaximized(self):
|
113
114
|
# """Returns True if the window is maximized."""
|
@@ -142,46 +143,12 @@
|
|
142
143
|
# if window:
|
143
144
|
# window.set_frame(frame)
|
144
145
|
|
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
146
|
# @Bridge(result=bool)
|
168
147
|
# def getFrame(self):
|
169
148
|
# """Returns whether the window has a frame."""
|
170
149
|
# window = self.app.get_window_by_id(self.window_id)
|
171
150
|
# return window.frame if window else False
|
172
151
|
|
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
152
|
# @Bridge(result=str)
|
186
153
|
# def getTitle(self):
|
187
154
|
# """Returns the title of the window."""
|
@@ -204,13 +171,6 @@
|
|
204
171
|
# window = self.app.get_window_by_id(self.window_id)
|
205
172
|
# return {"x": window.x, "y": window.y} if window else {"x": 0, "y": 0}
|
206
173
|
|
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
174
|
# ###############################################################
|
215
175
|
# # Clipboard
|
216
176
|
# ###############################################################
|
@@ -224,7 +184,7 @@
|
|
224
184
|
# def getClipboardText(self):
|
225
185
|
# """Gets the text from the clipboard."""
|
226
186
|
# return self.app.get_clipboard_text()
|
227
|
-
|
187
|
+
|
228
188
|
# @Bridge(str, str)
|
229
189
|
# def setClipboardImage(self, image_path: str, format: str):
|
230
190
|
# """Sets the image to the clipboard."""
|
@@ -240,12 +200,12 @@
|
|
240
200
|
# buffer = QBuffer(byte_array)
|
241
201
|
# buffer.open(QIODeviceBase.WriteOnly)
|
242
202
|
# image.save(buffer, "PNG") # PNG 형식으로 저장
|
243
|
-
|
203
|
+
|
244
204
|
# # Base64로 인코딩
|
245
205
|
# base64_data = byte_array.toBase64().data().decode()
|
246
206
|
# return f"data:image/png;base64,{base64_data}"
|
247
207
|
# return ""
|
248
|
-
|
208
|
+
|
249
209
|
# ###########################################################################################
|
250
210
|
# # Quit
|
251
211
|
# ###########################################################################################
|
@@ -253,6 +213,3 @@
|
|
253
213
|
# def quit(self):
|
254
214
|
# """Quits the application."""
|
255
215
|
# self.app.quit()
|
256
|
-
|
257
|
-
|
258
|
-
|