-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoday_study.py
More file actions
118 lines (99 loc) · 4.06 KB
/
Copy pathtoday_study.py
File metadata and controls
118 lines (99 loc) · 4.06 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
from functions import *
from view_scheme import view_scheme
def today_study_flashcards() -> str:
state = "OK"
frontText: list = copy.copy(get_flashcards_array()[0][1])
backText: list = copy.copy(get_flashcards_array()[0][2])
set_front_layout(from_text_to_elements(frontText))
set_back_layout(from_text_to_elements(backText))
layout = [
[
sg.Text("Front: "),
sg.Column(
layout=get_front_layout(),
key="front_layout",
scrollable=True,
vertical_scroll_only=True,
expand_x=True,
expand_y=True,
size=(None, 150),
justification="center",
),
],
[sg.Input(key="back_try_input")],
[
sg.Text("Your try: ", visible=False, key="display_text_back_try_input"),
sg.Text(key="text_back_try_input", visible=False),
],
[
sg.Text("Solution: ", visible=False, key="display_text_solution"),
sg.Column(
layout=get_back_layout(),
key="back_layout",
visible=False,
scrollable=True,
vertical_scroll_only=True,
expand_x=True,
expand_y=True,
size=(None, 150),
justification="center",
),
],
[sg.HorizontalSeparator()],
[
sg.Button("No", key="back_zero", visible=False),
sg.Button("Yes", key="advance_box", visible=False),
sg.Button("Scheme", key="see_scheme", visible=False, button_color="Orange"),
],
[sg.Button("Back", key="EVENT_BACK_study_layout")],
[sg.Button("Solution", key="see_solution", button_color="Green")],
[sg.Button("Home", key="EVENT_HOME_Today")],
]
window = sg.Window(
"Flashcard", layout=layout, finalize=True, keep_on_top=True, modal=True
)
window["back_try_input"].bind("<Return>", "_Enter")
while True:
event, values = window.read()
if event in (sg.WIN_CLOSED, "Exit"):
state = "EXIT"
break
if event is not None:
if event == "see_scheme":
flashcard_id = get_flashcards_array()[0][0]
view_scheme(flashcard_id)
if event in ["back_try_input_Enter", "see_solution"]:
window["back_try_input"].update(visible=False)
window["display_text_back_try_input"].update(visible=True)
window["display_text_solution"].update(visible=True)
window["text_back_try_input"].update(visible=True)
window["text_back_try_input"].update(value=values["back_try_input"])
window["back_layout"].update(visible=True)
window["back_zero"].update(visible=True)
window["advance_box"].update(visible=True)
window["see_scheme"].update(visible=True)
if event in ["back_zero", "advance_box"]:
flashcard_id = get_flashcards_array()[0][0]
new_box = 0
deadline_str = datetime.now().strftime("%Y-%m-%d")
if event == "advance_box":
deadline_str = (
datetime.now()
+ timedelta(days=pow(2, get_flashcards_array()[0][3]))
).strftime("%Y-%m-%d")
new_box = get_flashcards_array()[0][3] + 1
remove_flashcard(0)
else:
retry = get_flashcards_array()[0]
remove_flashcard(0)
append_flashcard(retry)
# I update new_box after the determination of deadline because
# the second rep is after 1 day not after 2 days.
cursor.execute(
"UPDATE flashcards SET deadline=?, box=? WHERE id=?",
(deadline_str, new_box, flashcard_id),
)
con.commit()
break
window.close()
return state