[99dee0f] | 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.default_config = pd.read_csv("default_config.csv", sep=',', header=0,
|
---|
| 27 | names=('Titel', 'Values'), index_col=False, keep_default_na=False)
|
---|
| 28 | self.photo = ImageTk.PhotoImage(file='flowtimer_startbg_new.png')
|
---|
| 29 | self.show_config = pd.read_csv("default_config.csv", usecols=[0, 1])
|
---|
| 30 | self.config_state = 'default'
|
---|
| 31 |
|
---|
| 32 | self.build_gui()
|
---|
| 33 |
|
---|
| 34 | def build_gui(self):
|
---|
| 35 |
|
---|
| 36 | s = ttk.Style()
|
---|
| 37 | s.theme_use('clam')
|
---|
| 38 | s.configure("orange.Horizontal.TProgressbar", troughcolor='ivory3', bordercolor='black', background='CadetBlue1', lightcolor='white', darkcolor='black')
|
---|
| 39 |
|
---|
| 40 | self.headline_frame = tk.Frame(self.parent, bg='white')
|
---|
| 41 | self.headline_frame.pack(side='top', fill='both', expand=False)
|
---|
| 42 | self.center_frame = tk.Frame(self.parent, bg='black')
|
---|
| 43 | self.center_frame.pack(side='top', fill='both', expand=True)
|
---|
| 44 | self.button_frame = tk.Frame(root)
|
---|
| 45 | self.button_frame.pack(side='bottom', fill='both', expand=False)
|
---|
| 46 |
|
---|
| 47 | self.label_headline = tk.Label(self.headline_frame, text=("Hochintensive Intervallarbeit"), bg='white', fg='grey', font="serif 20")
|
---|
| 48 | self.label_headline.pack(side='left', fill='both', expand=True)
|
---|
| 49 |
|
---|
| 50 | self.label_config = tk.LabelFrame(self.headline_frame, text="config: ", bg='white', font="serif 12")
|
---|
| 51 | self.label_config.pack(side='right', fill='both', expand=False, ipadx=20, padx=20, pady=10)
|
---|
| 52 |
|
---|
| 53 | self.config_button = tk.Button(self.headline_frame, text="change config", font="courier 14", width=20, command=self.change_config)
|
---|
| 54 | self.config_button.pack(side='right', padx=10, pady=10, expand=False)
|
---|
| 55 |
|
---|
| 56 | self.label_config_text = tk.Label(self.label_config, text=self.show_config, bg='white', font="serif 10", justify='right')
|
---|
| 57 | self.label_config_text.pack()
|
---|
| 58 |
|
---|
| 59 | self.label_start = tk.Label(self.center_frame, image=self.photo, bg='black')
|
---|
| 60 | self.label_start.pack(side='left', fill='both', expand=True)
|
---|
| 61 |
|
---|
| 62 | self.label_sequence = tk.Label(self.center_frame)
|
---|
| 63 | self.label_sequence.pack(side='top', fill='both', expand=True)
|
---|
| 64 |
|
---|
| 65 | self.progressbar = ttk.Progressbar(self.center_frame, style="orange.Horizontal.TProgressbar", orient="horizontal",length=600, mode="determinate")
|
---|
| 66 | self.progressbar.pack(side='top')
|
---|
| 67 |
|
---|
| 68 | self.label_duration = tk.Label(self.center_frame)
|
---|
| 69 | self.label_duration.pack(side='top', fill='both', expand=True)
|
---|
| 70 |
|
---|
| 71 | self.start_timer_button = tk.Button(self.button_frame, text="START", font="courier 14", width=20, command=self.start)
|
---|
| 72 | self.start_timer_button.pack(side='left', fill='both', ipady=20, expand=True)
|
---|
| 73 |
|
---|
| 74 | self.freeze_button = tk.Button(self.button_frame, text="PLAY/PAUSE", font="courier 14", width=20, command=self.toggle_tick)
|
---|
| 75 | self.freeze_button.pack(side='left', fill='both', ipady=20, expand=True)
|
---|
| 76 |
|
---|
| 77 | self.skip_button = tk.Button(self.button_frame, text=("SKIP"), font="courier 14", width=20, command=self.skip)
|
---|
| 78 | self.skip_button.pack(side='left', fill='both', ipady=20, expand=True)
|
---|
| 79 |
|
---|
| 80 | self.quit_button = tk.Button(self.button_frame, text="QUIT", font="courier 14", width=20, command=self.quit_app)
|
---|
| 81 | self.quit_button.pack(side='left', fill='both', ipady=20, expand=True)
|
---|
| 82 |
|
---|
| 83 | df = self.default_config
|
---|
| 84 | repeat_of_phases = df['Values'][3]
|
---|
| 85 |
|
---|
| 86 | phase_1 = Phase(title=df['Titel'][0], duration=df['Values'][0])
|
---|
| 87 | phase_2 = Phase(title=df['Titel'][1], duration=df['Values'][1])
|
---|
| 88 | phase_3 = Phase(title=df['Titel'][2], duration=df['Values'][2])
|
---|
| 89 |
|
---|
| 90 | if repeat_of_phases == 1:
|
---|
| 91 | phase_list = [phase_1, phase_2, phase_3]
|
---|
| 92 |
|
---|
| 93 | if repeat_of_phases == 2:
|
---|
| 94 | phase_list = [phase_1, phase_2, phase_3, copy(phase_2), copy(phase_3)]
|
---|
| 95 |
|
---|
| 96 | if repeat_of_phases == 3:
|
---|
| 97 | phase_list = [phase_1, phase_2, phase_3, copy(phase_2), copy(phase_3), copy(phase_2), copy(phase_3)]
|
---|
| 98 |
|
---|
| 99 | if repeat_of_phases == 4:
|
---|
| 100 | phase_list = [phase_1, phase_2, phase_3, copy(phase_2), copy(phase_3), copy(phase_2), copy(phase_3),
|
---|
| 101 | copy(phase_2), copy(phase_3)]
|
---|
| 102 |
|
---|
| 103 | if repeat_of_phases == 5:
|
---|
| 104 | phase_list = [phase_1, phase_2, phase_3, copy(phase_2), copy(phase_3), copy(phase_2), copy(phase_3),
|
---|
| 105 | copy(phase_2), copy(phase_3), copy(phase_2), copy(phase_3)]
|
---|
| 106 |
|
---|
| 107 | self.repeats = repeat_of_phases
|
---|
| 108 |
|
---|
| 109 | self.schedule = Schedule(phase_list)
|
---|
| 110 |
|
---|
| 111 | def tick(self):
|
---|
| 112 |
|
---|
| 113 | if self.schedule.is_paused():
|
---|
| 114 | return
|
---|
| 115 | self.label_start.pack_forget()
|
---|
| 116 | current_process = self.after(1000, self.tick)
|
---|
| 117 | self.currentValue = self.currentValue + 1
|
---|
| 118 |
|
---|
| 119 | if self.schedule.state == 'initial':
|
---|
| 120 | self.label_sequence.config(self.start_color(root))
|
---|
| 121 | self.label_sequence.config(text=("\n" + str(self.schedule.current_phase.title) + "..."))
|
---|
| 122 | self.label_duration.config(self.start_color(root))
|
---|
| 123 | self.label_duration.config(text=("noch " + str(math.ceil(self.schedule.current_phase.time_left)) + " Min\n"))
|
---|
| 124 | self.schedule.start()
|
---|
| 125 | self.schedule.tick(1)
|
---|
| 126 | else:
|
---|
| 127 | if self.schedule.running():
|
---|
| 128 | self.progress(self.currentValue)
|
---|
| 129 | self.progressbar.update()
|
---|
| 130 | self.label_sequence.configure(self.start_color(root))
|
---|
| 131 | self.center_frame.config(bg=self.start_color(root))
|
---|
| 132 | self.label_sequence.config(bg=self.random_color(self.label_sequence))
|
---|
| 133 | self.label_duration.config(self.random_color(root))
|
---|
| 134 | self.label_duration.config(text=("noch " + str(math.ceil(self.schedule.current_phase.time_left)) + " Min\n"), bg=self.random_color(self.label_duration))
|
---|
| 135 | if self.schedule.tick(1/60):
|
---|
| 136 | self.round_counter()
|
---|
| 137 |
|
---|
| 138 | else:
|
---|
| 139 | self.label_sequence.configure(self.time_out_color(root))
|
---|
| 140 | self.label_sequence.config(text=("\n" + "\nTime over !"), bg="red", fg="white")
|
---|
| 141 | self.label_duration.config(text="", bg="red", fg="white")
|
---|
| 142 | self.progressbar.pack_forget()
|
---|
| 143 | self.center_frame.configure(bg="red")
|
---|
| 144 | self.after_cancel(current_process)
|
---|
| 145 | self.skip_button['state'] = 'disabled'
|
---|
| 146 | self.skip_button.config(fg="ivory3")
|
---|
| 147 | self.freeze_button['state'] = 'disabled'
|
---|
| 148 | self.freeze_button.config(fg="ivory3")
|
---|
| 149 |
|
---|
| 150 | def start(self):
|
---|
| 151 | self.schedule.start()
|
---|
| 152 | self.tick()
|
---|
| 153 | self.start_timer_button['state'] = 'disabled'
|
---|
| 154 | self.start_timer_button.config(fg="ivory3")
|
---|
| 155 | self.config_button.pack_forget()
|
---|
| 156 |
|
---|
| 157 | def skip(self):
|
---|
| 158 | self.schedule.skip()
|
---|
| 159 | self.currentValue = 0
|
---|
| 160 | if self.schedule.state == "running":
|
---|
| 161 | self.round_counter()
|
---|
| 162 |
|
---|
| 163 | def toggle_tick(self):
|
---|
| 164 | if self.schedule.is_paused():
|
---|
| 165 | self.freeze_button.config(relief="raised", fg='black')
|
---|
| 166 | self.label_sequence.config(fg="white")
|
---|
| 167 | self.label_duration.config(fg="white")
|
---|
| 168 | self.schedule.start()
|
---|
| 169 | self.tick()
|
---|
| 170 | else:
|
---|
| 171 | self.schedule.pause()
|
---|
| 172 | self.freeze_button.config(relief="sunken", fg="red")
|
---|
| 173 | self.label_sequence.config(text=("\n" + "\n! timer paused !"), fg="red", bg="black")
|
---|
| 174 | self.label_duration.config(text="", bg="black")
|
---|
| 175 | self.center_frame.config(bg="black")
|
---|
| 176 |
|
---|
| 177 | def quit_app(self):
|
---|
| 178 | self.parent.destroy()
|
---|
| 179 |
|
---|
| 180 | def random_color(self, widget):
|
---|
| 181 | if self.schedule.current_phase.title == "B-Phase":
|
---|
| 182 | widget.configure(bg="blue")
|
---|
| 183 | self.label_sequence.config(text=("\n" + "Besprechung"))
|
---|
| 184 | self.center_frame.configure(bg="blue")
|
---|
| 185 | if self.schedule.current_phase.title == "I-Phase":
|
---|
| 186 | widget.configure(bg="green")
|
---|
| 187 | self.label_sequence.config(text=("\n" + "Intensivphase"))
|
---|
| 188 | self.center_frame.configure(bg="green")
|
---|
| 189 | if self.schedule.current_phase.title == "S-Phase":
|
---|
| 190 | widget.configure(bg="gold")
|
---|
| 191 | self.label_sequence.config(text=("\n" + "Synchronisation"))
|
---|
| 192 | self.center_frame.configure(bg="gold")
|
---|
| 193 | self.label_sequence.configure(fg="blue")
|
---|
| 194 | self.label_duration.configure(fg="blue")
|
---|
| 195 |
|
---|
| 196 |
|
---|
| 197 | def start_color(self, widget):
|
---|
| 198 | self.label_sequence.configure(fg="white", font="times 72")
|
---|
| 199 | self.label_duration.configure(fg="white", font="times 72")
|
---|
| 200 | self.center_frame.configure(bg="blue")
|
---|
| 201 | widget.configure(bg="blue")
|
---|
| 202 |
|
---|
| 203 | def time_out_color(self, widget):
|
---|
| 204 | widget.configure(bg="red")
|
---|
| 205 |
|
---|
| 206 | def progress(self, currentValue):
|
---|
| 207 | self.progressbar["value"] = self.currentValue
|
---|
| 208 | self.progressbar["maximum"] = 60
|
---|
| 209 | if self.currentValue == 60:
|
---|
| 210 | self.currentValue = 0
|
---|
| 211 |
|
---|
| 212 | def round_counter(self):
|
---|
| 213 | self.count += 1
|
---|
| 214 | if self.count < 3:
|
---|
| 215 | self.currentValue = 0
|
---|
| 216 | self.progress(self.currentValue +1)
|
---|
| 217 | self.progressbar.update()
|
---|
| 218 | self.label_config.config(text="Runde: ")
|
---|
| 219 | self.label_config_text.config(text=("1", "/", self.repeats), fg='blue',font="Times 48")
|
---|
| 220 | if self.count >= 3 and self.count < 5:
|
---|
| 221 | self.label_config_text.config(text=("2", "/", self.repeats), fg='blue',font="Times 48")
|
---|
| 222 | if self.count >= 5 and self.count < 7:
|
---|
| 223 | self.label_config_text.config(text=("3", "/", self.repeats), fg='blue',font="Times 48")
|
---|
| 224 | if self.count >= 7 and self.count < 9:
|
---|
| 225 | self.label_config_text.config(text=("4", "/", self.repeats), fg='blue',font="Times 48")
|
---|
| 226 | if self.count >= 9 and self.count < 11:
|
---|
| 227 | self.label_config_text.config(text=("5", "/", self.repeats), fg='blue',font="Times 48")
|
---|
| 228 |
|
---|
| 229 | def change_config(self):
|
---|
| 230 | self.config_state = 'user'
|
---|
| 231 | self.config_files = [("all files", "*.csv")]
|
---|
| 232 | self.answer = filedialog.askopenfilename(parent=root,
|
---|
| 233 | initialdir=os.chdir("./configs"),
|
---|
| 234 | title="Please choose a config file:",
|
---|
| 235 | filetypes=self.config_files)
|
---|
| 236 | self.user_config = pd.read_csv(self.answer, sep=',', header=0,
|
---|
| 237 | names=('Titel', 'Values'), index_col=False, keep_default_na=False)
|
---|
| 238 | self.choosed_config = pd.read_csv(self.answer, usecols=[0, 1])
|
---|
| 239 | self.df = self.user_config
|
---|
| 240 | self.label_config_text.config(text=self.choosed_config)
|
---|
| 241 | df = self.user_config
|
---|
| 242 | repeat_of_phases = df['Values'][3]
|
---|
| 243 |
|
---|
| 244 | phase_1 = Phase(title=df['Titel'][0], duration=df['Values'][0])
|
---|
| 245 | phase_2 = Phase(title=df['Titel'][1], duration=df['Values'][1])
|
---|
| 246 | phase_3 = Phase(title=df['Titel'][2], duration=df['Values'][2])
|
---|
| 247 |
|
---|
| 248 | if repeat_of_phases == 1:
|
---|
| 249 | phase_list = [phase_1, phase_2, phase_3]
|
---|
| 250 |
|
---|
| 251 | if repeat_of_phases == 2:
|
---|
| 252 | phase_list = [phase_1, phase_2, phase_3, copy(phase_2), copy(phase_3)]
|
---|
| 253 |
|
---|
| 254 | if repeat_of_phases == 3:
|
---|
| 255 | phase_list = [phase_1, phase_2, phase_3, copy(phase_2), copy(phase_3), copy(phase_2), copy(phase_3)]
|
---|
| 256 |
|
---|
| 257 | if repeat_of_phases == 4:
|
---|
| 258 | phase_list = [phase_1, phase_2, phase_3, copy(phase_2), copy(phase_3), copy(phase_2), copy(phase_3),
|
---|
| 259 | copy(phase_2), copy(phase_3)]
|
---|
| 260 |
|
---|
| 261 | if repeat_of_phases == 5:
|
---|
| 262 | phase_list = [phase_1, phase_2, phase_3, copy(phase_2), copy(phase_3), copy(phase_2), copy(phase_3),
|
---|
| 263 | copy(phase_2), copy(phase_3), copy(phase_2), copy(phase_3)]
|
---|
| 264 |
|
---|
| 265 | self.repeats = repeat_of_phases
|
---|
| 266 |
|
---|
| 267 | self.schedule = Schedule(phase_list)
|
---|
| 268 |
|
---|
| 269 | root = tk.Tk()
|
---|
| 270 |
|
---|
| 271 |
|
---|
| 272 | root.title("--=> flowtimer <=-- " + " date: " + date + " time: " + time)
|
---|
| 273 | root.geometry("1280x860")
|
---|
| 274 | root.config(bg='black')
|
---|
| 275 | root.iconphoto(False, ImageTk.PhotoImage(Image.open('icon_bombtimer.png')))
|
---|
| 276 |
|
---|
| 277 | app = TimerApp(root)
|
---|
| 278 |
|
---|
| 279 | app.mainloop()
|
---|