forked from hooniverse/SelfFitnessManager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Interface.py
219 lines (171 loc) · 9.44 KB
/
Interface.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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import PySimpleGUI as sg
import datetime
import os
from graph import day_count
from graph import test_day_show
class Interface:
sg.theme('DarkAmber')
def main_page(self):
layout = [
[sg.Graph((250, 280), (0, 0), (250, 280), key='logo')],
[sg.Text('모드선택', font=("Arial Bold", 10, "bold")), sg.Radio('트레이닝', key="training", group_id=1),
sg.Radio('테스트', key="test", group_id=1)],
[sg.Column(layout=[[sg.Button('기록보기')]], justification='center'), sg.Text('', size=(5, 1)),
sg.Button('확인')],
]
window = sg.Window('모드 선택', layout, finalize=True)
window['logo'].draw_image(filename='logo1.png', location=(6.5, 270))
return window
def training_page(self):
layout = [[sg.Text('운동 종목 선택'),
sg.Listbox(['Push-Up', 'Pull-Up', 'Squat'], no_scrollbar=True, s=(15, 3), key='type')],
[sg.Text('세트 개수(자연수 입력)'), sg.Input(s=15, key='set')],
[sg.Text('세트 당 개수(자연수 입력)'), sg.Input(s=15, key='reps_per_set')],
[sg.Text('쉬는 시간(초 단위 입력)'), sg.Input(s=15, key='break_time')],
[sg.Column(layout=[[sg.Button('이전으로')]], justification='center'), sg.Text('', size=(7, 1)),
sg.Button('확인')],
]
return sg.Window('training_page', layout)
def test_page(self):
layout = [[sg.Text('테스트 종목 선택'),
sg.Listbox(['Push-Up', 'Pull-Up', 'Squat'], no_scrollbar=True, s=(15, 3), key='type')],
[sg.Text('목표 시간(초 단위 입력)'), sg.Input(s=15, key='goal_time')],
[sg.Text('목표 개수(자연수 입력)'), sg.Input(s=15, key='goal_number')],
[sg.Column(layout=[[sg.Button('이전으로')]], justification='center'), sg.Text('', size=(7, 1)),
sg.Button('확인')],
]
return sg.Window('test_page', layout)
def report_choose_page(self):
layout = [[sg.Button("트레이닝 기록 보기"), sg.Button("테스트 기록 보기")],
[sg.Column(layout=[[sg.Button('이전으로')]], justification='right')],
]
return sg.Window('report_choose_page', layout)
def training_report_page(self):
layout = [[sg.Text("날짜를 선택하세요:"), sg.InputText(key="date", size=(20, 2), enable_events=True),
sg.CalendarButton("날짜 선택", target="date", format="%Y-%m-%d")],
[sg.Image(key='output')],
[sg.Column(layout=[[sg.Button('이전으로')]], justification='right')],
]
return sg.Window('training_report_page', size=(600, 600)).Layout(layout)
def test_report_page(self):
layout = [[sg.Text("날짜를 선택하세요:"), sg.InputText(key="date", size=(20, 2), enable_events=True),
sg.CalendarButton("날짜 선택", target="date", format="%Y-%m-%d")],
[sg.Image(key='output_test')],
[sg.Column(layout=[[sg.Button('이전으로')]], justification='right')],
]
return sg.Window('test_report_page', size=(1800, 500), location=(0, 0)).Layout(layout)
def run(self):
user_input = {}
window = self.main_page()
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == 'Cancel':
break
elif event == '확인':
if values['training']:
user_input['mode'] = 'training'
window.close()
window = self.training_page()
event, values = window.read()
if event == '확인':
user_input['type'] = values['type']
user_input['set_count'] = values['set']
user_input['reps_per_set'] = values['reps_per_set']
user_input['break_time'] = values['break_time']
window.close()
elif event == '이전으로':
window.close()
window = self.main_page()
event, values = window.read()
elif values['test']:
user_input['mode'] = 'test'
window.close()
window = self.test_page()
event, values = window.read()
if event == '확인':
user_input['type'] = values['type']
user_input['goal_time'] = values['goal_time']
user_input['goal_number'] = values['goal_number']
window.close()
elif event == '이전으로':
window.close()
window = self.main_page()
event, values = window.read()
elif event == '기록보기':
window.close()
window = self.report_choose_page()
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == 'Cancel':
break
if event == '트레이닝 기록 보기':
window.close()
window = self.training_report_page()
event, values = window.read()
while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
if event == '이전으로':
window.close()
window = self.report_choose_page()
event, values = window.read()
break
elif event == "date":
selected_date_str = values["date"]
try:
selected_date = datetime.datetime.strptime(selected_date_str, "%Y-%m-%d").date()
day_count.plot_exercise_counts("exercise_record.csv", selected_date)
path = f"graph_pictures\{selected_date}_exercise_count.png"
if os.path.exists(path):
window["output"].update(filename=path)
else:
# 대체할 경로 또는 이미지 설정
alternative_path = "do_not_exercise.png"
window["output"].update(filename=alternative_path)
except ValueError:
sg.popup_error("올바르지 않은 날짜 형식입니다. 날짜를 다시 입력하세요.")
elif event == '테스트 기록 보기':
window.close()
window = self.test_report_page()
event, values = window.read()
while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
if event == '이전으로':
window.close()
window = self.report_choose_page()
event, values = window.read()
break
elif event == "date":
selected_date_str = values["date"]
try:
selected_date = datetime.datetime.strptime(selected_date_str, "%Y-%m-%d").date()
# day_count.plot_exercise_counts("exercise_record.csv", selected_date)
test_day_show.merge_images(selected_date)
path = f"graph_pictures\\test_graph\\{selected_date}_Merged_Image.png"
if os.path.exists(path):
window["output_test"].update(filename=path)
else:
# 대체할 경로 또는 이미지 설정
alternative_path = "do_not_exercise.png"
window["output_test"].update(filename=alternative_path)
except ValueError:
sg.popup_error("올바르지 않은 날짜 형식입니다. 날짜를 다시 입력하세요.")
elif event == '이전으로':
window.close()
window = self.main_page()
event, values = window()
break
window.close()
return user_input
def end(self):
layout = [[sg.Text("운동이 종료되었습니다.", font=("Arial Bold", 13, "bold"))],
]
window = sg.Window('end_page', layout)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
window.close()