-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_scheme.py
62 lines (46 loc) · 1.53 KB
/
add_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
61
62
from functions import *
def save_scheme(flashcard_id: int, filename: str):
"""
## `save_scheme` method
===============================================
#### Description
It saves the scheme.
"""
exit_message = "EXIT_SUCCESS"
if exists_filename(filename):
cursor.execute(
"UPDATE flashcards SET filename_scheme=? WHERE id=?",
(filename, flashcard_id),
)
con.commit()
else:
sg.popup_error("Path Wrong", keep_on_top=True, modal=True)
exit_message = "PATH_WRONG"
return exit_message
def update_scheme(flashcard_id: int) -> (str, str):
layout = [
[sg.Text("Please, select a file", size=(20, 1))],
[
sg.InputText(key="filename_scheme"),
sg.FileBrowse(file_types=(("Image Portable Network Graphics", "*.png"),)),
],
[sg.Column([[sg.Button("Save", key="save_scheme")]], justification="right")],
]
window = sg.Window(
layout=layout, title="File selector", keep_on_top=True, modal=True
)
filename: str = ""
exit_message = "EXIT_SUCCESS"
while True:
event, values = window.read()
if event in [sg.WIN_CLOSED, "Exit"]:
filename = ""
exit_message = "EXIT_WINDOW"
break
if event == "save_scheme":
if "EXIT_SUCCESS" == save_scheme(
flashcard_id=flashcard_id, filename=values["filename_scheme"]
):
break
window.close()
return filename, exit_message