pyloid 0.21.0.dev1__py3-none-any.whl → 0.22.0.dev1__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 CHANGED
@@ -8,13 +8,11 @@ from PySide6.QtWebChannel import QWebChannel
8
8
  from PySide6.QtGui import (
9
9
  QKeySequence,
10
10
  QShortcut,
11
- QCursor,
12
11
  )
13
- from PySide6.QtCore import Qt, QPoint, QUrl, QEvent, QFile
12
+ from PySide6.QtCore import Qt, QPoint, QUrl, QEvent, QFile, QEventLoop, QTimer, QObject, Signal, Slot
14
13
  from PySide6.QtWebEngineCore import (
15
14
  QWebEnginePage,
16
15
  QWebEngineSettings,
17
- QWebEngineUrlRequestInterceptor,
18
16
  )
19
17
  from .api import PyloidAPI
20
18
  import uuid
@@ -25,19 +23,14 @@ from PySide6.QtWidgets import (
25
23
  QVBoxLayout,
26
24
  )
27
25
  from .custom.titlebar import CustomTitleBar
28
- from .js_api.window_api import WindowAPI
26
+ from .js_api.base import BaseAPI
29
27
  from PySide6.QtGui import QPixmap, QMovie
30
28
  from PySide6.QtWidgets import QSplashScreen, QLabel
31
- from typing import TYPE_CHECKING
32
- from PySide6.QtWebEngineCore import (
33
- QWebEngineSettings,
34
- QWebEngineDesktopMediaRequest,
35
- QWebEngineUrlRequestInterceptor,
36
- )
37
- from .utils import get_production_path, is_production
29
+ from typing import TYPE_CHECKING, Any
30
+ from PySide6.QtWebEngineCore import QWebEngineSettings, QWebEngineDesktopMediaRequest
38
31
 
39
32
  if TYPE_CHECKING:
40
- from ..pyloid import Pyloid
33
+ from .pyloid import _Pyloid
41
34
 
42
35
 
43
36
  class CustomWebPage(QWebEnginePage):
@@ -72,6 +65,7 @@ class CustomWebPage(QWebEnginePage):
72
65
  self._permission_handlers[feature] = handler
73
66
 
74
67
  def _handleDesktopMediaRequest(self, request: QWebEngineDesktopMediaRequest):
68
+ return
75
69
  print("Desktop media request received:", request)
76
70
 
77
71
  # 사용 가능한 화면 목록 확인
@@ -89,79 +83,66 @@ class CustomWebPage(QWebEnginePage):
89
83
  window_index = windows_model.index(i)
90
84
  window_name = windows_model.data(window_index)
91
85
  print(f"Window {i}: {window_name}")
92
-
86
+
93
87
  request.selectWindow(windows_model.index(3))
94
88
 
95
- # interceptor ( navigation request )
96
- def acceptNavigationRequest(self, url, navigation_type, is_main_frame):
97
- """네비게이션 요청을 처리하는 메서드"""
98
- url_string = url.toString()
99
- print(f"Navigation Request - URL: {url_string}")
100
- print(f"Navigation Type: {navigation_type}")
101
- print(f"Is Main Frame: {is_main_frame}")
89
+ # # interceptor ( navigation request )
90
+ # def acceptNavigationRequest(self, url, navigation_type, is_main_frame):
91
+ # """네비게이션 요청을 처리하는 메서드"""
92
+ # print(f"Navigation Request - URL: {url.toString()}")
93
+ # print(f"Navigation Type: {navigation_type}")
94
+ # print(f"Is Main Frame: {is_main_frame}")
102
95
 
103
- # file:// 프로토콜 처리
104
- if url.scheme() == "file":
105
- # 파일 경로에서 file:/// 제거
106
- file_path = url_string.replace("file:///", "").rstrip("/")
107
-
108
- # HTML 파일이 아닌 경우에만 index.html로 리다이렉트
109
- if not file_path.endswith(".html"):
110
- base_path = os.path.dirname(file_path)
111
- self.setUrl(QUrl.fromLocalFile(os.path.join(base_path, "index.html")))
112
- return False
113
-
114
- return True
96
+ # return True
115
97
 
116
98
 
117
99
  # interceptor ( all url request )
118
- class CustomUrlInterceptor(QWebEngineUrlRequestInterceptor):
119
- def interceptRequest(self, info):
120
- url = info.requestUrl().toString()
121
- print(url)
122
-
100
+ # class CustomUrlInterceptor(QWebEngineUrlRequestInterceptor):
101
+ # def interceptRequest(self, info):
102
+ # url = info.requestUrl().toString()
103
+ # print(url)
123
104
 
124
105
  # class CustomInterceptor(QWebEngineUrlRequestInterceptor):
125
106
  # def __init__(self, index_path=None):
126
107
  # super().__init__()
127
108
  # self.index_path = get_production_path()
128
109
  # self.last_path = "/"
129
-
110
+
130
111
  # def interceptRequest(self, info):
131
112
  # url = info.requestUrl()
132
113
  # navigation_type = info.navigationType()
133
114
 
134
115
  # print("--------------------------------")
135
-
116
+
136
117
  # if navigation_type == QWebEnginePage.NavigationType.NavigationTypeTyped:
137
118
  # print("NavigationTypeTyped")
138
-
119
+
139
120
  # if navigation_type == QWebEnginePage.NavigationType.NavigationTypeReload:
140
121
  # print("NavigationTypeReload")
141
-
122
+
142
123
  # if navigation_type == QWebEnginePage.NavigationType.NavigationTypeBackForward:
143
124
  # print("NavigationTypeBackForward")
144
-
125
+
145
126
  # if navigation_type == QWebEnginePage.NavigationType.NavigationTypeLinkClicked:
146
127
  # print("NavigationTypeLinkClicked")
147
-
128
+
148
129
  # if navigation_type == QWebEnginePage.NavigationType.NavigationTypeFormSubmitted:
149
130
  # print("NavigationTypeFormSubmitted")
150
-
131
+
151
132
  # if navigation_type == QWebEnginePage.NavigationType.NavigationTypeTyped:
152
133
  # print("NavigationTypeTyped")
153
-
134
+
154
135
  # if navigation_type == QWebEnginePage.NavigationType.NavigationTypeOther:
155
136
  # print("NavigationTypeOther")
156
-
137
+
157
138
  # print(navigation_type.value)
158
-
139
+
159
140
  # print(url)
160
141
  # print(url.scheme())
161
142
  # print(url.host())
162
143
  # print(url.url())
163
144
  # print(self.last_path)
164
-
145
+
165
146
  # self.last_path = url.path()
166
147
 
167
148
 
@@ -307,10 +288,10 @@ class CustomWebEngineView(QWebEngineView):
307
288
  self.resize_start_pos = global_pos
308
289
 
309
290
 
