@@ -44,8 +44,8 @@ class event:
4444 window = 0
4545 event_type = 0
4646 element = ""
47- data = ""
48- len = 0
47+ event_num = 0
48+ bind_id = 0
4949
5050
5151# JavaScript
@@ -93,9 +93,8 @@ def __init__(self):
9393 ctypes .c_size_t , # window
9494 ctypes .c_uint , # event type
9595 ctypes .c_char_p , # element
96- ctypes .c_char_p , # data
97- ctypes .c_longlong , # data len
98- ctypes .c_uint ) # event number
96+ ctypes .c_size_t , # event number
97+ ctypes .c_uint ) # Bind ID
9998 self .c_events = py_fun (self ._events )
10099 except OSError as e :
101100 print (
@@ -112,26 +111,21 @@ def __init__(self):
112111 def _events (self , window : ctypes .c_size_t ,
113112 event_type : ctypes .c_uint ,
114113 _element : ctypes .c_char_p ,
115- data : ctypes .c_char_p ,
116- len : ctypes .c_longlong ,
117- event_number : ctypes .c_uint ):
114+ event_number : ctypes .c_longlong ,
115+ bind_id : ctypes .c_uint ):
118116 element = _element .decode ('utf-8' )
119- func_id = self .window_id + element
120- if self .cb_fun_list [func_id ] is None :
117+ if self .cb_fun_list [bind_id ] is None :
121118 print ('webui_lib error: Callback is None.' )
122119 return
123120 # Create event
124121 e = event ()
125122 e .window = self # e.window should refer to this class
126123 e .event_type = int (event_type )
127124 e .element = element
128- e .len = len
129- if data is not None :
130- e .data = data .decode ('utf-8' )
131- else :
132- e .data = ''
125+ e .event_num = event_number
126+ e .bind_id = bind_id
133127 # User callback
134- cb_result = self .cb_fun_list [func_id ](e )
128+ cb_result = self .cb_fun_list [bind_id ](e )
135129 if cb_result is not None :
136130 cb_result_str = str (cb_result )
137131 cb_result_encode = cb_result_str .encode ('utf-8' )
@@ -149,17 +143,16 @@ def bind(self, element, func):
149143 _err_library_not_found ('bind' )
150144 return
151145 # Bind
152- webui_lib .webui_interface_bind (
146+ bindId = webui_lib .webui_interface_bind (
153147 self .window ,
154148 element .encode ('utf-8' ),
155149 self .c_events )
156150 # Add CB to the list
157- func_id = self .window_id + element
158- self .cb_fun_list [func_id ] = func
151+ self .cb_fun_list [bindId ] = func
159152
160153
161154 # Show a window using a embedded HTML, or a file. If the window is already opened then it will be refreshed.
162- def show (self , content = "<html></html>" , browser :int = 0 ):
155+ def show (self , content = "<html></html>" , browser :int = browser . ChromiumBased ):
163156 global webui_lib
164157 if self .window == 0 :
165158 _err_window_is_none ('show' )
@@ -184,18 +177,6 @@ def set_runtime(self, rt=runtime.deno):
184177 ctypes .c_uint (rt ))
185178
186179
187- def set_multi_access (self , status = False ):
188- global webui_lib
189- if self .window == 0 :
190- _err_window_is_none ('set_multi_access' )
191- return
192- if webui_lib is None :
193- _err_library_not_found ('set_multi_access' )
194- return
195- webui_lib .webui_set_multi_access (self .window ,
196- ctypes .c_bool (status ))
197-
198-
199180 # Close the window.
200181 def close (self ):
201182 global webui_lib
@@ -213,6 +194,46 @@ def is_shown(self):
213194 r = bool (webui_lib .webui_is_shown (self .window ))
214195 return r
215196
197+
198+ def get_str (self , e : event , index : c_size_t = 0 ) -> str :
199+ global webui_lib
200+ if webui_lib is None :
201+ _err_library_not_found ('get_str' )
202+ return
203+ c_res = webui_lib .webui_interface_get_string_at
204+ c_res .restype = ctypes .c_char_p
205+ data = c_res (self .window ,
206+ ctypes .c_uint (e .event_num ),
207+ ctypes .c_uint (index ))
208+ decode = data .decode ('utf-8' )
209+ return decode
210+
211+ def get_int (self , e : event , index : c_size_t = 0 ) -> int :
212+ global webui_lib
213+ if webui_lib is None :
214+ _err_library_not_found ('get_str' )
215+ return
216+ c_res = webui_lib .webui_interface_get_int_at
217+ c_res .restype = ctypes .c_longlong
218+ data = c_res (self .window ,
219+ ctypes .c_uint (e .event_num ),
220+ ctypes .c_uint (index ))
221+ return data
222+
223+
224+ def get_bool (self , e : event , index : c_size_t = 0 ) -> bool :
225+ global webui_lib
226+ if webui_lib is None :
227+ _err_library_not_found ('get_str' )
228+ return
229+ c_res = webui_lib .webui_interface_get_bool_at
230+ c_res .restype = ctypes .c_bool
231+ data = c_res (self .window ,
232+ ctypes .c_uint (e .event_num ),
233+ ctypes .c_uint (index ))
234+ return data
235+
236+
216237 # Run a JavaScript, and get the response back (Make sure your local buffer can hold the response).
217238 def script (self , script , timeout = 0 , response_size = (1024 * 8 )) -> javascript :
218239 global webui_lib
@@ -255,7 +276,7 @@ def run(self, script):
255276def _get_library_path () -> str :
256277 global webui_path
257278 if platform .system () == 'Darwin' :
258- file = '/webui-2- x64.dyn'
279+ file = '/webui-macos-clang- x64/webui-2 .dyn'
259280 path = os .getcwd () + file
260281 if os .path .exists (path ):
261282 return path
@@ -264,7 +285,7 @@ def _get_library_path() -> str:
264285 return path
265286 return path
266287 elif platform .system () == 'Windows' :
267- file = '\\ webui-2- x64.dll'
288+ file = '\\ webui-windows-msvc- x64\\ webui-2 .dll'
268289 path = os .getcwd () + file
269290 if os .path .exists (path ):
270291 return path
@@ -273,7 +294,7 @@ def _get_library_path() -> str:
273294 return path
274295 return path
275296 elif platform .system () == 'Linux' :
276- file = '/webui-2- x64.so'
297+ file = '/webui-linux-gcc- x64/webui-2 .so'
277298 path = os .getcwd () + file
278299 if os .path .exists (path ):
279300 return path
0 commit comments