Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build/Windows/GCC/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ debug:
# Static with Debug info
@echo Build WebUI Library (Debug Static)...
@gcc -g -m64 -o mongoose.o -I "$(INCLUDE)" -c "$(SOURCE)/mongoose.c" -Wno-stringop-overread
@gcc -g -m64 -o webui.o -I "$(INCLUDE)" -c "$(SOURCE)/webui.c"
@gcc -g -m64 -o webui.o -I "$(INCLUDE)" -c "$(SOURCE)/webui.c" -DWEBUI_LOG
@ar rc libwebui-2-static-x64.a webui.o mongoose.o
@ranlib libwebui-2-static-x64.a
# Dynamic with Debug info
@echo Build WebUI Library (Debug Dynamic)...
@gcc -g -fPIC -m64 -o mongoose.o -I "$(INCLUDE)" -c "$(SOURCE)/mongoose.c" -Wno-stringop-overread
@gcc -g -fPIC -m64 -o webui.o -I "$(INCLUDE)" -c "$(SOURCE)/webui.c"
@gcc -g -fPIC -m64 -o webui.o -I "$(INCLUDE)" -c "$(SOURCE)/webui.c" -DWEBUI_LOG
@gcc -g -shared -o webui-2-x64.dll webui.o mongoose.o -lws2_32
# Clean
@- del *.o >nul 2>&1
Expand Down
4 changes: 2 additions & 2 deletions build/Windows/MSVC/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ debug:
# Static with Debug info
@echo Build WebUI Library (Debug Static)...
@cl /Zi /Fomongoose.obj /c /EHsc "../../../src/mongoose.c" /I "../../../include" >nul 2>&1
@cl /Zi /Fowebui.obj /c /EHsc "../../../src/webui.c" /I "../../../include" >nul 2>&1
@cl /Zi /Fowebui.obj /c /EHsc /DWEBUI_LOG "../../../src/webui.c" /I "../../../include" >nul 2>&1
@lib /OUT:webui-2-static-x64.lib webui.obj mongoose.obj >nul 2>&1
# Dynamic with Debug info
@echo Build WebUI Library (Debug Dynamic)...
@cl /Zi /Fomongoose.obj /c /EHsc "../../../src/mongoose.c" /I "../../../include" >nul 2>&1
@cl /Zi /Fowebui.obj /c /EHsc "../../../src/webui.c" /I "../../../include" >nul 2>&1
@cl /Zi /Fowebui.obj /c /EHsc /DWEBUI_LOG "../../../src/webui.c" /I "../../../include" >nul 2>&1
@link /DLL /OUT:webui-2-x64.dll webui.obj mongoose.obj user32.lib >nul 2>&1
# Clean
@- del *.obj >nul 2>&1
Expand Down
4 changes: 2 additions & 2 deletions build/Windows/TCC/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ debug:
# Static with Debug info
@echo Build WebUI Library (Debug Static)...
@tcc -g -m64 -o mongoose.o -I "$(INCLUDE)" -c "$(SOURCE)/mongoose.c"
@tcc -g -m64 -o webui.o -I "$(INCLUDE)" -c "$(SOURCE)/webui.c"
@tcc -g -m64 -o webui.o -I "$(INCLUDE)" -c "$(SOURCE)/webui.c" -DWEBUI_LOG
@tcc -m64 -ar rcs libwebui-2-static-x64.a webui.o mongoose.o
# Dynamic with Debug info
@echo Build WebUI Library (Debug Dynamic)...
@tcc -g -fPIC -m64 -o mongoose.o -I "$(INCLUDE)" -c "$(SOURCE)/mongoose.c"
@tcc -g -fPIC -m64 -o webui.o -I "$(INCLUDE)" -c "$(SOURCE)/webui.c"
@tcc -g -fPIC -m64 -o webui.o -I "$(INCLUDE)" -c "$(SOURCE)/webui.c" -DWEBUI_LOG
@tcc -g -shared -o webui-2-x64.dll webui.o mongoose.o -lws2_32
# Clean
@- del *.o >nul 2>&1
Expand Down
4 changes: 2 additions & 2 deletions examples/C/call_c_from_js/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ int main() {
"background: linear-gradient(to right, #2C5364, #203A43, #0F2027);"
"text-align:center; font-size: 18px; font-family: sans-serif;}</style></head><body>"
"<h2>WebUI 2 - C99 Example</h2>"
"<p>Call C function with arguments</p><br>"
"<p>Call C function with arguments (See log in the Windows console)</p><br>"
"<button OnClick=\"webui_fn('One', 'Hello');\">Call C function one</button><br><br>"
"<button OnClick=\"webui_fn('Two', 2022);\">Call C function two</button><br><br>"
"<button OnClick=\"webui_fn('Three', true);\">Call C function three</button><br><br>"
Expand All @@ -74,7 +74,7 @@ int main() {
"<script>"
" function MyJS() {"
" const number = document.getElementById('MyInput').value;"
" const result = webui_fn('Four', number);"
" var result = webui_fn('Four', number);"
" document.getElementById('MyInput').value = result;"
" }"
"</script>"
Expand Down
35 changes: 27 additions & 8 deletions examples/Python/dev/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,50 @@
<body>
<h2>Python Debug & Development</h2>
<br>
<input type="password" id="MyInput" OnKeyUp="document.getElementById('err').innerHTML='&nbsp;';" autocomplete="off">
<input type="text" id="MyInput" OnKeyUp="document.getElementById('err').innerHTML='&nbsp;';" autocomplete="off" value=\"2\">
<br>
<h3 id="err" style="color: #dbdd52">&nbsp;</h3>
<h3 id="err" style="color: #dbdd52">&nbsp;</h3>
<br>
<button id="TestID">Test</button> - <button id="ExitID">Exit</button>
</body>
</html>
<button id="TestID">Test Python-To-JS</button>
<button OnClick="MyJS();">Test JS-To-Python</button>
<button id="ExitID">Exit</button>
<script>
function MyJS() {
const number = document.getElementById('MyInput').value;
var result = webui_fn('Test2', number);
document.getElementById('MyInput').value = result;
}
</script>
</body></html>
"""

def test(e : webui.event):

# Print some info (optional)
print('Element_id: ' + str(e.element_id))
print('Window_id: ' + str(e.window_id))
print('Element_name: ' + e.element_name)

# Run JavaScript to get the password
res = e.window.run_js("return document.getElementById(\"MyInput\").value;")
res = e.window.run_js("return document.getElementById('MyInput').value;")

# Check for any error
if res.error is True:
print("JavaScript Error -> Output: [" + res.data + "]")
else:
print("JavaScript OK -> Output: [" + res.data + "]")

def test2(e : webui.event):
print('Element_id: ' + str(e.element_id))
print('Window_id: ' + str(e.window_id))
print('Element_name: ' + e.element_name)
print('Data: ' + e.data)
v = int(e.data)
v = v * 2
return v

def close(e : webui.event):
print('Element_id: ' + str(e.element_id))
print('Window_id: ' + str(e.window_id))
print('Element_name: ' + e.element_name)
webui.exit()

def main():
Expand All @@ -80,6 +98,7 @@ def main():

# Bind am HTML element ID with a python function
MyWindow.bind_all(test)
MyWindow.bind('Test2', test2)
MyWindow.bind('ExitID', close)

# Show the window
Expand Down
2 changes: 1 addition & 1 deletion examples/Rust/hello_world/src/Webui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub struct webui_t {
pub initialized: bool,
pub cb: [::std::option::Option<unsafe extern "C" fn(e: *mut webui_event_t)>;
32usize],
pub cb_int: [::std::option::Option<
pub cb_interface: [::std::option::Option<
unsafe extern "C" fn(
element_id: ::std::os::raw::c_uint,
window_id: ::std::os::raw::c_uint,
Expand Down
13 changes: 8 additions & 5 deletions include/webui.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#define WEBUI_MAX_PORT (65500) // Should be less than 65535
#define WEBUI_MAX_BUF (1024000) // 1024 Kb max dynamic memory allocation
#define WEBUI_DEFAULT_PATH "." // Default root path
#define WEBUI_DEF_TIMEOUT (8) // Default startup timeout in seconds

// -- C STD ---------------------------
#include <stdbool.h>
Expand All @@ -42,6 +43,7 @@
#include <stddef.h>
#include <time.h>
#include <errno.h>
#include <math.h>
#if defined(__GNUC__) || defined(__TINYC__)
#include <dirent.h>
#endif
Expand Down Expand Up @@ -124,7 +126,7 @@ typedef struct webui_event_t {
char* element_name;
webui_window_t* window;
void* data;
unsigned int data_len;
void* response;
} webui_event_t;
typedef struct webui_javascript_result_t {
bool error;
Expand All @@ -141,7 +143,6 @@ typedef struct webui_cb_t {
char* webui_internal_id;
char* element_name;
void* data;
unsigned int data_len;
} webui_cb_t;
typedef struct webui_cmd_async_t {
webui_window_t* win;
Expand Down Expand Up @@ -189,8 +190,8 @@ typedef struct webui_t {
webui_runtime_t runtime;
bool initialized;
void (*cb[WEBUI_MAX_ARRAY])(webui_event_t* e);
void (*cb_int[WEBUI_MAX_ARRAY])(unsigned int, unsigned int, char*, webui_window_t*);
void (*cb_int_all[1])(unsigned int, unsigned int, char*, webui_window_t*);
void (*cb_interface[WEBUI_MAX_ARRAY])(unsigned int, unsigned int, char*, webui_window_t*, char*, char**);
void (*cb_interface_all[1])(unsigned int, unsigned int, char*, webui_window_t*, char*, char**);
char* executable_path;
void *ptr_list[WEBUI_MAX_ARRAY];
unsigned int ptr_position;
Expand Down Expand Up @@ -236,7 +237,7 @@ typedef struct webui_script_interface_t {
unsigned int length;
const char* data;
} webui_script_interface_t;
EXPORT unsigned int webui_bind_interface(webui_window_t* win, const char* element, void (*func)(unsigned int, unsigned int, char*, webui_window_t*));
EXPORT unsigned int webui_bind_interface(webui_window_t* win, const char* element, void (*func)(unsigned int, unsigned int, char*, webui_window_t*, char*, char**));
EXPORT void webui_script_interface(webui_window_t* win, const char* script, unsigned int timeout, bool* error, unsigned int* length, char* data);
EXPORT void webui_script_interface_struct(webui_window_t* win, webui_script_interface_t* js_int);

Expand Down Expand Up @@ -276,6 +277,8 @@ EXPORT bool _webui_set_root_folder(webui_window_t* win, const char* path);
EXPORT void _webui_wait_process(webui_window_t* win, bool status);
EXPORT const char* _webui_generate_js_bridge(webui_window_t* win);
EXPORT void _webui_print_hex(const char* data, size_t len);
EXPORT void _webui_free_mem(void **p);
EXPORT void _webui_str_copy(char *destination, char *source);
#ifdef _WIN32
EXPORT DWORD WINAPI _webui_cb(LPVOID _arg);
EXPORT DWORD WINAPI _webui_run_browser_task(LPVOID _arg);
Expand Down
23 changes: 18 additions & 5 deletions packages/PyPI/src/webui/webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@

WebUI = None
WebUI_Path = os.path.dirname(__file__)
PTR_CHAR = ctypes.POINTER(ctypes.c_char)
PTR_PTR_CHAR = ctypes.POINTER(PTR_CHAR)


# Event
class event:
element_id = 0
window_id = 0
element_name = ""
data = ""
window = None
c_window = None

Expand Down Expand Up @@ -92,7 +95,9 @@ def __init__(self):
ctypes.c_uint,
ctypes.c_uint,
ctypes.c_char_p,
ctypes.c_void_p)
ctypes.c_void_p,
ctypes.c_char_p,
PTR_PTR_CHAR)
self.c_events = py_fun(self.events)
except OSError as e:
print(
Expand All @@ -107,17 +112,25 @@ def __del__(self):


def events(self, element_id, window_id,
element_name, window):
element_name, window, data, response):
if self.cb_fun_list[int(element_id)] is None:
print('WebUI Error: Callback is None.')
return
# Create event
e = event()
e.element_id = element_id
e.window_id = window_id
e.element_id = int(element_id)
e.window_id = int(window_id)
e.data = data.decode('utf-8')
e.element_name = element_name.decode('utf-8')
e.window = self
e.c_window = window
self.cb_fun_list[element_id](e)
# User callback
cb_res = str(self.cb_fun_list[element_id](e))
cb_res_encode = cb_res.encode('utf-8')
# Allocate a new memory
buffer = ctypes.create_string_buffer(cb_res_encode)
# Set the response
response[0] = buffer


def bind(self, element, func):
Expand Down
Loading