-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathqxexample.nim
46 lines (36 loc) · 981 Bytes
/
qxexample.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import std/strutils
import std/os
import webui
const
html = """
<!DOCTYPE html>
<html>
<head></head>
<body>
<script>
function loadData() {
fetch("index.html").then(response => response.text()).then(content => {
document.open("text/html");
document.write(content);
document.close();
console.log(content);
}).catch(error => {
console.error(error);
});
}
window.onload = loadData;
</script>
</body>
</html>
"""
var counter: int
proc main() =
let window = newWindow()
window.bind("Button1Click") do (e: Event) -> string:
echo "Received callback: ", e.getString()
inc counter
return """{"label1": "Message from Nim", "label2": "$1"}""" % $counter
window.rootFolder = currentSourcePath().parentDir()
window.show(html)
wait()
main()