66# Import all the raw bindings
77import webui_bindings as _raw
88
9- # Define the C function type for the file handler
9+ # The C function type for the file handler
1010filehandler_callback = CFUNCTYPE (
1111 c_void_p , # Return type: pointer to the HTTP response bytes
1212 c_char_p , # filename: const char*
1313 POINTER (c_int ) # length: int*
1414)
1515
16+ # C function type for the file handler window
1617filehandler_window_callback = CFUNCTYPE (
1718 c_size_t ,
1819 c_void_p ,
2425
2526
2627Browser = _raw .WebuiBrowser
28+ """
29+ NoBrowser = 0 - No web browser
30+ AnyBrowser = 1 - Default recommended web browser
31+ Chrome = 2 - Google Chrome
32+ Firefox = 3 - Mozilla Firefox
33+ Edge = 4 - Microsoft Edge
34+ Safari = 5 - Apple Safari
35+ Chromium = 6 - The Chromium Project
36+ Opera = 7 - Opera Browser
37+ Brave = 8 - The Brave Browser
38+ Vivaldi = 9 - The Vivaldi Browser
39+ Epic = 10 - The Epic Browser
40+ Yandex = 11 - The Yandex Browser
41+ ChromiumBased = 12 - Any Chromium based browser
42+ Webview = 13 - WebView (Non-web-browser)
43+ """
44+
2745Runtime = _raw .WebuiRuntime
46+ """
47+ NoRuntime = 0 - Prevent WebUI from using any runtime for .js and .ts files
48+ Deno = 1 - Use Deno runtime for .js and .ts files
49+ NodeJS = 2 - Use Nodejs runtime for .js files
50+ Bun = 3 - Use Bun runtime for .js and .ts files
51+ """
52+
2853EventType = _raw .WebuiEvent
54+ """
55+ DISCONNECTED = 0 - Window disconnection event
56+ CONNECTED = 1 - Window connection event
57+ MOUSE_CLICK = 2 - Mouse click event
58+ NAVIGATION = 3 - Window navigation event
59+ CALLBACK = 4 - Function call event
60+ """
61+
2962Config = _raw .WebuiConfig
63+ """
64+ show_wait_connection = 0:
65+ Control if 'webui_show()', 'webui_show_browser()' and
66+ 'webui_show_wv()' should wait for the window to connect
67+ before returns or not.
68+ Default: True
69+
70+
71+ ui_event_blocking = 1:
72+ Control if WebUI should block and process the UI events
73+ one a time in a single thread `True`, or process every
74+ event in a new non-blocking thread `False`. This updates
75+ all windows. You can use `webui_set_event_blocking()` for
76+ a specific single window update.
77+ Default: False
78+
79+
80+ folder_monitor = 2:
81+ Automatically refresh the window UI when any file in the
82+ root folder gets changed.
83+ Default: False
84+
85+
86+ multi_client = 3:
87+ Allow multiple clients to connect to the same window,
88+ This is helpful for web apps (non-desktop software),
89+ Please see the documentation for more details.
90+ Default: False
91+
92+
93+ use_cookies = 4:
94+ Allow or prevent WebUI from adding `webui_auth` cookies.
95+ WebUI uses these cookies to identify clients and block
96+ unauthorized access to the window content using a URL.
97+ Please keep this option to `True` if you want only a single
98+ client to access the window content.
99+ Default: True
100+
101+
102+ asynchronous_response = 5:
103+ If the backend uses asynchronous operations, set this
104+ option to `True`. This will make webui wait until the
105+ backend sets a response using `webui_return_x()`.
106+ """
30107
31108
32109# == Definitions ==============================================================
33110
34111
35112# -- JavaScript responses -----------------------
36113class JavaScript :
114+ """
115+ A return response type for functions dealing with JavaScript.
116+ """
37117 error = False
38118 response = ""
39119
40120
41121# -- Event Object -------------------------------
42122class Event :
43- """Pythonic wrapper around webui_event_t."""
123+ """
124+ WebUI Event Object
125+
126+ Caries most of the client-side functions but also caries has reference to
127+ the Window object to be able to call Window related functions if needed.
128+ """
44129 __slots__ = ("window" , "event_type" , "element" , "event_number" , "bind_id" ,
45130 "client_id" , "connection_id" , "cookies" )
46131
@@ -55,7 +140,9 @@ def __init__(self, win: Window, c_event: _raw.WebuiEventT):
55140 self .cookies = c_event .cookies .decode ('utf-8' ) if c_event .cookies else ''
56141
57142 def _c_event (self ) -> _raw .WebuiEventT :
58- """Rebuild the underlying C struct if needed."""
143+ """
144+ Rebuild of the underlying C struct for interacting with the C API
145+ """
59146 return _raw .WebuiEventT (
60147 window = c_size_t (self .window .get_window_id ),
61148 event_type = self .event_type ,
@@ -69,14 +156,45 @@ def _c_event(self) -> _raw.WebuiEventT:
69156
70157 # -- show_client --------------------------------
71158 def show_client (self , content : str ) -> bool :
159+ """
160+ Display content in the client interface.
161+
162+ Args:
163+ content (str): The content to be displayed in the client, encoded in UTF-8.
164+
165+ Returns:
166+ bool: True if the content was successfully displayed, False otherwise.
167+ """
72168 return bool (_raw .webui_show_client (byref (self ._c_event ()), content .encode ('utf-8' )))
73169
74170 # -- close_client -------------------------------
75- def close_client (self ):
171+ def close_client (self ) -> None :
172+ """
173+ Close the client interface.
174+
175+ This method closes the currently active client interface associated with the event.
176+
177+ Returns:
178+ None
179+ """
76180 _raw .webui_close_client (byref (self ._c_event ()))
77181
78182 # -- send_raw_client ----------------------------
79183 def send_raw_client (self , function : str , raw : Optional [int ], size : int ) -> None :
184+ """
185+ Send raw data to the client for processing.
186+
187+ Args:
188+ function (str): The name of the function to invoke on the client, encoded in UTF-8.
189+ raw (Optional[int]): A pointer to the raw data. Must not be `None`.
190+ size (int): The size of the raw data in bytes.
191+
192+ Raises:
193+ ValueError: If `raw` is `None`.
194+
195+ Returns:
196+ None
197+ """
80198 if raw is None :
81199 raise ValueError ("Invalid Pointer: Cannot send a null pointer." )
82200 _raw .webui_send_raw_client (
@@ -88,14 +206,44 @@ def send_raw_client(self, function: str, raw: Optional[int], size: int) -> None:
88206
89207 # -- navigate_client ----------------------------
90208 def navigate_client (self , url : str ) -> None :
209+ """
210+ Navigate the client to a specified URL.
211+
212+ Args:
213+ url (str): The URL to navigate the client to, encoded in UTF-8.
214+
215+ Returns:
216+ None
217+ """
91218 _raw .webui_navigate_client (byref (self ._c_event ()), c_char_p (url .encode ("utf-8" )))
92219
93220 # -- run_client ---------------------------------
94221 def run_client (self , script : str ) -> None :
222+ """
223+ Execute a script in the client.
224+
225+ Args:
226+ script (str): The script to be executed in the client, encoded in UTF-8.
227+
228+ Returns:
229+ None
230+ """
95231 _raw .webui_run_client (byref (self ._c_event ()), c_char_p (script .encode ("utf-8" )))
96232
97233 # -- script_client ------------------------------
98234 def script_client (self , script : str , timeout : int = 0 , buffer_size : int = 4096 ) -> JavaScript :
235+ """
236+ Execute a JavaScript script in the client and retrieve the result.
237+
238+ Args:
239+ script (str): The JavaScript code to execute in the client, encoded in UTF-8.
240+ timeout (int, optional): The maximum time in milliseconds to wait for the script to execute. Defaults to 0 (no timeout).
241+ buffer_size (int, optional): The size of the buffer to store the result. Defaults to 4096.
242+
243+ Returns:
244+ JavaScript: An object containing the result of the script execution. The `data` attribute contains the script output,
245+ and the `error` attribute indicates whether an error occurred (True if there was an error, False otherwise).
246+ """
99247 # Create a mutable buffer in which the C function can store the result
100248 buffer = create_string_buffer (buffer_size )
101249
@@ -117,6 +265,12 @@ def script_client(self, script: str, timeout: int = 0, buffer_size: int = 4096)
117265
118266 # -- get_count ----------------------------------
119267 def get_count (self ) -> int :
268+ """
269+ Retrieve how many arguments there are in an event.
270+
271+ Returns:
272+ int: the number of arguments.
273+ """
120274 return int (_raw .webui_get_count (byref (self ._c_event ())))
121275
122276 # -- get_int_at ---------------------------------
0 commit comments