1 | import tkinter as tk
|
---|
2 | import tkinter.ttk as ttk
|
---|
3 | from tkinter import filedialog
|
---|
4 | from Schedule import Schedule
|
---|
5 | from Phase import Phase
|
---|
6 | from PIL import Image, ImageTk
|
---|
7 | from copy import copy
|
---|
8 | import pandas as pd
|
---|
9 | import os
|
---|
10 | import math
|
---|
11 | import datetime
|
---|
12 |
|
---|
13 | now = datetime.datetime.now()
|
---|
14 | date = now.strftime("%m/%d/%Y")
|
---|
15 | time = now.strftime("%H:%M:%S")
|
---|
16 |
|
---|
17 |
|
---|
18 | class TimerApp(tk.Frame):
|
---|
19 |
|
---|
20 | def __init__(self, parent):
|
---|
21 |
|
---|
22 | super().__init__(parent)
|
---|
23 | self.parent = parent
|
---|
24 | self.count = 0
|
---|
25 | self.currentValue = 0
|
---|
26 | self.show_config = pd.read_csv("default_config.csv", usecols=[0, 1])
|
---|
27 |
|
---|
28 | self.photo = ImageTk.PhotoImage(file='flowtimer_startbg_new.png')
|
---|
29 |
|
---|
30 | self.build_gui()
|
---|
31 |
|
---|
32 |
|
---|
33 | def build_gui(self):
|
---|
34 |
|
---|
35 | s = ttk.Style()
|
---|
36 | s.theme_use('clam')
|
---|
37 | s.configure("orange.Horizontal.TProgressbar", troughcolor='grey69', bordercolor='black', background='DarkOrange1', lightcolor='white', darkcolor='black')
|
---|
38 |
|
---|
39 | self.headline_frame = tk.Frame(self.parent, bg='white')
|
---|
40 | self.headline_frame.pack(side='top', fill='both', expand=False)
|
---|
41 | self.center_frame = tk.Frame(self.parent, bg='black')
|
---|
42 | self.center_frame.pack(side='top', fill='both', expand=True)
|
---|
43 | self.button_frame = tk.Frame(root)
|
---|
44 | self.button_frame.pack(side='bottom', fill='both', expand=False)
|
---|
45 |
|
---|
46 | self.label_headline = tk.Label(self.headline_frame, text=("Hochintensive Intervallarbeit"), bg='white', fg='grey', font="serif 20")
|
---|
47 | self.label_headline.pack(side='left', fill='both', expand=True)
|
---|
48 |
|
---|
49 | self.label_config = tk.LabelFrame(self.headline_frame, text="config: ", bg='white', font="serif 12")
|
---|
50 | self.label_config.pack(side='right', fill='both', expand=False, ipadx=20, padx=20, pady=10)
|
---|
51 |
|
---|
52 | self.label_config_text = tk.Label(self.label_config, text=self.show_config, bg='white', font="serif 10", justify='right')
|
---|
53 | self.label_config_text.pack()
|
---|
54 |
|
---|
55 | self.label_start = tk.Label(self.center_frame, image=self.photo, bg='black')
|
---|
56 | self.label_start.pack(side='left', fill='both', expand=True)
|
---|
57 |
|
---|
58 | self.label_sequence = tk.Label(self.center_frame)
|
---|
59 | self.label_sequence.pack(side='top', fill='both', expand=True)
|
---|
60 |
|
---|
61 | self.label_duration = tk.Label(self.center_frame)
|
---|
62 | self.label_duration.pack(side='top', fill='both', expand=True)
|
---|
63 |
|
---|
64 | self.progressbar = ttk.Progressbar(self.headline_frame, style="orange.Horizontal.TProgressbar", orient="horizontal",length=600, mode="determinate")
|
---|
65 | self.progressbar.pack(side='left')
|
---|
66 |
|
---|
67 | self.start_timer_button = tk.Button(self.button_frame, text="START", font="courier 14", width=20, command=self.start)
|
---|
68 | self.start_timer_button.pack(side='left', fill='both', ipady=20, expand=True)
|
---|
69 |
|
---|
70 | self.freeze_button = tk.Button(self.button_frame, text="PLAY/PAUSE", font="courier 14", width=20, command=self.toggle_tick)
|
---|
71 | self.freeze_button.pack(side='left', fill='both', ipady=20, expand=True)
|
---|
72 |
|
---|
73 | self.skip_button = tk.Button(self.button_frame, text="SKIP", font="courier 14", width=20, command=self.skip)
|
---|
74 | self.skip_button.pack(side='left', fill='both', ipady=20, expand=True)
|
---|
75 |
|
---|
76 | self.quit_button = tk.Button(self.button_frame, text="QUIT", font="courier 14", width=20, command=self.quit_app)
|
---|
77 | self.quit_button.pack(side='left', fill='both', ipady=20, expand=True)
|
---|
78 |
|
---|
79 | self.config_files = [("all files", "*.csv")]
|
---|
80 | self.answer = filedialog.askopenfilename(parent=root,
|
---|
81 | initialdir=os.chdir("./configs"),
|
---|
82 | title="Please choose a config file:",
|
---|
83 | filetypes=self.config_files)
|
---|
84 |
|
---|
85 | df = pd.read_csv(self.answer, sep=',', header=0,
|
---|
86 | names=('Titel', 'Values'), index_col=False, keep_default_na=False)
|
---|
87 |
|
---|
88 | self.show_config = pd.read_csv(self.answer, usecols=[0, 1])
|
---|
89 |
|
---|
90 | self.label_config_text.pack_forget()
|
---|
91 | self.label_config_text = tk.Label(self.label_config, text=self.show_config, bg='white', font="serif 10", justify='right')
|
---|
92 | self.label_config_text.pack()
|
---|
93 |
|
---|
94 | repeat_of_phases = df['Values'][3]
|
---|
95 |
|
---|
96 | phase_1 = Phase(title=df['Titel'][0], duration=df['Values'][0])
|
---|
97 | phase_2 = Phase(title=df['Titel'][1], duration=df['Values'][1])
|
---|
98 | phase_3 = Phase(title=df['Titel'][2], duration=df['Values'][2])
|
---|
99 |
|
---|
100 | if repeat_of_phases == 1:
|
---|
101 | phase_list = [phase_1, phase_2, phase_3]
|
---|
102 |
|
---|
103 | if repeat_of_phases == 2:
|
---|
104 | phase_list = [phase_1, phase_2, phase_3, copy(phase_2), copy(phase_3)]
|
---|
105 |
|
---|
106 | if repeat_of_phases == 3:
|
---|
107 | phase_list = [phase_1, phase_2, phase_3, copy(phase_2), copy(phase_3), copy(phase_2), copy(phase_3)]
|
---|
108 |
|
---|
109 | if repeat_of_phases == 4:
|
---|
110 | phase_list = [phase_1, phase_2, phase_3, copy(phase_2), copy(phase_3), copy(phase_2), copy(phase_3),
|
---|
111 | copy(phase_2), copy(phase_3)]
|
---|
112 |
|
---|
113 | if repeat_of_phases == 5:
|
---|
114 | phase_list = [phase_1, phase_2, phase_3, copy(phase_2), copy(phase_3), copy(phase_2), copy(phase_3),
|
---|
115 | copy(phase_2), copy(phase_3), copy(phase_2), copy(phase_3)]
|
---|
116 |
|
---|
117 | self.repeats = repeat_of_phases
|
---|
118 |
|
---|
119 | self.schedule = Schedule(phase_list)
|
---|
120 |
|
---|
121 | def tick(self):
|
---|
122 |
|
---|
123 | if self.schedule.is_paused():
|
---|
124 | return
|
---|
125 | self.label_start.pack_forget()
|
---|
126 | current_process = self.after(1000, self.tick)
|
---|
127 | self.currentValue = self.currentValue + 1
|
---|
128 |
|
---|
129 | if self.schedule.state == 'initial':
|
---|
130 | self.label_sequence.config(self.start_color(root))
|
---|
131 | self.label_sequence.config(text=("\n" + str(self.schedule.current_phase.title) + "..."))
|
---|
132 | self.label_duration.config(self.start_color(root))
|
---|
133 | self.label_duration.config(text=("noch " + str(math.ceil(self.schedule.current_phase.time_left)) + " Min\n"))
|
---|
134 | self.schedule.start()
|
---|
135 | self.schedule.tick(1)
|
---|
136 | else:
|
---|
137 | if self.schedule.running():
|
---|
138 | self.progress(self.currentValue)
|
---|
139 | self.progressbar.update()
|
---|
140 | # print(current_process)
|
---|
141 | self.label_sequence.configure(self.start_color(root))
|
---|
142 | self.label_sequence.config(text=("\n" + str(self.schedule.current_phase.title) + "..."), bg=self.random_color(self.label_sequence))
|
---|
143 | self.label_duration.config(self.random_color(root))
|
---|
144 | self.label_duration.config(text=("noch " + str(math.ceil(self.schedule.current_phase.time_left)) + " Min\n"), bg=self.random_color(self.label_duration))
|
---|
145 | if self.schedule.tick(1/60):
|
---|
146 | self.count += 1
|
---|
147 | if self.count < 3:
|
---|
148 | self.currentValue = 0
|
---|
149 | self.progress(self.currentValue +1)
|
---|
150 | self.progressbar.update()
|
---|
151 | self.label_config.config(text="Runde: ")
|
---|
152 | self.label_config_text.config(text=("1", "/", self.repeats), fg='blue',font="Times 26")
|
---|
153 | if self.count >= 3 and self.count < 5:
|
---|
154 | self.label_config_text.config(text=("2", "/", str(self.repeats)), fg='blue',font="Times 26")
|
---|
155 | if self.count >= 5 and self.count < 7:
|
---|
156 | self.label_config_text.config(text=("3", "/", self.repeats), fg='blue',font="Times 26")
|
---|
157 | if self.count >= 7 and self.count < 9:
|
---|
158 | self.label_config_text.config(text=("4", "/", self.repeats), fg='blue',font="Times 26")
|
---|
159 |
|
---|
160 | else:
|
---|
161 | self.label_sequence.configure(self.time_out_color(root))
|
---|
162 | self.label_sequence.config(text=("\n" + "\nTime over !"), bg="red")
|
---|
163 | self.label_duration.config(text="", bg="red")
|
---|
164 | self.progressbar.pack_forget()
|
---|
165 | self.after_cancel(current_process)
|
---|
166 |
|
---|
167 | def start(self):
|
---|
168 | self.schedule.start()
|
---|
169 | self.tick()
|
---|
170 |
|
---|
171 | def skip(self):
|
---|
172 | self.schedule.skip()
|
---|
173 | self.currentValue = 0
|
---|
174 |
|
---|
175 | def toggle_tick(self):
|
---|
176 | if self.schedule.is_paused():
|
---|
177 | self.freeze_button.config(relief="raised")
|
---|
178 | self.label_sequence.config(fg="white")
|
---|
179 | self.label_duration.config(fg="white")
|
---|
180 | self.schedule.start()
|
---|
181 | self.tick()
|
---|
182 | else:
|
---|
183 | self.schedule.pause()
|
---|
184 | self.freeze_button.config(relief="sunken")
|
---|
185 | self.label_sequence.config(text=("\n" + "\n! timer paused !"), fg="red", bg="black")
|
---|
186 | self.label_duration.config(text="", bg="black")
|
---|
187 |
|
---|
188 | def quit_app(self):
|
---|
189 | self.parent.destroy()
|
---|
190 |
|
---|
191 | def random_color(self, widget):
|
---|
192 | if self.schedule.current_phase.title == "B-Phase":
|
---|
193 | widget.configure(bg="blue")
|
---|
194 | if self.schedule.current_phase.title == "I-Phase":
|
---|
195 | widget.configure(bg="green")
|
---|
196 | if self.schedule.current_phase.title == "S-Phase":
|
---|
197 | widget.configure(bg="gold")
|
---|
198 |
|
---|
199 |
|
---|
200 | def start_color(self, widget):
|
---|
201 | self.label_sequence.configure(bg="blue", fg="white", font="times 72")
|
---|
202 | self.label_duration.configure(bg="blue", fg="white", font="times 72")
|
---|
203 | widget.configure(bg="blue")
|
---|
204 |
|
---|
205 | def time_out_color(self, widget):
|
---|
206 | widget.configure(bg="red")
|
---|
207 |
|
---|
208 | def progress(self, currentValue):
|
---|
209 | self.progressbar["value"] = self.currentValue
|
---|
210 | self.progressbar["maximum"] = 60
|
---|
211 | if self.currentValue == 60:
|
---|
212 | self.currentValue = 0
|
---|
213 |
|
---|
214 | root = tk.Tk()
|
---|
215 |
|
---|
216 |
|
---|
217 | root.title("--=> flowtimer <=-- " + " date: " + date + " time: " + time)
|
---|
218 | root.geometry("1280x870")
|
---|
219 | root.config(bg='black')
|
---|
220 | root.iconphoto(False, ImageTk.PhotoImage(Image.open('icon_bombtimer.png')))
|
---|
221 |
|
---|
222 | app = TimerApp(root)
|
---|
223 |
|
---|
224 | app.mainloop() |
---|