-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview_scheme.py
60 lines (45 loc) · 1.83 KB
/
view_scheme.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
51
52
53
54
55
56
57
58
59
60
from functions import *
from add_scheme import update_scheme
def view_scheme(flashcard_id: int):
if flashcard_id is not None:
cursor.execute(
"SELECT filename_scheme FROM flashcards WHERE id=?", (flashcard_id,)
)
filename = cursor.fetchone()[0]
img = None
cond_window_visible = True
if exists_filename(filename):
img = convert_to_bytes(filename, (800, 500))
while not exists_img(img):
filename, result = update_scheme(flashcard_id=flashcard_id)
if result == "EXIT_WINDOW":
cond_window_visible = False
break
if exists_filename(filename):
img = convert_to_bytes(filename, (800, 500))
if cond_window_visible:
layout = [
[sg.Image(data=img, key="img_scheme", size=(800, 500))],
[sg.HorizontalSeparator()],
[sg.Button("Change scheme", key="change_scheme")],
]
window = sg.Window(
"Popup Scheme",
layout=layout,
keep_on_top=True,
finalize=True,
modal=True,
)
while True:
event, values = window.read()
if event in (sg.WIN_CLOSED, "Exit"):
break
if event is not None:
if event == "change_scheme":
filename = update_scheme(flashcard_id=flashcard_id)
if exists_filename(filename):
img = convert_to_bytes(filename, (800, 500))
window["img_scheme"].update(data=img)
else:
sg.popup_error("Path wrong!", keep_on_top=True, modal=True)
window.close()