pyloid 0.22.0.dev1__tar.gz → 0.22.0.dev2__tar.gz
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-0.22.0.dev1 → pyloid-0.22.0.dev2}/PKG-INFO +1 -1
- {pyloid-0.22.0.dev1 → pyloid-0.22.0.dev2}/pyproject.toml +1 -1
- {pyloid-0.22.0.dev1 → pyloid-0.22.0.dev2}/src/pyloid/__init__.py +2 -1
- {pyloid-0.22.0.dev1 → pyloid-0.22.0.dev2}/src/pyloid/browser_window.py +48 -48
- pyloid-0.22.0.dev2/src/pyloid/js_api/base.py +29 -0
- {pyloid-0.22.0.dev1 → pyloid-0.22.0.dev2}/src/pyloid/pyloid.py +1 -160
- pyloid-0.22.0.dev2/src/pyloid/serve.py +56 -0
- {pyloid-0.22.0.dev1 → pyloid-0.22.0.dev2}/src/pyloid/utils.py +31 -0
- pyloid-0.22.0.dev1/src/pyloid/js_api/base.py +0 -13
- {pyloid-0.22.0.dev1 → pyloid-0.22.0.dev2}/LICENSE +0 -0
- {pyloid-0.22.0.dev1 → pyloid-0.22.0.dev2}/README.md +0 -0
- {pyloid-0.22.0.dev1 → pyloid-0.22.0.dev2}/src/pyloid/api.py +0 -0
- {pyloid-0.22.0.dev1 → pyloid-0.22.0.dev2}/src/pyloid/autostart.py +0 -0
- {pyloid-0.22.0.dev1 → pyloid-0.22.0.dev2}/src/pyloid/custom/titlebar.py +0 -0
- {pyloid-0.22.0.dev1 → pyloid-0.22.0.dev2}/src/pyloid/filewatcher.py +0 -0
- {pyloid-0.22.0.dev1 → pyloid-0.22.0.dev2}/src/pyloid/js_api/event_api.py +0 -0
- {pyloid-0.22.0.dev1 → pyloid-0.22.0.dev2}/src/pyloid/js_api/window_api.py +0 -0
- {pyloid-0.22.0.dev1 → pyloid-0.22.0.dev2}/src/pyloid/monitor.py +0 -0
- {pyloid-0.22.0.dev1 → pyloid-0.22.0.dev2}/src/pyloid/thread_pool.py +0 -0
- {pyloid-0.22.0.dev1 → pyloid-0.22.0.dev2}/src/pyloid/timer.py +0 -0
- {pyloid-0.22.0.dev1 → pyloid-0.22.0.dev2}/src/pyloid/tray.py +0 -0
@@ -3,5 +3,6 @@ from .api import PyloidAPI, Bridge
|
|
3
3
|
from .utils import get_production_path, is_production
|
4
4
|
from .tray import TrayEvent
|
5
5
|
from .timer import PyloidTimer
|
6
|
+
from .serve import pyloid_serve
|
6
7
|
|
7
|
-
__all__ = ['Pyloid', 'PyloidAPI', 'Bridge', 'get_production_path', 'is_production', 'TrayEvent', 'PyloidTimer']
|
8
|
+
__all__ = ['Pyloid', 'PyloidAPI', 'Bridge', 'get_production_path', 'is_production', 'TrayEvent', 'PyloidTimer', 'serve']
|
@@ -533,7 +533,7 @@ class _BrowserWindow:
|
|
533
533
|
|
534
534
|
document.addEventListener('mousedown', function (e) {
|
535
535
|
if (e.target.hasAttribute('data-pyloid-drag-region')) {
|
536
|
-
window.pyloid.
|
536
|
+
window.pyloid.BaseAPI.startSystemDrag();
|
537
537
|
}
|
538
538
|
});
|
539
539
|
|
@@ -2013,7 +2013,7 @@ class BrowserWindow(QObject):
|
|
2013
2013
|
|
2014
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
2015
|
super().__init__()
|
2016
|
-
self.
|
2016
|
+
self._window = _BrowserWindow(app, title, width, height, x, y, frame, context_menu, dev_tools, js_apis)
|
2017
2017
|
self.command_signal.connect(self._handle_command)
|
2018
2018
|
|
2019
2019
|
@Slot(str, str, object)
|
@@ -2029,97 +2029,97 @@ class BrowserWindow(QObject):
|
|
2029
2029
|
result = None
|
2030
2030
|
|
2031
2031
|
if command_type == "load_file":
|
2032
|
-
result = self.
|
2032
|
+
result = self._window.load_file(params["file_path"])
|
2033
2033
|
elif command_type == "load_url":
|
2034
|
-
result = self.
|
2034
|
+
result = self._window.load_url(params["url"])
|
2035
2035
|
elif command_type == "load_html":
|
2036
2036
|
html_content = params.get("html_content", "")
|
2037
2037
|
base_url = params.get("base_url", "")
|
2038
|
-
result = self.
|
2038
|
+
result = self._window.load_html(html_content, base_url)
|
2039
2039
|
elif command_type == "set_title":
|
2040
|
-
result = self.
|
2040
|
+
result = self._window.set_title(params["title"])
|
2041
2041
|
elif command_type == "set_size":
|
2042
|
-
result = self.
|
2042
|
+
result = self._window.set_size(params["width"], params["height"])
|
2043
2043
|
elif command_type == "set_position":
|
2044
|
-
result = self.
|
2044
|
+
result = self._window.set_position(params["x"], params["y"])
|
2045
2045
|
elif command_type == "set_position_by_anchor":
|
2046
|
-
result = self.
|
2046
|
+
result = self._window.set_position_by_anchor(params["anchor"])
|
2047
2047
|
elif command_type == "set_frame":
|
2048
|
-
result = self.
|
2048
|
+
result = self._window.set_frame(params["frame"])
|
2049
2049
|
elif command_type == "set_context_menu":
|
2050
|
-
result = self.
|
2050
|
+
result = self._window.set_context_menu(params["context_menu"])
|
2051
2051
|
elif command_type == "set_dev_tools":
|
2052
|
-
result = self.
|
2052
|
+
result = self._window.set_dev_tools(params["enable"])
|
2053
2053
|
elif command_type == "open_dev_tools":
|
2054
|
-
result = self.
|
2054
|
+
result = self._window.open_dev_tools()
|
2055
2055
|
elif command_type == "hide":
|
2056
|
-
result = self.
|
2056
|
+
result = self._window.hide()
|
2057
2057
|
elif command_type == "show":
|
2058
|
-
result = self.
|
2058
|
+
result = self._window.show()
|
2059
2059
|
elif command_type == "focus":
|
2060
|
-
result = self.
|
2060
|
+
result = self._window.focus()
|
2061
2061
|
elif command_type == "show_and_focus":
|
2062
|
-
result = self.
|
2062
|
+
result = self._window.show_and_focus()
|
2063
2063
|
elif command_type == "close":
|
2064
|
-
result = self.
|
2064
|
+
result = self._window.close()
|
2065
2065
|
elif command_type == "fullscreen":
|
2066
|
-
result = self.
|
2066
|
+
result = self._window.fullscreen()
|
2067
2067
|
elif command_type == "toggle_fullscreen":
|
2068
|
-
result = self.
|
2068
|
+
result = self._window.toggle_fullscreen()
|
2069
2069
|
elif command_type == "minimize":
|
2070
|
-
result = self.
|
2070
|
+
result = self._window.minimize()
|
2071
2071
|
elif command_type == "maximize":
|
2072
|
-
result = self.
|
2072
|
+
result = self._window.maximize()
|
2073
2073
|
elif command_type == "unmaximize":
|
2074
|
-
result = self.
|
2074
|
+
result = self._window.unmaximize()
|
2075
2075
|
elif command_type == "toggle_maximize":
|
2076
|
-
result = self.
|
2076
|
+
result = self._window.toggle_maximize()
|
2077
2077
|
elif command_type == "is_fullscreen":
|
2078
|
-
result = self.
|
2078
|
+
result = self._window.is_fullscreen()
|
2079
2079
|
elif command_type == "is_maximized":
|
2080
|
-
result = self.
|
2080
|
+
result = self._window.is_maximized()
|
2081
2081
|
elif command_type == "capture":
|
2082
|
-
result = self.
|
2082
|
+
result = self._window.capture(params["save_path"])
|
2083
2083
|
elif command_type == "add_shortcut":
|
2084
|
-
result = self.
|
2084
|
+
result = self._window.add_shortcut(params["key_sequence"], params["callback"])
|
2085
2085
|
elif command_type == "remove_shortcut":
|
2086
|
-
result = self.
|
2086
|
+
result = self._window.remove_shortcut(params["key_sequence"])
|
2087
2087
|
elif command_type == "get_all_shortcuts":
|
2088
|
-
result = self.
|
2088
|
+
result = self._window.get_all_shortcuts()
|
2089
2089
|
elif command_type == "emit":
|
2090
2090
|
event_name = params["event_name"]
|
2091
2091
|
data = params.get("data")
|
2092
|
-
result = self.
|
2092
|
+
result = self._window.invoke(event_name, data)
|
2093
2093
|
elif command_type == "get_window_properties":
|
2094
|
-
result = self.
|
2094
|
+
result = self._window.get_window_properties()
|
2095
2095
|
elif command_type == "get_id":
|
2096
|
-
result = self.
|
2096
|
+
result = self._window.get_id()
|
2097
2097
|
elif command_type == "get_size":
|
2098
|
-
result = self.
|
2098
|
+
result = self._window.get_size()
|
2099
2099
|
elif command_type == "get_position":
|
2100
|
-
result = self.
|
2100
|
+
result = self._window.get_position()
|
2101
2101
|
elif command_type == "get_title":
|
2102
|
-
result = self.
|
2102
|
+
result = self._window.get_title()
|
2103
2103
|
elif command_type == "get_url":
|
2104
|
-
result = self.
|
2104
|
+
result = self._window.get_url()
|
2105
2105
|
elif command_type == "get_visible":
|
2106
|
-
result = self.
|
2106
|
+
result = self._window.get_visible()
|
2107
2107
|
elif command_type == "get_frame":
|
2108
|
-
result = self.
|
2108
|
+
result = self._window.get_frame()
|
2109
2109
|
elif command_type == "set_resizable":
|
2110
|
-
result = self.
|
2110
|
+
result = self._window.set_resizable(params["resizable"])
|
2111
2111
|
elif command_type == "set_minimum_size":
|
2112
|
-
result = self.
|
2112
|
+
result = self._window.set_minimum_size(params["min_width"], params["min_height"])
|
2113
2113
|
elif command_type == "set_maximum_size":
|
2114
|
-
result = self.
|
2114
|
+
result = self._window.set_maximum_size(params["max_width"], params["max_height"])
|
2115
2115
|
elif command_type == "get_minimum_size":
|
2116
|
-
result = self.
|
2116
|
+
result = self._window.get_minimum_size()
|
2117
2117
|
elif command_type == "get_maximum_size":
|
2118
|
-
result = self.
|
2118
|
+
result = self._window.get_maximum_size()
|
2119
2119
|
elif command_type == "get_resizable":
|
2120
|
-
result = self.
|
2120
|
+
result = self._window.get_resizable()
|
2121
2121
|
elif command_type == "set_static_image_splash_screen":
|
2122
|
-
result = self.
|
2122
|
+
result = self._window.set_static_image_splash_screen(
|
2123
2123
|
params["image_path"],
|
2124
2124
|
params.get("close_on_load", True),
|
2125
2125
|
params.get("stay_on_top", True),
|
@@ -2127,7 +2127,7 @@ class BrowserWindow(QObject):
|
|
2127
2127
|
params.get("position", "center")
|
2128
2128
|
)
|
2129
2129
|
elif command_type == "set_gif_splash_screen":
|
2130
|
-
result = self.
|
2130
|
+
result = self._window.set_gif_splash_screen(
|
2131
2131
|
params["gif_path"],
|
2132
2132
|
params.get("close_on_load", True),
|
2133
2133
|
params.get("stay_on_top", True),
|
@@ -2135,7 +2135,7 @@ class BrowserWindow(QObject):
|
|
2135
2135
|
params.get("position", "center")
|
2136
2136
|
)
|
2137
2137
|
elif command_type == "close_splash_screen":
|
2138
|
-
result = self.
|
2138
|
+
result = self._window.close_splash_screen()
|
2139
2139
|
else:
|
2140
2140
|
return None
|
2141
2141
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
from ..api import PyloidAPI, Bridge
|
2
|
+
|
3
|
+
class BaseAPI(PyloidAPI):
|
4
|
+
def __init__(self, window_id: str, data: dict):
|
5
|
+
super().__init__()
|
6
|
+
self.window_id: str = window_id
|
7
|
+
self.data: dict = data
|
8
|
+
|
9
|
+
@Bridge(result=dict)
|
10
|
+
def getData(self):
|
11
|
+
"""Returns the shared data of the application."""
|
12
|
+
return self.data
|
13
|
+
|
14
|
+
@Bridge(result=str)
|
15
|
+
def getWindowId(self):
|
16
|
+
"""Returns the current window ID."""
|
17
|
+
return self.window_id
|
18
|
+
|
19
|
+
@Bridge()
|
20
|
+
def startSystemDrag(self):
|
21
|
+
"""Starts the system drag."""
|
22
|
+
window = self.app.get_window_by_id(self.window_id)
|
23
|
+
if window:
|
24
|
+
window._window.web_view.start_system_drag()
|
25
|
+
|
26
|
+
@Bridge()
|
27
|
+
def quit(self):
|
28
|
+
"""Quits the application."""
|
29
|
+
self.app.quit()
|
@@ -299,7 +299,7 @@ class _Pyloid(QApplication):
|
|
299
299
|
dev_tools,
|
300
300
|
js_apis,
|
301
301
|
)
|
302
|
-
self.windows_dict[window.
|
302
|
+
self.windows_dict[window._window.id] = window
|
303
303
|
return window
|
304
304
|
|
305
305
|
def run(self):
|
@@ -1486,30 +1486,6 @@ class Pyloid(QObject):
|
|
1486
1486
|
elif command_type == "get_window_by_id":
|
1487
1487
|
result = self.app.get_window_by_id(params["window_id"])
|
1488
1488
|
|
1489
|
-
elif command_type == "hide_window_by_id":
|
1490
|
-
result = self.app.hide_window_by_id(params["window_id"])
|
1491
|
-
|
1492
|
-
elif command_type == "show_window_by_id":
|
1493
|
-
result = self.app.show_window_by_id(params["window_id"])
|
1494
|
-
|
1495
|
-
elif command_type == "close_window_by_id":
|
1496
|
-
result = self.app.close_window_by_id(params["window_id"])
|
1497
|
-
|
1498
|
-
elif command_type == "toggle_fullscreen_by_id":
|
1499
|
-
result = self.app.toggle_fullscreen_by_id(params["window_id"])
|
1500
|
-
|
1501
|
-
elif command_type == "minimize_window_by_id":
|
1502
|
-
result = self.app.minimize_window_by_id(params["window_id"])
|
1503
|
-
|
1504
|
-
elif command_type == "maximize_window_by_id":
|
1505
|
-
result = self.app.maximize_window_by_id(params["window_id"])
|
1506
|
-
|
1507
|
-
elif command_type == "unmaximize_window_by_id":
|
1508
|
-
result = self.app.unmaximize_window_by_id(params["window_id"])
|
1509
|
-
|
1510
|
-
elif command_type == "capture_window_by_id":
|
1511
|
-
result = self.app.capture_window_by_id(params["window_id"], params["save_path"])
|
1512
|
-
|
1513
1489
|
elif command_type == "set_tray_icon":
|
1514
1490
|
result = self.app.set_tray_icon(params["tray_icon_path"])
|
1515
1491
|
|
@@ -1802,141 +1778,6 @@ class Pyloid(QObject):
|
|
1802
1778
|
"""
|
1803
1779
|
return self.execute_command("get_window_by_id", {"window_id": window_id})
|
1804
1780
|
|
1805
|
-
def hide_window_by_id(self, window_id: str) -> None:
|
1806
|
-
"""
|
1807
|
-
Hides the window with the given ID.
|
1808
|
-
|
1809
|
-
Parameters
|
1810
|
-
----------
|
1811
|
-
window_id : str
|
1812
|
-
The ID of the window to hide
|
1813
|
-
|
1814
|
-
Examples
|
1815
|
-
--------
|
1816
|
-
>>> app = Pyloid(app_name="Pyloid-App")
|
1817
|
-
>>> app.hide_window_by_id("some-window-id")
|
1818
|
-
"""
|
1819
|
-
return self.execute_command("hide_window_by_id", {"window_id": window_id})
|
1820
|
-
|
1821
|
-
def show_window_by_id(self, window_id: str) -> None:
|
1822
|
-
"""
|
1823
|
-
Shows and focuses the window with the given ID.
|
1824
|
-
|
1825
|
-
Parameters
|
1826
|
-
----------
|
1827
|
-
window_id : str
|
1828
|
-
The ID of the window to show
|
1829
|
-
|
1830
|
-
Examples
|
1831
|
-
--------
|
1832
|
-
>>> app = Pyloid(app_name="Pyloid-App")
|
1833
|
-
>>> app.show_window_by_id("some-window-id")
|
1834
|
-
"""
|
1835
|
-
return self.execute_command("show_window_by_id", {"window_id": window_id})
|
1836
|
-
|
1837
|
-
def close_window_by_id(self, window_id: str) -> None:
|
1838
|
-
"""
|
1839
|
-
Closes the window with the given ID.
|
1840
|
-
|
1841
|
-
Parameters
|
1842
|
-
----------
|
1843
|
-
window_id : str
|
1844
|
-
The ID of the window to close
|
1845
|
-
|
1846
|
-
Examples
|
1847
|
-
--------
|
1848
|
-
>>> app = Pyloid(app_name="Pyloid-App")
|
1849
|
-
>>> app.close_window_by_id("some-window-id")
|
1850
|
-
"""
|
1851
|
-
return self.execute_command("close_window_by_id", {"window_id": window_id})
|
1852
|
-
|
1853
|
-
def toggle_fullscreen_by_id(self, window_id: str) -> None:
|
1854
|
-
"""
|
1855
|
-
Toggles fullscreen mode for the window with the given ID.
|
1856
|
-
|
1857
|
-
Parameters
|
1858
|
-
----------
|
1859
|
-
window_id : str
|
1860
|
-
The ID of the window to toggle fullscreen mode
|
1861
|
-
|
1862
|
-
Examples
|
1863
|
-
--------
|
1864
|
-
>>> app = Pyloid(app_name="Pyloid-App")
|
1865
|
-
>>> app.toggle_fullscreen_by_id("some-window-id")
|
1866
|
-
"""
|
1867
|
-
return self.execute_command("toggle_fullscreen_by_id", {"window_id": window_id})
|
1868
|
-
|
1869
|
-
def minimize_window_by_id(self, window_id: str) -> None:
|
1870
|
-
"""
|
1871
|
-
Minimizes the window with the given ID.
|
1872
|
-
|
1873
|
-
Parameters
|
1874
|
-
----------
|
1875
|
-
window_id : str
|
1876
|
-
The ID of the window to minimize
|
1877
|
-
|
1878
|
-
Examples
|
1879
|
-
--------
|
1880
|
-
>>> app = Pyloid(app_name="Pyloid-App")
|
1881
|
-
>>> app.minimize_window_by_id("some-window-id")
|
1882
|
-
"""
|
1883
|
-
return self.execute_command("minimize_window_by_id", {"window_id": window_id})
|
1884
|
-
|
1885
|
-
def maximize_window_by_id(self, window_id: str) -> None:
|
1886
|
-
"""
|
1887
|
-
Maximizes the window with the given ID.
|
1888
|
-
|
1889
|
-
Parameters
|
1890
|
-
----------
|
1891
|
-
window_id : str
|
1892
|
-
The ID of the window to maximize
|
1893
|
-
|
1894
|
-
Examples
|
1895
|
-
--------
|
1896
|
-
>>> app = Pyloid(app_name="Pyloid-App")
|
1897
|
-
>>> app.maximize_window_by_id("some-window-id")
|
1898
|
-
"""
|
1899
|
-
return self.execute_command("maximize_window_by_id", {"window_id": window_id})
|
1900
|
-
|
1901
|
-
def unmaximize_window_by_id(self, window_id: str) -> None:
|
1902
|
-
"""
|
1903
|
-
Unmaximizes the window with the given ID.
|
1904
|
-
|
1905
|
-
Parameters
|
1906
|
-
----------
|
1907
|
-
window_id : str
|
1908
|
-
The ID of the window to unmaximize
|
1909
|
-
|
1910
|
-
Examples
|
1911
|
-
--------
|
1912
|
-
>>> app = Pyloid(app_name="Pyloid-App")
|
1913
|
-
>>> app.unmaximize_window_by_id("some-window-id")
|
1914
|
-
"""
|
1915
|
-
return self.execute_command("unmaximize_window_by_id", {"window_id": window_id})
|
1916
|
-
|
1917
|
-
def capture_window_by_id(self, window_id: str, save_path: str) -> Optional[str]:
|
1918
|
-
"""
|
1919
|
-
Captures the specified window.
|
1920
|
-
|
1921
|
-
Parameters
|
1922
|
-
----------
|
1923
|
-
window_id : str
|
1924
|
-
The ID of the window to capture
|
1925
|
-
save_path : str
|
1926
|
-
The path to save the captured image
|
1927
|
-
|
1928
|
-
Returns
|
1929
|
-
-------
|
1930
|
-
Optional[str]
|
1931
|
-
The path of the saved image. Returns None if the window is not found or an error occurs.
|
1932
|
-
|
1933
|
-
Examples
|
1934
|
-
--------
|
1935
|
-
>>> app = Pyloid(app_name="Pyloid-App")
|
1936
|
-
>>> image_path = app.capture_window_by_id("some-window-id", "save/image.png")
|
1937
|
-
"""
|
1938
|
-
return self.execute_command("capture_window_by_id", {"window_id": window_id, "save_path": save_path})
|
1939
|
-
|
1940
1781
|
def set_tray_icon(self, tray_icon_path: str) -> bool:
|
1941
1782
|
"""
|
1942
1783
|
Dynamically sets the tray icon.
|
@@ -0,0 +1,56 @@
|
|
1
|
+
import threading
|
2
|
+
from http.server import HTTPServer, SimpleHTTPRequestHandler
|
3
|
+
from typing import Optional
|
4
|
+
from .utils import get_free_port
|
5
|
+
|
6
|
+
class CustomStaticHandler(SimpleHTTPRequestHandler):
|
7
|
+
def __init__(self, *args, directory=None, **kwargs):
|
8
|
+
super().__init__(*args, directory=directory, **kwargs)
|
9
|
+
|
10
|
+
def log_message(self, format, *args):
|
11
|
+
pass
|
12
|
+
|
13
|
+
def pyloid_serve(
|
14
|
+
directory: str,
|
15
|
+
port: Optional[int] = None,
|
16
|
+
) -> str:
|
17
|
+
"""
|
18
|
+
Static file server starts.
|
19
|
+
|
20
|
+
Args
|
21
|
+
----
|
22
|
+
directory (str): Path to the static file directory to serve
|
23
|
+
port (int, optional): Server port (default: None - will use a random free port)
|
24
|
+
|
25
|
+
Returns
|
26
|
+
-------
|
27
|
+
str
|
28
|
+
URL of the started server
|
29
|
+
|
30
|
+
Examples
|
31
|
+
--------
|
32
|
+
```python
|
33
|
+
from pyloid import Pyloid
|
34
|
+
from pyloid.serve import pyloid_serve
|
35
|
+
|
36
|
+
app = Pyloid("Pyloid-App")
|
37
|
+
url = pyloid_serve("dist")
|
38
|
+
window = app.create_window("Pyloid-App")
|
39
|
+
window.load_url(url)
|
40
|
+
window.show_and_focus()
|
41
|
+
```
|
42
|
+
"""
|
43
|
+
|
44
|
+
if port is None:
|
45
|
+
port = get_free_port()
|
46
|
+
|
47
|
+
handler = lambda *args: CustomStaticHandler(*args, directory=directory)
|
48
|
+
server = HTTPServer(("127.0.0.1", port), handler)
|
49
|
+
|
50
|
+
thread = threading.Thread(
|
51
|
+
target=server.serve_forever,
|
52
|
+
daemon=True
|
53
|
+
)
|
54
|
+
thread.start()
|
55
|
+
|
56
|
+
return f"http://127.0.0.1:{port}"
|
@@ -122,6 +122,37 @@ def get_absolute_path(path: str) -> str:
|
|
122
122
|
return os.path.normpath(os.path.abspath(path))
|
123
123
|
|
124
124
|
def get_free_port() -> int:
|
125
|
+
"""
|
126
|
+
Finds and returns an available random network port number from the operating system.
|
127
|
+
|
128
|
+
This function creates a socket and binds it to port '0', allowing the operating system
|
129
|
+
to allocate a random available port. It retrieves the port number and safely closes
|
130
|
+
the socket afterward.
|
131
|
+
|
132
|
+
Returns
|
133
|
+
-------
|
134
|
+
int
|
135
|
+
An available network port number (typically in the range 1024-65535)
|
136
|
+
|
137
|
+
Notes
|
138
|
+
-----
|
139
|
+
- Since this function closes the socket immediately after finding a port, there is a
|
140
|
+
possibility that the port could be reassigned to another process.
|
141
|
+
- It is recommended to use the port number quickly after receiving it.
|
142
|
+
- This function interacts with the operating system's network stack, so its behavior
|
143
|
+
may vary depending on firewall or network settings.
|
144
|
+
|
145
|
+
Examples
|
146
|
+
--------
|
147
|
+
>>> from pyloid.utils import get_free_port
|
148
|
+
>>> port = get_free_port()
|
149
|
+
>>> print(f"Found available port: {port}")
|
150
|
+
Found available port: 49152
|
151
|
+
|
152
|
+
>>> # Web server example
|
153
|
+
>>> import http.server
|
154
|
+
>>> server = http.server.HTTPServer(('localhost', port), http.server.SimpleHTTPRequestHandler)
|
155
|
+
"""
|
125
156
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
126
157
|
s.bind(('', 0))
|
127
158
|
return s.getsockname()[1]
|
@@ -1,13 +0,0 @@
|
|
1
|
-
from ..api import PyloidAPI, Bridge
|
2
|
-
|
3
|
-
class BaseAPI(PyloidAPI):
|
4
|
-
def __init__(self, window_id: str, data: dict):
|
5
|
-
super().__init__()
|
6
|
-
self.window_id: str = window_id
|
7
|
-
self.data: dict = data
|
8
|
-
|
9
|
-
@Bridge(result=str)
|
10
|
-
def get_data(self):
|
11
|
-
"""Returns the shared data of the application."""
|
12
|
-
return self.data
|
13
|
-
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|