-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello.html
100 lines (93 loc) · 3.83 KB
/
hello.html
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<!DOCTYPE html>
<html>
<head>
<style>
.styled {
border: 0;
line-height: 2.5;
padding: 0 20px;
font-size: 1rem;
text-align: center;
border-radius: 10px;
box-shadow: inset 1px 1px 2px rgba(255, 255, 255, .6),
inset -1px -1px 2px rgba(0, 0, 0, .6);
}
.red-styled {
color: #fff;
background-color: rgba(220, 0, 0, 1);
}
.blue-styled {
color: #fff;
background-color: rgba(0, 0, 220, 1);
}
.red-styled:hover {
background-color: rgba(255, 0, 0, 1);
}
.blue-styled:hover {
background-color: rgba(0, 0, 255, 1);
}
.styled:active {
box-shadow: inset -1px -1px 2px rgba(255, 255, 255, .6),
inset 1px 1px 2px rgba(0, 0, 0, .6);
}
.styled:focus {
outline: 0;
}
</style>
<script type="text/javascript" src="/eel.js"></script>
<script type="text/javascript">
function switchStyledColor() {
// Example: Change class with JavaScript (botton color switches between red and blue)
let styledElements = document.getElementsByClassName("styled");
// ref: https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName
for (var i=0, len=styledElements.length|0; i<len; i=i+1|0) {
if (styledElements[i].classList.contains("red-styled")) {
styledElements[i].classList.remove("red-styled");
styledElements[i].classList.add("blue-styled");
}
else if (styledElements[i].classList.contains("blue-styled")) {
styledElements[i].classList.remove("blue-styled");
styledElements[i].classList.add("red-styled");
}
}
}
function print_greeting(message) {
switchStyledColor();
let greeting = document.getElementById("greeting");
greeting.innerHTML = message;
}
function greeting() {
// See attributes: say_hello, Helloest, Helloer_say_instance_method, Helloer_say_class_method, Helloer_say_static_method, Helloer.another_say_static_method
console.log(eel);
// console.log(eel.Helloest.say()); // raises `Uncaught TypeError: eel.Helloest.say is not a function` in JavaScript
// eel.Helloest()(print_greeting); // No error but message of print_greeting is null (not Python class object)
// pass some value as self/cls parameter to prevent `TypeError: say_instance() missing 1 required positional argument: 'self'` in Python
// But it causes another error `AttributeError: 'dict' object has no attribute 'name'` in Python
// Maps and class instances seem to be passed as Python's dict
/*
let Hoge = class {
constructor(name) {
this.name = name;
}
};
console.log(eel.Helloer_say_instance_method(new Hoge("hoge")));
console.log(eel.Helloer_say_class_method({class_var: "foo"}));
*/
console.log(eel.Helloer_say_static_method()); // staticmethod does not need self or cls parameter
// if you expose the function as the name include period, specify like Python's dict
// console.log(eel.Helloer.another_say_static_method()); // raises `Uncaught TypeError: Cannot read property 'another_say_static_method' of undefined` in JavaScript
eel["Helloer.another_say_static_method"]()(print_greeting);
}
// Another way to receive return values: await
// async function greeting() {
// let greeting = document.getElementById("greeting");
// let message = await eel.say_hello()();
// greeting.innerHTML = message;
// }
</script>
</head>
<body>
<button type="button" onclick="greeting()" class="styled red-styled">Greet</button>
<p id="greeting"></p>
</body>
</html>