Changeset 36c9ef5 in flowtimer
- Timestamp:
- 08/22/24 19:50:01 (9 months ago)
- Branches:
- guix
- Children:
- bd94da0
- Parents:
- 5741f6d
- Location:
- flowtimer
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
flowtimer/RecurringPhaseSequence.py
r5741f6d r36c9ef5 45 45 @property 46 46 def title(self): 47 return self. current_phase.title47 return self._title 48 48 49 49 def is_sequence(self): … … 82 82 self.state = "running" 83 83 84 def skip(self): 85 if self.upcoming_phases_in_pass(): 86 self.current_phase.reset() 87 self.current_phase = self.upcoming_phases_in_pass()[0] 88 return 89 else: 90 if self.passes_left == 0: 91 self.abort() 92 return 93 else: 94 self.passes_left -= 1 95 self.current_phase.reset() 96 self.current_phase = self.phase_list[0] 97 84 98 def tick(self, ticks): 85 99 if not self.finished(): -
flowtimer/Schedule.py
r5741f6d r36c9ef5 1 1 import json 2 3 """ 4 I represent a Schedule consisting of blocks. Blocks can be a single phase or 5 a sequence of phases. 6 """ 2 7 3 8 4 9 class Schedule: 5 10 6 def __init__(self, phase_list): 7 self.phase_list = phase_list 8 self.current_phase = phase_list[0] 11 def __init__(self, block_list): 12 assert block_list is not [] 13 self.block_list = block_list 14 self.current_block = block_list[0] 9 15 self.state = "initial" 10 16 … … 14 20 def start(self): 15 21 self.state = "running" 16 self.current_ phase.start()22 self.current_block.start() 17 23 18 24 def pause(self): … … 26 32 27 33 def abort(self): 28 self.current_ phase.abort()34 self.current_block.abort() 29 35 self.state = "finished" 30 36 31 37 def finished(self): 32 if (self.current_ phase.finished()) and (self.phase_list[-1] == self.current_phase):38 if (self.current_block.finished()) and (self.block_list[-1] == self.current_block): 33 39 self.state = "finished" 34 print("Finished")35 40 return True 36 41 else: … … 38 43 39 44 def skip(self): 40 if self.current_ phase_is_final():41 self. abort()45 if self.current_block.is_sequence: 46 self.current_block.skip() 42 47 else: 43 index = self.phase_list.index(self.current_phase) 44 self.current_phase = self.phase_list[index+1] 48 if self.current_block_is_final(): 49 self.abort() 50 else: 51 index = self.block_list.index(self.current_block) 52 self.current_block = self.block_list[index+1] 45 53 46 def t icks_left(self):47 return (self.current_ phase.ticks_left +48 sum([ phase.ticks_left for phase in self.upcoming_phases()]))54 def total_ticks_left(self): 55 return (self.current_block.ticks_left + 56 sum([block.ticks_left for block in self.upcoming_blocks()])) 49 57 50 def upcoming_ phases(self):51 index = self. phase_list.index(self.current_phase)52 if index < len(self. phase_list):53 return self. phase_list[index+1:]58 def upcoming_blocks(self): 59 index = self.block_list.index(self.current_block) 60 if index < len(self.block_list): 61 return self.block_list[index+1:] 54 62 return [] 55 63 56 def current_ phase_is_final(self):57 index = self. phase_list.index(self.current_phase)58 return index == (len(self. phase_list) - 1)64 def current_block_is_final(self): 65 index = self.block_list.index(self.current_block) 66 return index == (len(self.block_list) - 1) 59 67 60 68 def tick(self, duration): 61 69 if not self.finished(): 62 self.current_ phase.tick(duration)63 if self.current_ phase.finished():64 if self.current_ phase_is_final():70 self.current_block.tick(duration) 71 if self.current_block.finished(): 72 if self.current_block_is_final(): 65 73 self.abort() 66 74 else: -
flowtimer/main.py
r5741f6d r36c9ef5 8 8 import datetime 9 9 10 now = datetime.datetime.now()11 date = now.strftime("%m/%d/%Y")12 time = now.strftime("%H:%M:%S")13 14 10 15 11 class TimerApp(tk.Frame): 16 12 17 def __init__(self, parent ):13 def __init__(self, parent, tickspeed): 18 14 19 15 super().__init__(parent) 20 16 self.parent = parent 17 self.tick_speed = tickspeed 21 18 self.count = 0 22 self.currentValue = 0 23 config = Path(__file__).parent / 'configs' / 'default.json' 24 with open(config) as config_file: 25 self.schedule = Schedule([RecurringPhaseSequence.from_json(config_file.read())]) 26 19 self.load_config() 27 20 self.photo = ImageTk.PhotoImage(file=Path(__file__).parent / 28 21 'resources' / 'flowtimer_startbg_new.png') 29 print(self.schedule.current_phase.title)30 self.show_config = self.schedule.current_phase.title31 22 self.config_state = 'default' 32 23 … … 59 50 60 51 self.config_button = tk.Button(self.headline_frame, text="change config", 61 font="courier 14", width=20, command=self. change_config)52 font="courier 14", width=20, command=self.select_config) 62 53 self.config_button.pack(side='right', padx=10, pady=10, expand=False) 63 54 64 self.label_config_text = tk.Label(self.label_config, text=self. show_config,55 self.label_config_text = tk.Label(self.label_config, text=self.current_config(), 65 56 bg='white', font="serif 10", justify='right') 66 57 self.label_config_text.pack() … … 96 87 font="courier 14", width=20, command=self.quit_app) 97 88 self.quit_button.pack(side='left', fill='both', ipady=20, expand=True) 89 90 def ticks_left_in_phase(self): 91 if self.schedule.current_block.is_sequence(): 92 return self.schedule.current_block.current_phase.ticks_left 93 else: 94 return self.schedule.current_block.ticks_left 95 96 def ticks_left_in_block(self): 97 if self.schedule.current_block.is_sequence(): 98 return self.schedule.current_block.ticks_left 99 else: 100 return self.schedule.current_block.ticks_left 101 102 def current_title(self): 103 if self.schedule.current_block.is_sequence(): 104 return self.schedule.current_block.current_phase.title 105 else: 106 return self.schedule.current_block.title 107 108 def current_config(self): 109 if self.schedule.current_block.is_sequence(): 110 return f"{self.schedule.current_block.title} / {self.schedule.current_block.current_phase.title} / {self.schedule.current_block.current_phase_number()+1} of {len(self.schedule.current_block.phase_list)} ({self.schedule.current_block.passes_left})" 111 112 def current_time_status(self): 113 if self.ticks_left_in_phase() < 60: 114 return f"{self.ticks_left_in_phase()} seconds left in phase {self.current_title()}" 115 else: 116 return f"{(self.ticks_left_in_phase() // 60)} min left in phase {self.current_title()}" 98 117 99 118 def tick(self): … … 105 124 if self.schedule.state == 'initial': 106 125 self.label_sequence.config(self.start_color(root)) 107 self.label_sequence.config(text=("\n" + str(self.schedule.current_ phase.title) + "..."))126 self.label_sequence.config(text=("\n" + str(self.schedule.current_block.title) + "...")) 108 127 self.label_duration.config(self.start_color(root)) 109 self.label_duration.config(text=("noch " + 110 str(self.schedule.current_phase.ticks_left // 60) + 111 " Min\n")) 128 self.label_duration.config(text=self.current_time_status()) 112 129 self.schedule.start() 113 self.schedule.tick(1 )130 self.schedule.tick(1*self.tick_speed) 114 131 else: 115 132 if self.schedule.running(): 116 self.schedule.tick(1 )117 self.progressbar["value"] = (self.schedule.current_ phase.initial_ticks -118 self.schedule.current_ phase.ticks_left) % 60133 self.schedule.tick(1*self.tick_speed) 134 self.progressbar["value"] = (self.schedule.current_block.initial_ticks - 135 self.schedule.current_block.ticks_left) % 60 119 136 self.progressbar.update() 120 137 self.label_sequence.configure(self.start_color(root)) … … 122 139 self.label_sequence.config(bg=self.random_color(self.label_sequence)) 123 140 self.label_duration.config(self.random_color(root)) 124 self.label_duration.config(text=("noch " + 125 str(self.schedule.current_phase.ticks_left // 60) 126 + " Min\n"), bg=self.random_color(self.label_duration)) 127 self.label_config_text.config(text=(self.schedule.current_phase.current_phase_number()+1, 128 "/", self.schedule.current_phase.current_phase_number()), 129 fg='blue', font="Times 48") 130 141 self.label_duration.config(text=self.current_time_status(), bg=self.random_color(self.label_duration)) 142 self.label_config_text.config(text=self.current_config(), fg='blue', font="Times 48") 131 143 else: 132 144 self.label_sequence.configure(self.time_out_color(root)) … … 150 162 def skip(self): 151 163 self.schedule.skip() 152 self.currentValue = 0153 164 154 165 def toggle_tick(self): … … 171 182 def random_color(self, widget): 172 183 # FIXME: Do not hardcode this 173 print(self.schedule.current_phase.title) 174 if self.schedule.current_phase.title == "Huddle": 184 if self.schedule.current_block.title == "Huddle": 175 185 widget.configure(bg="blue") 176 186 self.label_sequence.config(text=("\n" + "Besprechung")) 177 187 self.center_frame.configure(bg="blue") 178 if self.schedule.current_ phase.title == "Tasking":188 if self.schedule.current_block.title == "Tasking": 179 189 widget.configure(bg="green") 180 190 self.label_sequence.config(text=("\n" + "Intensivphase")) 181 191 self.center_frame.configure(bg="green") 182 if self.schedule.current_ phase.title == "Work":192 if self.schedule.current_block.title == "Work": 183 193 widget.configure(bg="gold") 184 194 self.label_sequence.config(text=("\n" + "Synchronisation")) … … 196 206 widget.configure(bg="red") 197 207 198 def progress(self, currentValue): 199 self.progressbar["value"] = self.currentValue 200 201 def change_config(self): 208 def change_config(self, json_string): 209 self.schedule = Schedule([RecurringPhaseSequence.from_json(json_string)]) 210 211 def load_config(self, file_name=Path(__file__).parent / 'configs' / 'default.json'): 212 with open(file_name) as config_file: 213 self.change_config(config_file.read()) 214 215 def select_config(self): 202 216 self.config_state = 'user' 203 217 self.config_files = [("all files", "*.json")] … … 206 220 title="Please choose a config file:", 207 221 filetypes=self.config_files) 208 with open(self.answer) as config_file: 209 self.schedule = Schedule(RecurringPhaseSequence.from_json(config_file.read())) 210 222 self.load_config(Path(self.answer)) 223 224 225 now = datetime.datetime.now() 226 date = now.strftime("%m/%d/%Y") 227 time = now.strftime("%H:%M:%S") 211 228 212 229 root = tk.Tk() … … 216 233 root.iconphoto(False, ImageTk.PhotoImage(Image.open(Path(__file__).parent / 'resources' / 'icon_bombtimer.png'))) 217 234 218 app = TimerApp(root )235 app = TimerApp(root, tickspeed=1) 219 236 220 237 app.mainloop()
Note:
See TracChangeset
for help on using the changeset viewer.