Skip to content

Commit c2a9f44

Browse files
committed
Update examples
1 parent 96de697 commit c2a9f44

File tree

9 files changed

+257
-222
lines changed

9 files changed

+257
-222
lines changed

PyPI/Package/pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ include-package-data = true
2828
where = ["src"]
2929

3030
[tool.setuptools.package-data]
31-
webui = ["webui-windows-msvc-x64/*", "webui-linux-gcc-x64/*", "webui-macos-clang-x64/*", "webui-windows-msvc-arm64/*", "webui-linux-gcc-arm64/*", "webui-macos-clang-arm64/*"]
31+
webui = [
32+
"webui-macos-clang-x64/*","webui-macos-clang-arm64/*","webui-windows-msvc-x64/*","webui-linux-gcc-arm/*","webui-linux-gcc-arm64/*","webui-linux-gcc-x64/*"]

PyPI/Package/src/webui/webui.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,28 @@ def run(self, script):
279279
ctypes.c_char_p(script.encode('utf-8')))
280280

281281

282+
# Set the web-server root folder path for a specific window
283+
def set_root_folder(self, path):
284+
global webui_lib
285+
if self.window == 0:
286+
_err_window_is_none('set_root_folder')
287+
return
288+
if webui_lib is None:
289+
_err_library_not_found('set_root_folder')
290+
return
291+
# Set path
292+
webui_lib.webui_set_root_folder(self.window,
293+
ctypes.c_char_p(path.encode('utf-8')))
294+
295+
282296
def _get_architecture() -> str:
283297
arch = platform.machine()
284298
if arch in ['x86_64', 'AMD64', 'amd64']:
285299
return 'x64'
286-
elif arch in ['aarch64', 'ARM64', 'arm', 'arm64']:
300+
elif arch in ['aarch64', 'ARM64', 'arm64']:
287301
return 'arm64'
302+
elif arch in ['arm']:
303+
return 'arm'
288304
else:
289305
return arch
290306

PyPI/test_package.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import webui
1212

1313
# Use the local WebUI Dynamic lib
14-
# webui.set_library_path('../../../build/Windows/MSVC')
14+
# webui.set_library_path('')
1515