310
- class BrowserWindow:
291
+ class _BrowserWindow:
311
292
  def __init__(
312
293
  self,
313
- app: "Pyloid",
294
+ app: "_Pyloid",
314
295
  title: str = "pyloid app",
315
296
  width: int = 800,
316
297
  height: int = 600,
@@ -337,7 +318,7 @@ class BrowserWindow:
337
318
  self.frame = frame
338
319
  self.context_menu = context_menu
339
320
  self.dev_tools = dev_tools
340
- self.js_apis = [WindowAPI()]
321
+ self.js_apis = [BaseAPI(self.id, self.app.data)]
341
322
  for js_api in js_apis:
342
323
  self.js_apis.append(js_api)
343
324
  self.shortcuts = {}
@@ -489,10 +470,10 @@ class BrowserWindow:
489
470
 
490
471
  # Set F12 shortcut
491
472
  self.set_dev_tools(self.dev_tools)
492
-
473
+
493
474
  # 프로필 가져오기 및 인터셉터 설정
494
475
  profile = self.web_view.page().profile()
495
-
476
+
496
477
  # # 기존 인터셉터가 있다면 제거
497
478
  # if self.interceptor:
498
479
  # profile.setUrlRequestInterceptor(None)
@@ -885,9 +866,9 @@ class BrowserWindow:
885
866
 
886
867
  def _remove_from_app_windows(self):
887
868
  """Removes the window from the app's window list."""
888
- if self in self.app.windows:
889
- self.app.windows.remove(self)
890
- if not self.app.windows:
869
+ if self in self.app.windows_dict:
870
+ self.app.windows_dict.pop(self.id)
871
+ if not self.app.windows_dict:
891
872
  self.app.quit() # Quit the app if all windows are closed
892
873
 
893
874
  ###########################################################################################
@@ -927,11 +908,14 @@ class BrowserWindow:
927
908
  >>> window = app.create_window("pyloid-window")
928
909
  >>> window.focus()
929
910
  """
911
+ was_on_top = bool(self._window.windowFlags() & Qt.WindowStaysOnTopHint)
912
+ if not was_on_top:
913
+ self._window.setWindowFlag(Qt.WindowStaysOnTopHint, True)
914
+ self._window.show()
930
915
  self._window.activateWindow()
931
- self._window.raise_()
932
- self._window.setWindowState(
933
- self._window.windowState() & ~Qt.WindowMinimized | Qt.WindowActive
934
- )
916
+ if not was_on_top:
917
+ self._window.setWindowFlag(Qt.WindowStaysOnTopHint, False)
918
+ self._window.show()
935
919
 
936
920
  def show_and_focus(self):
937
921
  """
@@ -943,12 +927,14 @@ class BrowserWindow:
943
927
  >>> window = app.create_window("pyloid-window")
944
928
  >>> window.show_and_focus()
945
929
  """
946
- self._window.show()
930
+ was_on_top = bool(self._window.windowFlags() & Qt.WindowStaysOnTopHint)
931
+ if not was_on_top:
932
+ self._window.setWindowFlag(Qt.WindowStaysOnTopHint, True)
933
+ self._window.show()
947
934
  self._window.activateWindow()
948
- self._window.raise_()
949
- self._window.setWindowState(
950
- self._window.windowState() & ~Qt.WindowMinimized | Qt.WindowActive
951
- )
935
+ if not was_on_top:
936
+ self._window.setWindowFlag(Qt.WindowStaysOnTopHint, False)
937
+ self._window.show()
952
938
 
953
939
  def close(self):
954
940
  """
@@ -1190,9 +1176,9 @@ class BrowserWindow:
1190
1176
  ###########################################################################################
1191
1177
  # Event (Calling the JS from Python)
1192
1178
  ###########################################################################################
1193
- def emit(self, event_name, data: Optional[Dict] = None):
1179
+ def invoke(self, event_name, data: Optional[Dict] = None):
1194
1180
  """
1195
- Emits an event to the JavaScript side.
1181
+ Invokes an event to the JavaScript side.
1196
1182
 
1197
1183
  Parameters
1198
1184
  ----------
@@ -1208,7 +1194,7 @@ class BrowserWindow:
1208
1194
  app = Pyloid(app_name="Pyloid-App")
1209
1195
 
1210
1196
  window = app.create_window("pyloid-window")
1211
- window.emit("customEvent", {"message": "Hello, Pyloid!"})
1197
+ window.invoke("customEvent", {"message": "Hello, Pyloid!"})
1212
1198
 
1213
1199
  app.run()
1214
1200
  ```
@@ -1590,52 +1576,52 @@ class BrowserWindow:
1590
1576
  ###########################################################################################
1591
1577
  # For Custom Pyside6 Features
1592
1578
  ###########################################################################################
1593
- def get_QMainWindow(self) -> QMainWindow:
1594
- """
1595
- Returns the QMainWindow object of the window.
1579
+ # def get_QMainWindow(self) -> QMainWindow:
1580
+ # """
1581
+ # Returns the QMainWindow object of the window.
1596
1582
 
1597
- you can use all the features of QMainWindow for customizing the window.
1583
+ # you can use all the features of QMainWindow for customizing the window.
1598
1584
 
1599
- Returns
1600
- -------
1601
- QMainWindow
1602
- QMainWindow object of the window
1585
+ # Returns
1586
+ # -------
1587
+ # QMainWindow
1588
+ # QMainWindow object of the window
1603
1589
 
1604
- Examples
1605
- --------
1606
- ```python
1607
- from PySide6.QtCore import Qt
1608
- from pyloid import Pyloid
1590
+ # Examples
1591
+ # --------
1592
+ # ```python
1593
+ # from PySide6.QtCore import Qt
1594
+ # from pyloid import Pyloid
1609
1595
 
1610
- app = Pyloid(app_name="Pyloid-App")
1596
+ # app = Pyloid(app_name="Pyloid-App")
1611
1597
 
1612
- window = app.create_window("pyloid-window")
1613
- qmain = window.get_QMainWindow()
1598
+ # window = app.create_window("pyloid-window")
1599
+ # qmain = window.get_QMainWindow()
1614
1600
 
1615
- qmain.setWindowFlags(qmain.windowFlags() | Qt.WindowStaysOnTopHint) # window stays on top
1616
- ```
1617
- """
1618
- return self._window
1601
+ # qmain.setWindowFlags(qmain.windowFlags() | Qt.WindowStaysOnTopHint) # window stays on top
1602
+ # ```
1603
+ # """
1604
+ # return self._window
1619
1605
 
1620
- def get_QWebEngineView(self) -> CustomWebEngineView:
1621
- """
1622
- Returns the CustomWebEngineView object which inherits from QWebEngineView.
1606
+ # def get_QWebEngineView(self) -> CustomWebEngineView:
1607
+ # """
1608
+ # Returns the CustomWebEngineView object which inherits from QWebEngineView.
1623
1609
 
1624
- Returns
1625
- -------
1626
- CustomWebEngineView
1627
- CustomWebEngineView object of the window
1610
+ # Returns
1611
+ # -------
1612
+ # CustomWebEngineView
1613
+ # CustomWebEngineView object of the window
1628
1614
 
1629
- Examples
1630
- --------
1631
- ```python
1632
- window = app.create_window("pyloid-window")
1633
- web_view = window.get_QWebEngineView()
1615
+ # Examples
1616
+ # --------
1617
+ # ```python
1618
+ # window = app.create_window("pyloid-window")
1619
+ # web_view = window.get_QWebEngineView()
1634
1620
 
1635
- web_view.page().runJavaScript("console.log('Hello, Pyloid!')")
1636
- ```
1637
- """
1638
- return self.web_view
1621
+ # web_view.page().runJavaScript("console.log('Hello, Pyloid!')")
1622
+ # ```
1623
+ # """
1624
+ # return self.web_view
1639
1625
 
1640
1626
  ###########################################################################################
1641
1627
  # QMainWindow flags
@@ -1733,7 +1719,7 @@ class BrowserWindow:
1733
1719
  Examples
1734
1720
  --------
1735
1721
  ```python
1736
- window.set_image_splash_screen("./assets/loading.png", close_on_load=True, stay_on_top=True)
1722
+ window.set_static_image_splash_screen("./assets/loading.png", close_on_load=True, stay_on_top=True)
1737
1723
  ```
1738
1724
  """
1739
1725
  pixmap = QPixmap(image_path)
@@ -1871,150 +1857,1121 @@ class BrowserWindow:
1871
1857
  ###########################################################################################
1872
1858
  # WebEngineView Attribute setting
1873
1859
  ###########################################################################################
1874
- def set_web_engine_view_attribute(self, attribute: QWebEngineSettings, on: bool):
1860
+ # def set_web_engine_view_attribute(self, attribute: QWebEngineSettings, on: bool):
1861
+ # """
1862
+ # Sets the attribute of the WebEngineView.
1863
+
1864
+ # Parameters
1865
+ # ----------
1866
+ # attribute : QWebEngineSettings
1867
+ # Attribute to set
1868
+ # on : bool
1869
+ # True to enable the attribute, False to disable it
1870
+
1871
+ # Examples
1872
+ # --------
1873
+ # ```python
1874
+ # window.set_web_engine_view_attribute(QWebEngineSettings.WebAttribute.ScreenCaptureEnabled, False)
1875
+ # ```
1876
+ # """
1877
+ # settings = self.web_view.settings()
1878
+ # settings.setAttribute(attribute, on)
1879
+
1880
+ # def is_web_engine_view_attribute(self, attribute: QWebEngineSettings) -> bool:
1881
+ # """
1882
+ # Returns the attribute of the WebEngineView.
1883
+
1884
+ # Parameters
1885
+ # ----------
1886
+ # attribute : QWebEngineSettings
1887
+ # Attribute to get
1888
+
1889
+ # Returns
1890
+ # -------
1891
+ # bool
1892
+ # True if the attribute is enabled, False otherwise
1893
+
1894
+ # Examples
1895
+ # --------
1896
+ # ```python
1897
+ # window.is_web_engine_view_attribute(QWebEngineSettings.WebAttribute.ScreenCaptureEnabled)
1898
+ # ```
1899
+ # """
1900
+ # settings = self.web_view.settings()
1901
+ # return settings.testAttribute(attribute)
1902
+
1903
+ # def set_permission_handler(self, feature: QWebEnginePage.Feature, handler):
1904
+ # """
1905
+ # Sets a handler for a specific permission.
1906
+
1907
+ # Parameters
1908
+ # ----------
1909
+ # feature : QWebEnginePage.Feature
1910
+ # The type of permission to set
1911
+ # handler : callable
1912
+ # The handler function to process the permission request
1913
+
1914
+ # Examples
1915
+ # --------
1916
+ # ```python
1917
+ # def handle_camera(origin, feature):
1918
+ # window.web_view.page().setFeaturePermission(
1919
+ # origin,
1920
+ # feature,
1921
+ # QWebEnginePage.PermissionPolicy.PermissionGrantedByUser
1922
+ # )
1923
+
1924
+ # window.set_permission_handler(
1925
+ # QWebEnginePage.Feature.MediaVideoCapture,
1926
+ # handle_camera
1927
+ # )
1928
+ # ```
1929
+ # """
1930
+ # self.web_view.custom_page.setPermissionHandler(feature, handler)
1931
+
1932
+ # def grant_permission(self, feature: QWebEnginePage.Feature):
1933
+ # """
1934
+ # Automatically grants a specific permission when a request is made.
1935
+
1936
+ # Parameters
1937
+ # ----------
1938
+ # feature : QWebEnginePage.Feature
1939
+ # The type of permission to automatically grant
1940
+
1941
+ # Examples
1942
+ # --------
1943
+ # ```python
1944
+ # window.grant_permission(QWebEnginePage.Feature.MediaVideoCapture)
1945
+ # ```
1946
+ # """
1947
+
1948
+ # def auto_grant(origin, feat):
1949
+ # self.web_view.page().setFeaturePermission(
1950
+ # origin, feat, QWebEnginePage.PermissionPolicy.PermissionGrantedByUser
1951
+ # )
1952
+
1953
+ # self.set_permission_handler(feature, auto_grant)
1954
+
1955
+ # def deny_permission(self, feature: QWebEnginePage.Feature):
1956
+ # """
1957
+ # Automatically denies a specific permission when a request is made.
1958
+
1959
+ # Parameters
1960
+ # ----------
1961
+ # feature : QWebEnginePage.Feature
1962
+ # The type of permission to automatically deny
1963
+
1964
+ # Examples
1965
+ # --------
1966
+ # ```python
1967
+ # window.deny_permission(QWebEnginePage.Feature.Notifications)
1968
+ # ```
1969
+ # """
1970
+
1971
+ # def auto_deny(origin, feat):
1972
+ # self.web_view.page().setFeaturePermission(
1973
+ # origin, feat, QWebEnginePage.PermissionPolicy.PermissionDeniedByUser
1974
+ # )
1975
+
1976
+ # self.set_permission_handler(feature, auto_deny)
1977
+
1978
+ # def set_desktop_media_handler(self, handler):
1979
+ # """
1980
+ # 데스크톱 미디어(화면/윈도우) 선택 핸들러를 설정합니다.
1981
+
1982
+ # Parameters
1983
+ # ----------
1984
+ # handler : callable
1985
+ # 요청을 처리할 핸들러 함수. QWebEngineDesktopMediaRequest 인자로 받습니다.
1986
+
1987
+ # Examples
1988
+ # --------
1989
+ # ```python
1990
+ # def custom_media_handler(request):
1991
+ # # 사용 가능한 화면 목록 출력
1992
+ # for screen in request.screenList():
1993
+ # print(f"Screen: {screen.name}")
1994
+
1995
+ # # 사용 가능한 윈도우 목록 출력
1996
+ # for window in request.windowList():
1997
+ # print(f"Window: {window.name}")
1998
+
1999
+ # # 첫 번째 화면 선택
2000
+ # if request.screenList():
2001
+ # request.selectScreen(request.screenList()[0])
2002
+
2003
+ # window.set_desktop_media_handler(custom_media_handler)
2004
+ # ```
2005
+ # """
2006
+ # self.web_view.custom_page.setDesktopMediaHandler(handler)
2007
+
2008
+
2009
+ # This wrapper class work in other thread
2010
+ class BrowserWindow(QObject):
2011
+ command_signal = Signal(str, str, object)
2012
+ result_signal = Signal(str, object)
2013
+
2014
+ def __init__(self, app, title: str, width: int, height: int, x: int, y: int, frame: bool, context_menu: bool, dev_tools: bool, js_apis: List[PyloidAPI]):
2015
+ super().__init__()
2016
+ self.window = _BrowserWindow(app, title, width, height, x, y, frame, context_menu, dev_tools, js_apis)
2017
+ self.command_signal.connect(self._handle_command)
2018
+
2019
+ @Slot(str, str, object)
2020
+ def _handle_command(self, command_id: str, command_type: str, params: object) -> None:
2021
+ """
2022
+ Handles commands sent from multiple threads.
2023
+ Calls the corresponding method of _BrowserWindow based on the command type and returns the result.
2024
+
2025
+ :param command_id: Unique identifier for each command
2026
+ :param command_type: Type of command to execute (e.g., "load_file", "set_title", etc.)
2027
+ :param params: Object containing parameters needed for command execution
2028
+ """
2029
+ result = None
2030
+
2031
+ if command_type == "load_file":
2032
+ result = self.window.load_file(params["file_path"])
2033
+ elif command_type == "load_url":
2034
+ result = self.window.load_url(params["url"])
2035
+ elif command_type == "load_html":
2036
+ html_content = params.get("html_content", "")
2037
+ base_url = params.get("base_url", "")
2038
+ result = self.window.load_html(html_content, base_url)
2039
+ elif command_type == "set_title":
2040
+ result = self.window.set_title(params["title"])
2041
+ elif command_type == "set_size":
2042
+ result = self.window.set_size(params["width"], params["height"])
2043
+ elif command_type == "set_position":
2044
+ result = self.window.set_position(params["x"], params["y"])
2045
+ elif command_type == "set_position_by_anchor":
2046
+ result = self.window.set_position_by_anchor(params["anchor"])
2047
+ elif command_type == "set_frame":
2048
+ result = self.window.set_frame(params["frame"])
2049
+ elif command_type == "set_context_menu":
2050
+ result = self.window.set_context_menu(params["context_menu"])
2051
+ elif command_type == "set_dev_tools":
2052
+ result = self.window.set_dev_tools(params["enable"])
2053
+ elif command_type == "open_dev_tools":
2054
+ result = self.window.open_dev_tools()
2055
+ elif command_type == "hide":
2056
+ result = self.window.hide()
2057
+ elif command_type == "show":
2058
+ result = self.window.show()
2059
+ elif command_type == "focus":
2060
+ result = self.window.focus()
2061
+ elif command_type == "show_and_focus":
2062
+ result = self.window.show_and_focus()
2063
+ elif command_type == "close":
2064
+ result = self.window.close()
2065
+ elif command_type == "fullscreen":
2066
+ result = self.window.fullscreen()
2067
+ elif command_type == "toggle_fullscreen":
2068
+ result = self.window.toggle_fullscreen()
2069
+ elif command_type == "minimize":
2070
+ result = self.window.minimize()
2071
+ elif command_type == "maximize":
2072
+ result = self.window.maximize()
2073
+ elif command_type == "unmaximize":
2074
+ result = self.window.unmaximize()
2075
+ elif command_type == "toggle_maximize":
2076
+ result = self.window.toggle_maximize()
2077
+ elif command_type == "is_fullscreen":
2078
+ result = self.window.is_fullscreen()
2079
+ elif command_type == "is_maximized":
2080
+ result = self.window.is_maximized()
2081
+ elif command_type == "capture":
2082
+ result = self.window.capture(params["save_path"])
2083
+ elif command_type == "add_shortcut":
2084
+ result = self.window.add_shortcut(params["key_sequence"], params["callback"])
2085
+ elif command_type == "remove_shortcut":
2086
+ result = self.window.remove_shortcut(params["key_sequence"])
2087
+ elif command_type == "get_all_shortcuts":
2088
+ result = self.window.get_all_shortcuts()
2089
+ elif command_type == "emit":
2090
+ event_name = params["event_name"]
2091
+ data = params.get("data")
2092
+ result = self.window.invoke(event_name, data)
2093
+ elif command_type == "get_window_properties":
2094
+ result = self.window.get_window_properties()
2095
+ elif command_type == "get_id":
2096
+ result = self.window.get_id()
2097
+ elif command_type == "get_size":
2098
+ result = self.window.get_size()
2099
+ elif command_type == "get_position":
2100
+ result = self.window.get_position()
2101
+ elif command_type == "get_title":
2102
+ result = self.window.get_title()
2103
+ elif command_type == "get_url":
2104
+ result = self.window.get_url()
2105
+ elif command_type == "get_visible":
2106
+ result = self.window.get_visible()
2107
+ elif command_type == "get_frame":
2108
+ result = self.window.get_frame()
2109
+ elif command_type == "set_resizable":
2110
+ result = self.window.set_resizable(params["resizable"])
2111
+ elif command_type == "set_minimum_size":
2112
+ result = self.window.set_minimum_size(params["min_width"], params["min_height"])
2113
+ elif command_type == "set_maximum_size":
2114
+ result = self.window.set_maximum_size(params["max_width"], params["max_height"])
2115
+ elif command_type == "get_minimum_size":
2116
+ result = self.window.get_minimum_size()
2117
+ elif command_type == "get_maximum_size":
2118
+ result = self.window.get_maximum_size()
2119
+ elif command_type == "get_resizable":
2120
+ result = self.window.get_resizable()
2121
+ elif command_type == "set_static_image_splash_screen":
2122
+ result = self.window.set_static_image_splash_screen(
2123
+ params["image_path"],
2124
+ params.get("close_on_load", True),
2125
+ params.get("stay_on_top", True),
2126
+ params.get("clickable", True),
2127
+ params.get("position", "center")
2128
+ )
2129
+ elif command_type == "set_gif_splash_screen":
2130
+ result = self.window.set_gif_splash_screen(
2131
+ params["gif_path"],
2132
+ params.get("close_on_load", True),
2133
+ params.get("stay_on_top", True),
2134
+ params.get("clickable", True),
2135
+ params.get("position", "center")
2136
+ )
2137
+ elif command_type == "close_splash_screen":
2138
+ result = self.window.close_splash_screen()
2139
+ else:
2140
+ return None
2141
+
2142
+ self.result_signal.emit(command_id, result)
2143
+
2144
+ def execute_command(self, command_type: str, params: object, timeout: Optional[int] = None):
2145
+ command_id = str(uuid.uuid4())
2146
+
2147
+ result_data = [None]
2148
+ loop = QEventLoop()
2149
+
2150
+ if timeout:
2151
+ timer = QTimer()
2152
+ timer.setSingleShot(True)
2153
+ timer.timeout.connect(loop.quit)
2154
+ timer.start(timeout)
2155
+
2156
+ def on_result(received_id, result):
2157
+ if received_id == command_id:
2158
+ result_data[0] = result
2159
+ loop.quit()
2160
+
2161
+
2162
+ self.result_signal.connect(on_result, Qt.QueuedConnection)
2163
+
2164
+ self.command_signal.emit(command_id, command_type, params)
2165
+
2166
+ loop.exec()
2167
+
2168
+ self.result_signal.disconnect(on_result)
2169
+
2170
+ return result_data[0]
2171
+
2172
+ # -------------------------------------------------------------------
2173
+ # Execute_command wrapper functions
2174
+ # -------------------------------------------------------------------
2175
+ def load_file(self, file_path: str) -> None:
1875
2176
  """
1876
- Sets the attribute of the WebEngineView.
2177
+ Loads a local HTML file into the web view.
1877
2178
 
1878
2179
  Parameters
1879
2180
  ----------
1880
- attribute : QWebEngineSettings
1881
- Attribute to set
1882
- on : bool
1883
- True to enable the attribute, False to disable it
2181
+ file_path : str
2182
+ The path to the local HTML file to be loaded.
1884
2183
 
1885
2184
  Examples
1886
2185
  --------
1887
- ```python
1888
- window.set_web_engine_view_attribute(QWebEngineSettings.WebAttribute.ScreenCaptureEnabled, False)
1889
- ```
2186
+ >>> app = Pyloid(app_name="Pyloid-App")
2187
+ >>> window = app.create_window("pyloid-window")
2188
+ >>> window.load_file('/path/to/local/file.html')
2189
+ >>> window.show()
1890
2190
  """
1891
- settings = self.web_view.settings()
1892
- settings.setAttribute(attribute, on)
2191
+ return self.execute_command("load_file", {"file_path": file_path})
1893
2192
 
1894
- def is_web_engine_view_attribute(self, attribute: QWebEngineSettings) -> bool:
2193
+ def load_url(self, url: str) -> None:
1895
2194
  """
1896
- Returns the attribute of the WebEngineView.
2195
+ Sets the URL of the window.
1897
2196
 
1898
2197
  Parameters
1899
2198
  ----------
1900
- attribute : QWebEngineSettings
1901
- Attribute to get
2199
+ url : str
2200
+ The URL to be loaded in the web view.
1902
2201
 
1903
- Returns
1904
- -------
1905
- bool
1906
- True if the attribute is enabled, False otherwise
2202
+ Examples
2203
+ --------
2204
+ >>> app = Pyloid(app_name="Pyloid-App")
2205
+ >>> window = app.create_window("pyloid-window")
2206
+ >>> window.load_url('https://www.example.com')
2207
+ >>> window.show()
2208
+ """
2209
+ return self.execute_command("load_url", {"url": url})
2210
+
2211
+ def load_html(self, html_content: str, base_url: str = "") -> None:
2212
+ """
2213
+ Loads HTML content directly into the web view.
2214
+
2215
+ Parameters
2216
+ ----------
2217
+ html_content : str
2218
+ The HTML content to be loaded.
2219
+ base_url : str, optional
2220
+ The base URL to use for resolving relative URLs (default is "").
1907
2221
 
1908
2222
  Examples
1909
2223
  --------
1910
- ```python
1911
- window.is_web_engine_view_attribute(QWebEngineSettings.WebAttribute.ScreenCaptureEnabled)
1912
- ```
2224
+ >>> app = Pyloid(app_name="Pyloid-App")
2225
+ >>> window = app.create_window("pyloid-window")
2226
+ >>> html_content = "<html><body><h1>Hello, Pyloid!</h1></body></html>"
2227
+ >>> window.load_html(html_content)
2228
+ >>> window.show()
1913
2229
  """
1914
- settings = self.web_view.settings()
1915
- return settings.testAttribute(attribute)
2230
+ return self.execute_command("load_html", {"html_content": html_content, "base_url": base_url})
1916
2231
 
1917
- def set_permission_handler(self, feature: QWebEnginePage.Feature, handler):
2232
+ def set_title(self, title: str) -> None:
1918
2233
  """
1919
- Sets a handler for a specific permission.
2234
+ Sets the title of the window.
1920
2235
 
1921
2236
  Parameters
1922
2237
  ----------
1923
- feature : QWebEnginePage.Feature
1924
- The type of permission to set
1925
- handler : callable
1926
- The handler function to process the permission request
2238
+ title : str
2239
+ The title to be set for the window.
1927
2240
 
1928
2241
  Examples
1929
2242
  --------
1930
- ```python
1931
- def handle_camera(origin, feature):
1932
- window.web_view.page().setFeaturePermission(
1933
- origin,
1934
- feature,
1935
- QWebEnginePage.PermissionPolicy.PermissionGrantedByUser
1936
- )
2243
+ >>> app = Pyloid(app_name="Pyloid-App")
2244
+ >>> window = app.create_window("pyloid-window")
2245
+ >>> window.set_title('My Window Title')
2246
+ """
2247
+ return self.execute_command("set_title", {"title": title})
1937
2248
 
1938
- window.set_permission_handler(
1939
- QWebEnginePage.Feature.MediaVideoCapture,
1940
- handle_camera
1941
- )
1942
- ```
2249
+ def set_size(self, width: int, height: int) -> None:
2250
+ """
2251
+ Sets the size of the window.
2252
+
2253
+ Parameters
2254
+ ----------
2255
+ width : int
2256
+ The width of the window.
2257
+ height : int
2258
+ The height of the window.
2259
+
2260
+ Examples
2261
+ --------
2262
+ >>> app = Pyloid(app_name="Pyloid-App")
2263
+ >>> window = app.create_window("pyloid-window")
2264
+ >>> window.set_size(800, 600)
1943
2265
  """
1944
- self.web_view.custom_page.setPermissionHandler(feature, handler)
2266
+ return self.execute_command("set_size", {"width": width, "height": height})
1945
2267
 
1946
- def grant_permission(self, feature: QWebEnginePage.Feature):
2268
+ def set_position(self, x: int, y: int) -> None:
1947
2269
  """
1948
- Automatically grants a specific permission when a request is made.
2270
+ Sets the position of the window.
1949
2271
 
1950
2272
  Parameters
1951
2273
  ----------
1952
- feature : QWebEnginePage.Feature
1953
- The type of permission to automatically grant
2274
+ x : int
2275
+ The x-coordinate of the window's position.
2276
+ y : int
2277
+ The y-coordinate of the window's position.
1954
2278
 
1955
2279
  Examples
1956
2280
  --------
1957
- ```python
1958
- window.grant_permission(QWebEnginePage.Feature.MediaVideoCapture)
1959
- ```
2281
+ >>> app = Pyloid(app_name="Pyloid-App")
2282
+ >>> window = app.create_window("pyloid-window")
2283
+ >>> window.set_position(100, 100)
1960
2284
  """
2285
+ return self.execute_command("set_position", {"x": x, "y": y})
1961
2286
 
1962
- def auto_grant(origin, feat):
1963
- self.web_view.page().setFeaturePermission(
1964
- origin, feat, QWebEnginePage.PermissionPolicy.PermissionGrantedByUser
1965
- )
2287
+ def set_position_by_anchor(self, anchor: str) -> None:
2288
+ """
2289
+ Positions the window at a specific location on the screen.
2290
+
2291
+ Parameters
2292
+ ----------
2293
+ anchor : str
2294
+ The anchor point indicating where to position the window.
2295
+ Possible values: 'center', 'top', 'bottom', 'left', 'right',
2296
+ 'top-left', 'top-right', 'bottom-left', 'bottom-right'
1966
2297
 
1967
- self.set_permission_handler(feature, auto_grant)
2298
+ Examples
2299
+ --------
2300
+ >>> window.set_position_by_anchor('center')
2301
+ >>> window.set_position_by_anchor('top-right')
2302
+ """
2303
+ return self.execute_command("set_position_by_anchor", {"anchor": anchor})
1968
2304
 
1969
- def deny_permission(self, feature: QWebEnginePage.Feature):
2305
+ def set_frame(self, frame: bool) -> None:
1970
2306
  """
1971
- Automatically denies a specific permission when a request is made.
2307
+ Sets the frame of the window.
1972
2308
 
1973
2309
  Parameters
1974
2310
  ----------
1975
- feature : QWebEnginePage.Feature
1976
- The type of permission to automatically deny
2311
+ frame : bool
2312
+ If True, the window will have a frame. If False, the window will be frameless.
1977
2313
 
1978
2314
  Examples
1979
2315
  --------
1980
- ```python
1981
- window.deny_permission(QWebEnginePage.Feature.Notifications)
1982
- ```
2316
+ >>> app = Pyloid(app_name="Pyloid-App")
2317
+ >>> window = app.create_window("pyloid-window")
2318
+ >>> window.set_frame(True)
2319
+ >>> window.set_frame(False)
1983
2320
  """
2321
+ return self.execute_command("set_frame", {"frame": frame})
1984
2322
 
1985
- def auto_deny(origin, feat):
1986
- self.web_view.page().setFeaturePermission(
1987
- origin, feat, QWebEnginePage.PermissionPolicy.PermissionDeniedByUser
1988
- )
2323
+ def set_context_menu(self, context_menu: bool) -> None:
2324
+ """
2325
+ Sets the context menu of the window.
2326
+
2327
+ Parameters
2328
+ ----------
2329
+ context_menu : bool
2330
+ If True, the context menu will be disabled. If False, the default context menu will be enabled.
1989
2331
 
1990
- self.set_permission_handler(feature, auto_deny)
2332
+ Examples
2333
+ --------
2334
+ >>> app = Pyloid(app_name="Pyloid-App")
2335
+ >>> window = app.create_window("pyloid-window")
2336
+ >>> window.set_context_menu(True)
2337
+ >>> window.set_context_menu(False)
2338
+ """
2339
+ return self.execute_command("set_context_menu", {"context_menu": context_menu})
1991
2340
 
1992
- def set_desktop_media_handler(self, handler):
2341
+ def set_dev_tools(self, enable: bool) -> None:
1993
2342
  """
1994
- 데스크톱 미디어(화면/윈도우) 선택 핸들러를 설정합니다.
2343
+ Sets the developer tools of the window.
2344
+
2345
+ If enabled, the developer tools can be opened using the F12 key.
1995
2346
 
1996
2347
  Parameters
1997
2348
  ----------
1998
- handler : callable
1999
- 요청을 처리할 핸들러 함수. QWebEngineDesktopMediaRequest 인자로 받습니다.
2349
+ enable : bool
2350
+ If True, the developer tools will be enabled. If False, the developer tools will be disabled.
2000
2351
 
2001
2352
  Examples
2002
2353
  --------
2003
- ```python
2004
- def custom_media_handler(request):
2005
- # 사용 가능한 화면 목록 출력
2006
- for screen in request.screenList():
2007
- print(f"Screen: {screen.name}")
2354
+ >>> app = Pyloid(app_name="Pyloid-App")
2355
+ >>> window = app.create_window("pyloid-window")
2356
+ >>> window.set_dev_tools(True)
2357
+ >>> window.set_dev_tools(False)
2358
+ """
2359
+ return self.execute_command("set_dev_tools", {"enable": enable})
2360
+
2361
+ def open_dev_tools(self) -> None:
2362
+ """
2363
+ Opens the developer tools window.
2008
2364
 
2009
- # 사용 가능한 윈도우 목록 출력
2010
- for window in request.windowList():
2011
- print(f"Window: {window.name}")
2365
+ Examples
2366
+ --------
2367
+ >>> app = Pyloid(app_name="Pyloid-App")
2368
+ >>> window = app.create_window("pyloid-window")
2369
+ >>> window.open_dev_tools()
2370
+ """
2371
+ return self.execute_command("open_dev_tools", {})
2012
2372
 
2013
- # 번째 화면 선택
2014
- if request.screenList():
2015
- request.selectScreen(request.screenList()[0])
2373
+ def hide(self) -> None:
2374
+ """
2375
+ Hides the window.
2016
2376
 
2017
- window.set_desktop_media_handler(custom_media_handler)
2018
- ```
2377
+ Examples
2378
+ --------
2379
+ >>> app = Pyloid(app_name="Pyloid-App")
2380
+ >>> window = app.create_window("pyloid-window")
2381
+ >>> window.hide()
2382
+ """
2383
+ return self.execute_command("hide", {})
2384
+
2385
+ def show(self) -> None:
2386
+ """
2387
+ Shows the window.
2388
+
2389
+ Examples
2390
+ --------
2391
+ >>> app = Pyloid(app_name="Pyloid-App")
2392
+ >>> window = app.create_window("pyloid-window")
2393
+ >>> window.show()
2394
+ """
2395
+ return self.execute_command("show", {})
2396
+
2397
+ def focus(self) -> None:
2398
+ """
2399
+ Focuses the window.
2400
+
2401
+ Examples
2402
+ --------
2403
+ >>> app = Pyloid(app_name="Pyloid-App")
2404
+ >>> window = app.create_window("pyloid-window")
2405
+ >>> window.focus()
2406
+ """
2407
+ return self.execute_command("focus", {})
2408
+
2409
+ def show_and_focus(self) -> None:
2410
+ """
2411
+ Shows and focuses the window.
2412
+
2413
+ Examples
2414
+ --------
2415
+ >>> app = Pyloid(app_name="Pyloid-App")
2416
+ >>> window = app.create_window("pyloid-window")
2417
+ >>> window.show_and_focus()
2418
+ """
2419
+ return self.execute_command("show_and_focus", {})
2420
+
2421
+ def close(self) -> None:
2422
+ """
2423
+ Closes the window.
2424
+
2425
+ Examples
2426
+ --------
2427
+ >>> app = Pyloid(app_name="Pyloid-App")
2428
+ >>> window = app.create_window("pyloid-window")
2429
+ >>> window.close()
2430
+ """
2431
+ return self.execute_command("close", {})
2432
+
2433
+ def fullscreen(self) -> None:
2434
+ """
2435
+ Enters fullscreen mode.
2436
+
2437
+ Examples
2438
+ --------
2439
+ >>> app = Pyloid(app_name="Pyloid-App")
2440
+ >>> window = app.create_window("pyloid-window")
2441
+ >>> window.fullscreen()
2442
+ """
2443
+ return self.execute_command("fullscreen", {})
2444
+
2445
+ def toggle_fullscreen(self) -> None:
2446
+ """
2447
+ Toggles the fullscreen mode of the window.
2448
+
2449
+ Examples
2450
+ --------
2451
+ >>> app = Pyloid(app_name="Pyloid-App")
2452
+ >>> window = app.create_window("pyloid-window")
2453
+ >>> window.toggle_fullscreen()
2454
+ """
2455
+ return self.execute_command("toggle_fullscreen", {})
2456
+
2457
+ def minimize(self) -> None:
2458
+ """
2459
+ Minimizes the window.
2460
+
2461
+ Examples
2462
+ --------
2463
+ >>> app = Pyloid(app_name="Pyloid-App")
2464
+ >>> window = app.create_window("pyloid-window")
2465
+ >>> window.minimize()
2466
+ """
2467
+ return self.execute_command("minimize", {})
2468
+
2469
+ def maximize(self) -> None:
2470
+ """
2471
+ Maximizes the window.
2472
+
2473
+ Examples
2474
+ --------
2475
+ >>> app = Pyloid(app_name="Pyloid-App")
2476
+ >>> window = app.create_window("pyloid-window")
2477
+ >>> window.maximize()
2478
+ """
2479
+ return self.execute_command("maximize", {})
2480
+
2481
+ def unmaximize(self) -> None:
2482
+ """
2483
+ Restores the window from maximized state.
2484
+
2485
+ Examples
2486
+ --------
2487
+ >>> app = Pyloid(app_name="Pyloid-App")
2488
+ >>> window = app.create_window("pyloid-window")
2489
+ >>> window.unmaximize()
2490
+ """
2491
+ return self.execute_command("unmaximize", {})
2492
+
2493
+ def toggle_maximize(self) -> None:
2494
+ """
2495
+ Toggles the maximized state of the window.
2496
+
2497
+ Examples
2498
+ --------
2499
+ >>> app = Pyloid(app_name="Pyloid-App")
2500
+ >>> window = app.create_window("pyloid-window")
2501
+ >>> window.toggle_maximize()
2502
+ """
2503
+ return self.execute_command("toggle_maximize", {})
2504
+
2505
+ def is_fullscreen(self) -> bool:
2506
+ """
2507
+ Returns True if the window is fullscreen.
2508
+
2509
+ Examples
2510
+ --------
2511
+ >>> app = Pyloid(app_name="Pyloid-App")
2512
+ >>> window = app.create_window("pyloid-window")
2513
+ >>> window.is_fullscreen()
2514
+ """
2515
+ return self.execute_command("is_fullscreen", {})
2516
+
2517
+ def is_maximized(self) -> bool:
2518
+ """
2519
+ Returns True if the window is maximized.
2520
+
2521
+ Examples
2522
+ --------
2523
+ >>> app = Pyloid(app_name="Pyloid-App")
2524
+ >>> window = app.create_window("pyloid-window")
2525
+ >>> window.is_maximized()
2526
+ """
2527
+ return self.execute_command("is_maximized", {})
2528
+
2529
+ def capture(self, save_path: str) -> "Optional[str]":
2530
+ """
2531
+ Captures the current window.
2532
+
2533
+ Parameters
2534
+ ----------
2535
+ save_path : str
2536
+ Path to save the captured image. If not specified, it will be saved in the current directory.
2537
+
2538
+ Returns
2539
+ -------
2540
+ Optional[str]
2541
+ Returns the path of the saved image.
2542
+
2543
+ Examples
2544
+ --------
2545
+ >>> app = Pyloid(app_name="Pyloid-App")
2546
+ >>> window = app.create_window("pyloid-window")
2547
+ >>> save_path = window.capture("screenshot.png")
2548
+ >>> print(f"Image saved at: {save_path}")
2549
+ """
2550
+ return self.execute_command("capture", {"save_path": save_path})
2551
+
2552
+ def add_shortcut(self, key_sequence: str, callback: Callable) -> Any:
2553
+ """
2554
+ Adds a keyboard shortcut to the window if it does not already exist.
2555
+
2556
+ Parameters
2557
+ ----------
2558
+ key_sequence : str
2559
+ Shortcut sequence (e.g., "Ctrl+C")
2560
+ callback : Callable
2561
+ Function to be executed when the shortcut is pressed
2562
+
2563
+ Returns
2564
+ -------
2565
+ QShortcut or None
2566
+ Created QShortcut object or None if the shortcut already exists
2567
+
2568
+ Examples
2569
+ --------
2570
+ >>> app = Pyloid(app_name="Pyloid-App")
2571
+ >>> window = app.create_window("pyloid-window")
2572
+ >>> def on_shortcut():
2573
+ ... print("Shortcut activated!")
2574
+ >>> window.add_shortcut("Ctrl+C", on_shortcut)
2575
+ >>> app.run()
2576
+ """
2577
+ return self.execute_command("add_shortcut", {"key_sequence": key_sequence, "callback": callback})
2578
+
2579
+ def remove_shortcut(self, key_sequence: str) -> None:
2580
+ """
2581
+ Removes a keyboard shortcut from the window.
2582
+
2583
+ Parameters
2584
+ ----------
2585
+ key_sequence : str
2586
+ Shortcut sequence to be removed
2587
+
2588
+ Examples
2589
+ --------
2590
+ >>> app = Pyloid(app_name="Pyloid-App")
2591
+ >>> window = app.create_window("pyloid-window")
2592
+ >>> window.remove_shortcut("Ctrl+C")
2593
+ >>> app.run()
2594
+ """
2595
+ return self.execute_command("remove_shortcut", {"key_sequence": key_sequence})
2596
+
2597
+ def get_all_shortcuts(self) -> dict:
2598
+ """
2599
+ Returns all registered shortcuts in the window.
2600
+
2601
+ Returns
2602
+ -------
2603
+ dict
2604
+ Dictionary of shortcut sequences and QShortcut objects
2605
+
2606
+ Examples
2607
+ --------
2608
+ >>> app = Pyloid(app_name="Pyloid-App")
2609
+ >>> window = app.create_window("pyloid-window")
2610
+ >>> shortcuts = window.get_all_shortcuts()
2611
+ >>> print(shortcuts)
2612
+ >>> app.run()
2613
+ """
2614
+ return self.execute_command("get_all_shortcuts", {})
2615
+
2616
+ def invoke(self, event_name: str, data: "Optional[Dict]" = None) -> None:
2617
+ """
2618
+ Invokes an event to the JavaScript side.
2619
+
2620
+ Parameters
2621
+ ----------
2622
+ event_name : str
2623
+ Name of the event
2624
+ data : dict, optional
2625
+ Data to be sent with the event (default is None)
2626
+
2627
+ Examples
2628
+ --------
2629
+ (Python)
2630
+ >>> app = Pyloid(app_name="Pyloid-App")
2631
+ >>> window = app.create_window("pyloid-window")
2632
+ >>> window.invoke("customEvent", {"message": "Hello, Pyloid!"})
2633
+
2634
+ (JavaScript)
2635
+ >>> document.addEventListener('customEvent', (data) => {
2636
+ ... console.log(data.message);
2637
+ ... });
2638
+ """
2639
+ return self.execute_command("invoke", {"event_name": event_name, "data": data})
2640
+
2641
+ def get_window_properties(self) -> dict:
2642
+ """
2643
+ Returns the properties of the window.
2644
+
2645
+ Returns
2646
+ -------
2647
+ dict
2648
+ Dictionary containing the properties of the window
2649
+
2650
+ Examples
2651
+ --------
2652
+ >>> app = Pyloid(app_name="Pyloid-App")
2653
+ >>> window = app.create_window("pyloid-window")
2654
+ >>> properties = window.get_window_properties()
2655
+ >>> print(properties)
2656
+ >>> app.run()
2657
+ """
2658
+ return self.execute_command("get_window_properties", {})
2659
+
2660
+ def get_id(self) -> str:
2661
+ """
2662
+ Returns the ID of the window.
2663
+
2664
+ Returns
2665
+ -------
2666
+ str
2667
+ ID of the window
2668
+
2669
+ Examples
2670
+ --------
2671
+ >>> app = Pyloid(app_name="Pyloid-App")
2672
+ >>> window = app.create_window("pyloid-window")
2673
+ >>> window_id = window.get_id()
2674
+ >>> print(window_id)
2675
+ >>> app.run()
2676
+ """
2677
+ return self.execute_command("get_id", {})
2678
+
2679
+ def get_size(self) -> "Dict[str, int]":
2680
+ """
2681
+ Returns the size of the window.
2682
+
2683
+ Returns
2684
+ -------
2685
+ dict
2686
+ Dictionary containing the width and height of the window
2687
+
2688
+ Examples
2689
+ --------
2690
+ >>> app = Pyloid(app_name="Pyloid-App")
2691
+ >>> window = app.create_window("pyloid-window")
2692
+ >>> size = window.get_size()
2693
+ >>> print(size)
2694
+ >>> app.run()
2695
+ """
2696
+ return self.execute_command("get_size", {})
2697
+
2698
+ def get_position(self) -> "Dict[str, int]":
2699
+ """
2700
+ Returns the position of the window.
2701
+
2702
+ Returns
2703
+ -------
2704
+ dict
2705
+ Dictionary containing the x and y coordinates of the window
2706
+
2707
+ Examples
2708
+ --------
2709
+ >>> app = Pyloid(app_name="Pyloid-App")
2710
+ >>> window = app.create_window("pyloid-window")
2711
+ >>> position = window.get_position()
2712
+ >>> print(position)
2713
+ >>> app.run()
2714
+ """
2715
+ return self.execute_command("get_position", {})
2716
+
2717
+ def get_title(self) -> str:
2718
+ """
2719
+ Returns the title of the window.
2720
+
2721
+ Returns
2722
+ -------
2723
+ str
2724
+ Title of the window
2725
+
2726
+ Examples
2727
+ --------
2728
+ >>> app = Pyloid(app_name="Pyloid-App")
2729
+ >>> window = app.create_window("pyloid-window")
2730
+ >>> title = window.get_title()
2731
+ >>> print(title)
2732
+ >>> app.run()
2733
+ """
2734
+ return self.execute_command("get_title", {})
2735
+
2736
+ def get_url(self) -> str:
2737
+ """
2738
+ Returns the URL of the window.
2739
+
2740
+ Returns
2741
+ -------
2742
+ str
2743
+ URL of the window
2744
+
2745
+ Examples
2746
+ --------
2747
+ >>> app = Pyloid(app_name="Pyloid-App")
2748
+ >>> window = app.create_window("pyloid-window")
2749
+ >>> url = window.get_url()
2750
+ >>> print(url)
2751
+ >>> app.run()
2752
+ """
2753
+ return self.execute_command("get_url", {})
2754
+
2755
+ def get_visible(self) -> bool:
2756
+ """
2757
+ Returns the visibility of the window.
2758
+
2759
+ Returns
2760
+ -------
2761
+ bool
2762
+ True if the window is visible, False otherwise
2763
+
2764
+ Examples
2765
+ --------
2766
+ >>> app = Pyloid(app_name="Pyloid-App")
2767
+ >>> window = app.create_window("pyloid-window")
2768
+ >>> visible = window.get_visible()
2769
+ >>> print(visible)
2770
+ >>> app.run()
2771
+ """
2772
+ return self.execute_command("get_visible", {})
2773
+
2774
+ def get_frame(self) -> bool:
2775
+ """
2776
+ Returns the frame enabled state of the window.
2777
+
2778
+ Returns
2779
+ -------
2780
+ bool
2781
+ True if the frame is enabled, False otherwise
2782
+
2783
+ Examples
2784
+ --------
2785
+ >>> app = Pyloid(app_name="Pyloid-App")
2786
+ >>> window = app.create_window("pyloid-window")
2787
+ >>> frame = window.get_frame()
2788
+ >>> print(frame)
2789
+ >>> app.run()
2790
+ """
2791
+ return self.execute_command("get_frame", {})
2792
+
2793
+ def set_resizable(self, resizable: bool) -> None:
2794
+ """
2795
+ Sets the resizability of the window.
2796
+
2797
+ Parameters
2798
+ ----------
2799
+ resizable : bool
2800
+ True to make the window resizable, False to make it fixed size
2801
+
2802
+ Examples
2803
+ --------
2804
+ >>> app = Pyloid(app_name="Pyloid-App")
2805
+ >>> window = app.create_window("pyloid-window")
2806
+ >>> window.set_resizable(True)
2807
+ >>> app.run()
2808
+ """
2809
+ return self.execute_command("set_resizable", {"resizable": resizable})
2810
+
2811
+ def set_minimum_size(self, min_width: int, min_height: int) -> None:
2812
+ """
2813
+ Sets the minimum size of the window.
2814
+
2815
+ Parameters
2816
+ ----------
2817
+ min_width : int
2818
+ Minimum width of the window
2819
+ min_height : int
2820
+ Minimum height of the window
2821
+
2822
+ Examples
2823
+ --------
2824
+ >>> app = Pyloid(app_name="Pyloid-App")
2825
+ >>> window = app.create_window("pyloid-window")
2826
+ >>> window.set_minimum_size(400, 300)
2827
+ >>> app.run()
2828
+ """
2829
+ return self.execute_command("set_minimum_size", {"min_width": min_width, "min_height": min_height})
2830
+
2831
+ def set_maximum_size(self, max_width: int, max_height: int) -> None:
2832
+ """
2833
+ Sets the maximum size of the window.
2834
+
2835
+ Parameters
2836
+ ----------
2837
+ max_width : int
2838
+ Maximum width of the window
2839
+ max_height : int
2840
+ Maximum height of the window
2841
+
2842
+ Examples
2843
+ --------
2844
+ >>> app = Pyloid(app_name="Pyloid-App")
2845
+ >>> window = app.create_window("pyloid-window")
2846
+ >>> window.set_maximum_size(1024, 768)
2847
+ >>> app.run()
2848
+ """
2849
+ return self.execute_command("set_maximum_size", {"max_width": max_width, "max_height": max_height})
2850
+
2851
+ def get_minimum_size(self) -> "Dict[str, int]":
2852
+ """
2853
+ Returns the minimum size of the window.
2854
+
2855
+ Returns
2856
+ -------
2857
+ dict
2858
+ Dictionary containing the minimum width and height of the window
2859
+
2860
+ Examples
2861
+ --------
2862
+ >>> app = Pyloid(app_name="Pyloid-App")
2863
+ >>> window = app.create_window("pyloid-window")
2864
+ >>> min_size = window.get_minimum_size()
2865
+ >>> print(min_size)
2866
+ >>> app.run()
2867
+ """
2868
+ return self.execute_command("get_minimum_size", {})
2869
+
2870
+ def get_maximum_size(self) -> "Dict[str, int]":
2871
+ """
2872
+ Returns the maximum size of the window.
2873
+
2874
+ Returns
2875
+ -------
2876
+ dict
2877
+ Dictionary containing the maximum width and height of the window
2878
+
2879
+ Examples
2880
+ --------
2881
+ >>> app = Pyloid(app_name="Pyloid-App")
2882
+ >>> window = app.create_window("pyloid-window")
2883
+ >>> max_size = window.get_maximum_size()
2884
+ >>> print(max_size)
2885
+ >>> app.run()
2886
+ """
2887
+ return self.execute_command("get_maximum_size", {})
2888
+
2889
+ def get_resizable(self) -> bool:
2890
+ """
2891
+ Returns the resizability of the window.
2892
+
2893
+ Returns
2894
+ -------
2895
+ bool
2896
+ True if the window is resizable, False otherwise
2897
+
2898
+ Examples
2899
+ --------
2900
+ >>> app = Pyloid(app_name="Pyloid-App")
2901
+ >>> window = app.create_window("pyloid-window")
2902
+ >>> resizable = window.get_resizable()
2903
+ >>> print(resizable)
2904
+ >>> app.run()
2905
+ """
2906
+ return self.execute_command("get_resizable", {})
2907
+
2908
+ def set_static_image_splash_screen(self, image_path: str, close_on_load: bool = True, stay_on_top: bool = True, clickable: bool = True, position: str = "center") -> None:
2909
+ """
2910
+ Sets the static image splash screen of the window.
2911
+
2912
+ Parameters
2913
+ ----------
2914
+ image_path : str
2915
+ Path to the image file
2916
+ close_on_load : bool, optional
2917
+ True to close the splash screen when the page is loaded, False otherwise (default is True)
2918
+ stay_on_top : bool, optional
2919
+ True to keep the splash screen on top, False otherwise (default is True)
2920
+ clickable : bool, optional
2921
+ True to make the splash screen clickable, False otherwise (default is True)
2922
+ if clickable is True, you can click the splash screen to close it.
2923
+ position : str, optional
2924
+ Position of the splash screen. Options are 'center', 'top-left', 'top-right', 'bottom-left', 'bottom-right' (default is 'center')
2925
+
2926
+ Examples
2927
+ --------
2928
+ >>> window.set_static_image_splash_screen("./assets/loading.png", close_on_load=True, stay_on_top=True)
2929
+ """
2930
+ return self.execute_command("set_static_image_splash_screen", {
2931
+ "image_path": image_path,
2932
+ "close_on_load": close_on_load,
2933
+ "stay_on_top": stay_on_top,
2934
+ "clickable": clickable,
2935
+ "position": position
2936
+ })
2937
+
2938
+ def set_gif_splash_screen(self, gif_path: str, close_on_load: bool = True, stay_on_top: bool = True, clickable: bool = True, position: str = "center") -> None:
2939
+ """
2940
+ Sets the gif splash screen of the window.
2941
+
2942
+ Parameters
2943
+ ----------
2944
+ gif_path : str
2945
+ Path to the gif file
2946
+ close_on_load : bool, optional
2947
+ True to close the splash screen when the page is loaded, False otherwise (default is True)
2948
+ stay_on_top : bool, optional
2949
+ True to keep the splash screen on top, False otherwise (default is True)
2950
+ clickable : bool, optional
2951
+ True to make the splash screen clickable, False otherwise (default is True)
2952
+ if clickable is True, you can click the splash screen to close it.
2953
+ position : str, optional
2954
+ Position of the splash screen. Options are 'center', 'top-left', 'top-right', 'bottom-left', 'bottom-right' (default is 'center')
2955
+
2956
+ Examples
2957
+ --------
2958
+ >>> window.set_gif_splash_screen("./assets/loading.gif", close_on_load=True, stay_on_top=True)
2959
+ """
2960
+ return self.execute_command("set_gif_splash_screen", {
2961
+ "gif_path": gif_path,
2962
+ "close_on_load": close_on_load,
2963
+ "stay_on_top": stay_on_top,
2964
+ "clickable": clickable,
2965
+ "position": position
2966
+ })
2967
+
2968
+ def close_splash_screen(self) -> None:
2969
+ """
2970
+ Closes the splash screen if it exists.
2971
+
2972
+ Examples
2973
+ --------
2974
+ >>> window.close_splash_screen()
2019
2975
  """
2020
- self.web_view.custom_page.setDesktopMediaHandler(handler)
2976
+ return self.execute_command("close_splash_screen", {})
2977
+