-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.py
50 lines (38 loc) · 929 Bytes
/
gui.py
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
import json
import eel
from db.ejdic import found_word
LIMIT = 10
def words_means(word):
out = []
for i in range(4):
out.extend(list(found_word(word, i)))
if len(out) > LIMIT + 20:
break
return out
def results(word):
count = 0
text_list = set()
out = words_means(word)
for text, mean in out:
if text not in text_list:
yield text, mean
count += 1
text_list.add(text)
if count > LIMIT + 1:
break
@eel.expose
def get_candidates(word):
result = [
{"word": word, "candidate": text, "translate": mean}
for text, mean in results(word)
]
return json.dumps(result)
def start_gui():
app_options = {
"mode": "chrome",
"port": 18085,
}
eel.init("front/dist")
eel.start("index.html", **app_options)
if __name__ == "__main__":
start_gui()