1616
# HTML
1717
html = """
@@ -59,7 +59,7 @@
5959
<script>
6060
function MyJS() {
6161
const number = document.getElementById('MyInput').value;
62-
webui.call('JS2P', number).then((response) => {
62+
JS2P(number).then((response) => {
6363
document.getElementById('MyInput').value = response;
6464
});
6565
}

examples/andershell3000/andershell3000.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def close(self):
3737
self.shell.wait()
3838

3939
def run_command(e : webui.event):
40-
cmd = e.data
40+
cmd = e.window.get_str(e, 0)
4141
if cmd == "exit":
4242
webui.exit()
4343
try:
@@ -49,6 +49,7 @@ def run_command(e : webui.event):
4949
executor = CommandExecutor()
5050
MyWindow = webui.window()
5151
MyWindow.bind("Run", run_command)
52-
MyWindow.show('ui/index.html')
52+
MyWindow.set_root_folder("ui/")
53+
MyWindow.show('index.html')
5354
webui.wait()
5455
executor.close()

examples/andershell3000/ui/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
prompt: function() {
7979
return "$ "
8080
},
81-
banner: "\ndP dP dP dP dP dP dP \n88 88 88 88 88 88 88 \n88 .8P .8P .d8888b. 88d888b. 88 88 88 \n88 d8' d8' 88ooood8 88' `88 88 88 88 \n88.d8P8.d8P 88. ... 88. .88 Y8. .8P 88 \n8888' Y88' `88888P' 88Y8888' `Y88888P' dP\n\nAnderShell 3000 (Python)\n\nWebUI v2.4.0.3 | webui.me\n\n"
81+
banner: "\ndP dP dP dP dP dP dP \n88 88 88 88 88 88 88 \n88 .8P .8P .d8888b. 88d888b. 88 88 88 \n88 d8' d8' 88ooood8 88' `88 88 88 88 \n88.d8P8.d8P 88. ... 88. .88 Y8. .8P 88 \n8888' Y88' `88888P' 88Y8888' `Y88888P' dP\n\nAnderShell 3000 (Python)\n\nWebUI v2.4 | webui.me\n\n"
8282
})
8383
})
8484
}, function(n, t) {

examples/text-editor/main.py

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,22 @@
1-
from tkinter import filedialog
21
from webui import webui
32

4-
import tkinter as tk
5-
import base64 as b64
6-
7-
file_path = ""
8-
9-
def encodeStr(string: str) -> str:
10-
string_bytes = string.encode("ascii")
11-
b64_bytes = b64.b64encode(string_bytes)
12-
b64_string = b64_bytes.decode("ascii")
13-
14-
return b64_string
15-
163
def close(e: webui.event):
174
print("Exit.")
18-
195
# Close all opened windows
206
webui.exit()
217

22-
def openFile(e: webui.event):
23-
global file_path
24-
25-
print("Open.")
26-
27-
# Initialize tkinker
28-
root = tk.Tk()
29-
root.withdraw()
30-
31-
# Open file dialog
32-
file_path = filedialog.askopenfilename()
33-
34-
# If no file was chosen, return
35-
if len(file_path) == 0:
36-
return
37-
38-
with open(file_path) as file:
39-
file_content = file.read() # read file contents into variable
40-
41-
# Send data back to Javascript
42-
e.window.run(f"addText('{encodeStr(file_content)}')")
43-
e.window.run(f"SetFile('{encodeStr(file_path)}')")
44-
45-
def save(e: webui.event):
46-
print("Save.")
47-
48-
with open(file_path, "w") as file:
49-
file.write(e.data) # Write data received from the UI
50-
518
def main():
529
# Create new window
5310
window = webui.window()
5411

5512
# Bind HTML element IDs with Python functions
56-
window.bind("Open", openFile)
57-
window.bind("Save", save)
58-
window.bind("Close", close)
13+
window.bind("__close-btn", close)
14+
15+
# Show the window
16+
window.set_root_folder("ui/")
5917

6018
# Show the window
61-
window.show("ui/MainWindow.html")
19+
window.show("index.html")
6220

6321
# Wait until all windows get closed
6422
webui.wait()
Lines changed: 80 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,113 @@
11
body {
2-
margin: 0;
3-
padding: 0;
4-
height: 100vh;
5-
font-family: 'Courier New', Courier, monospace;
6-
background-image: linear-gradient(to right top, #8e44ad 0%, #3498db 100%);
7-
background-repeat: no-repeat;
8-
background-position: center center;
9-
background-size: cover;
10-
background-attachment : fixed;
11-
color: #ddecf9;
2+
margin: 0;
3+
padding: 0;
4+
height: 100vh;
5+
font-family: 'Courier New', Courier, monospace;
6+
background-image: linear-gradient(to right top, #8e44ad 0%, #3498db 100%);
7+
background-repeat: no-repeat;
8+
background-position: center center;
9+
background-size: cover;
10+
background-attachment: fixed;
11+
color: #ddecf9;
1212
}
1313

1414
.topbar {
15-
width: 100%;
16-
height: 4px;
17-
background-image: linear-gradient(to right, #4ed2e7 0%, #db57eb 50%, #f98818 100%);
15+
width: 100%;
16+
height: 4px;
17+
background-image: linear-gradient(to right, #4ed2e7 0%, #db57eb 50%, #f98818 100%);
1818
}
1919

2020
header {
21-
color: #fff;
21+
color: #fff;
2222
}
2323

2424
/* Nav */
2525

2626
nav {
27-
margin: 0 auto;
28-
padding: 0px;
29-
text-shadow: 1px 1px 2px #000000;
30-
position: relative;
31-
z-index: 99;
32-
font-family: 'Font Awesome 5 Free';
33-
font-size: 18px;
34-
}
35-
36-
nav ul {
37-
margin-top: 0px;
38-
margin-bottom: 0px;
39-
text-align: center;
40-
background: linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.2) 25%, rgba(255, 255, 255, 0.2) 75%, rgba(255, 255, 255, 0) 100%);
41-
box-shadow: 0 0 25px rgba(0, 0, 0, 0.1), inset 0 0 1px rgba(255, 255, 255, 0.6);
42-
cursor: pointer;
43-
}
44-
45-
nav ul li {
46-
display: inline-block;
47-
}
48-
49-
nav ul li a {
50-
padding: 18px;
51-
font-family: "Open Sans";
52-
text-transform:uppercase;
53-
text-decoration: none;
54-
display: block;
55-
}
56-
57-
nav ul li a:hover {
58-
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1), inset 0 0 1px rgba(255, 255, 255, 0.6);
59-
background: rgba(255, 255, 255, 0.1);
60-
}
27+
background: linear-gradient(
28+
90deg,
29+
rgba(255, 255, 255, 0) 0%,
30+
rgba(255, 255, 255, 0.2) 25%,
31+
rgba(255, 255, 255, 0.2) 75%,
32+
rgba(255, 255, 255, 0) 100%
33+
);
34+
box-shadow:
35+
0 0 25px rgba(0, 0, 0, 0.1),
36+
inset 0 0 1px rgba(255, 255, 255, 0.6);
37+
text-align: center;
38+
}
39+
40+
nav button {
41+
background: none;
42+
border: none;
43+
text-shadow: 1px 1px 2px #000000;
44+
font-family: 'Font Awesome 5 Free';
45+
font-size: 18px;
46+
color: #ddecf9;
47+
cursor: pointer;
48+
margin: 0 auto;
49+
padding: 18px;
50+
}
51+
52+
nav button:hover {
53+
box-shadow:
54+
0 0 10px rgba(0, 0, 0, 0.1),
55+
inset 0 0 1px rgba(255, 255, 255, 0.6);
56+
background: rgba(255, 255, 255, 0.1);
57+
}
58+
59+
nav #save-btn:disabled {
60+
pointer-events: none;
61+
color: #7ca0df;
62+
}
63+
64+
nav button i {
65+
/* Click through the icon in the button */
66+
pointer-events: none;
67+
}
6168

6269
/* Code */
6370

6471
.main {
65-
padding: 0px;
72+
padding: 0px;
6673
}
6774

6875
/* About */
6976

7077
.about-box {
71-
display: none;
72-
position: fixed;
73-
z-index: 1;
74-
left: 0;
75-
top: 0;
76-
width: 100%;
77-
height: 100%;
78-
background-image: linear-gradient(to right top, #8e44ad 0%, #3498db 100%);
78+
display: none;
79+
position: fixed;
80+
z-index: 1;
81+
left: 0;
82+
top: 0;
83+
width: 100%;
84+
height: 100%;
85+
background-image: linear-gradient(to right top, #8e44ad 0%, #3498db 100%);
7986
}
80-
87+
8188
.about-box-content {
82-
background-image: linear-gradient(to right top, #8e44ad 0%, #3498db 100%);
83-
position: absolute;
84-
margin: 0;
85-
padding: 10px;
86-
width: 30%;
87-
border-radius: 5px;
88-
top: 50%;
89-
left: 50%;
90-
transform: translate(-50%, -50%);
89+
background-image: linear-gradient(to right top, #8e44ad 0%, #3498db 100%);
90+
position: absolute;
91+
margin: 0;
92+
padding: 10px;
93+
width: 30%;
94+
border-radius: 5px;
95+
top: 50%;
96+
left: 50%;
97+
transform: translate(-50%, -50%);
9198
}
9299

93100
.about-box-content h1 {
94-
text-align: center;
101+
text-align: center;
95102
}
96103

97104
.about-box-content a {
98-
color: inherit;
105+
color: inherit;
99106
}
100107

101108
.CodeMirror {
102-
height: 100%;
103-
font-family: 'Courier New', Courier, monospace;
104-
font-size: 16px;
105-
text-shadow: 1px 1px 2px #000000;
106-
}
107-
108-
.CodeMirror-scroll {
109-
109+
height: 100%;
110+
font-family: 'Courier New', Courier, monospace;
111+
font-size: 16px;
112+
text-shadow: 1px 1px 2px #000000;
110113
}

examples/text-editor/ui/index.html

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8" />
5+
<script src="/webui.js"></script>
6+
7+
<link rel="icon" type="image/png" href="img/icon.png" />
8+
<title>Text Editor in C using WebUI</title>
9+
<link rel="stylesheet" href="css/style.css" />
10+
<link rel="stylesheet" href="css/lucario.css" />
11+
<link rel="stylesheet" href="css/codemirror.min.css" />
12+
<link rel="stylesheet" href="css/all.min.css" />
13+
</head>
14+
<body>
15+
<div class="topbar"></div>
16+
<nav>
17+
<button id="open-btn" title="Open file" type="button"><i class="fas fa-folder-open"></i></button>
18+
<button id="save-btn" title="Save file" type="button" disabled><i class="fa fa-floppy-disk"></i></button>
19+
<button id="__close-btn" title="Close file" type="button"><i class="fas fa-circle-xmark"></i></button>
20+
<button id="about-btn" title="About Info" type="button"><i class="fas fa-question-circle"></i></button>
21+
</nav>
22+
<div class="main" id="main">
23+
<textarea id="editor"></textarea>
24+
</div>
25+
<div id="about-box" class="about-box">
26+
<div class="about-box-content">
27+
<h1>WebUI Text Editor</h1>
28+
v1.1
29+
<p>Example of a text editor software in C using WebUI library.</p>
30+
<p><a href="https://webui.me" target="_blank">webui.me</a> | (C)2023 Hassan Draga</p>
31+
</div>
32+
</div>
33+
<script src="js/codemirror.min.js"></script>
34+
<script src="js/xml.min.js"></script>
35+
<script src="js/css.min.js"></script>
36+
<script src="js/javascript.min.js"></script>
37+
<script src="js/clike.min.js"></script>
38+
<script src="js/python.min.js"></script>
39+
<script src="js/ui.js"></script>
40+
</body>
41+
</html>

0 commit comments

Comments
 (0)