Skip to content

Commit b251245

Browse files
committed
Update wrapper and libs
1 parent 0cbafd5 commit b251245

File tree

10 files changed

+69
-41
lines changed

10 files changed

+69
-41
lines changed
-475 KB
Binary file not shown.
-225 KB
Binary file not shown.
-243 KB
Binary file not shown.
249 KB
Binary file not shown.
229 KB
Binary file not shown.
498 KB
Binary file not shown.

PyPI/Package/src/webui/webui.py

Lines changed: 56 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -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):
255276
def _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

PyPI/test_package.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<html>
2020
<head>
2121
<title>WebUI 2 - Python Wrapper Test</title>
22+
<script src="webui.js"></script>
2223
<style>
2324
body {
2425
color: white;
@@ -56,13 +57,14 @@ def all_events(e : webui.event):
5657
print('Function: all_events()')
5758
print('Element: ' + e.element)
5859
print('Type: ' + str(e.event_type))
59-
print('Data: ' + e.data)
60+
print(' ')
6061

6162
def python_to_js(e : webui.event):
6263
print('Function: python_to_js()')
6364
print('Element: ' + e.element)
6465
print('Type: ' + str(e.event_type))
65-
print('Data: ' + e.data)
66+
print('Data: ' + e.window.get_str(e))
67+
print(' ')
6668
# Run JavaScript to get the password
6769
res = e.window.script("return document.getElementById('MyInput').value;")
6870
# Check for any error
@@ -72,21 +74,24 @@ def python_to_js(e : webui.event):
7274
print("JavaScript OK: [" + res.data + "]")
7375
# Quick JavaScript (no response waiting)
7476
# e.window.run("alert('Fast!')")
77+
print(' ')
7578

7679
def js_to_python(e : webui.event):
7780
print('Function: js_to_python()')
7881
print('Element: ' + e.element)
7982
print('Type: ' + str(e.event_type))
80-
print('Data: ' + e.data)
81-
v = int(e.data)
83+
print('Data: ' + e.window.get_str(e, 0))
84+
print(' ')
85+
v = int(e.window.get_str(e, 0))
8286
v = v * 2
8387
return v
8488

8589
def exit(e : webui.event):
8690
print('Function: exit()')
8791
print('Element: ' + e.element)
8892
print('Type: ' + str(e.event_type))
89-
print('Data: ' + e.data)
93+
print('Data: ' + e.window.get_str(e, 0))
94+
print(' ')
9095
webui.exit()
9196

9297
def main():

examples/hello_world.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<html>
1010
<head>
1111
<title>WebUI 2 - Python Example</title>
12+
<script src="webui.js"></script>
1213
<style>
1314
body {
1415
color: white;
@@ -38,6 +39,7 @@
3839
<html>
3940
<head>
4041
<title>Dashboard</title>
42+
<script src="webui.js"></script>
4143
<style>
4244
body {
4345
color: white;

examples/minimal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
from webui import webui
55

66
MyWindow = webui.window()
7-
MyWindow.show('<html>Hello World</html>')
7+
MyWindow.show('<html><head><script src=\"webui.js\"></script></head> Hello World ! </html>')
88
webui.wait()
99
print('Thank you.')

0 commit comments

Comments
 (0)