Changeset 37ae3b7 in flowtimer
- Timestamp:
- 08/15/24 21:00:01 (9 months ago)
- Branches:
- guix
- Children:
- 3b76475
- Parents:
- 729b23d
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
flowtimer/RecurringPhaseSequence.py
r729b23d r37ae3b7 1 1 import json 2 from copy import deepcopy 3 from Phase import Phase 2 4 3 5 4 6 class RecurringPhaseSequence: 7 8 @classmethod 9 def from_json(cls, a_json_string): 10 def custom_object_hook(d): 11 if 'title' in d and 'duration' in d: 12 return Phase(d['title'], d['duration']) 13 if 'phase_list' in d and 'repetitions' in d: 14 return RecurringPhaseSequence(d['phase_list'], d['repetitions']) 15 return d 16 return json.loads(a_json_string, object_hook=custom_object_hook) 17 18 @classmethod 19 def default_json_string(cls): 20 return json.dumps({"phase_list": [{"title": "Huddle", "duration": 10}, 21 {"title": "Tasking", "duration": 5}, 22 {"title": "Work", "duration": 45}, 23 {"title": "Break", "duration": 15}], 24 "repetitions": 3}) 5 25 6 26 def __init__(self, phase_list, repetitions): … … 12 32 13 33 def unrolled(self): 14 return [ [deepcopy(seq) for seq in [each for each in se1f.repetitions * se1f.phase_list]]]34 return [deepcopy(seq) for seq in [each for each in self.repetitions * self.phase_list]] 15 35 # return self.repetitions * self.phase_list -
flowtimer/Schedule.py
r729b23d r37ae3b7 5 5 6 6 def __init__(self, phase_list): 7 self.currentValue = 08 7 self.phase_list = phase_list 9 8 self.current_phase = phase_list[0] … … 11 10 12 11 def to_json(self): 13 json.dumps(self.__dict__)12 return json.dumps(self.__dict__) 14 13 15 14 def start(self): … … 44 43 self.current_phase = self.phase_list[index+1] 45 44 45 def time_left(self): 46 return self.current_phase.time_left + sum([phase.time_left for phase in self.upcoming_phases]) 47 48 def upcoming_phases(self): 49 index = self.phase_list.index(self.current_phase) 50 return self.phase_list[index:] 51 46 52 def current_phase_is_final(self): 47 53 index = self.phase_list.index(self.current_phase) -
flowtimer/main.py
r729b23d r37ae3b7 3 3 from tkinter import filedialog 4 4 from Schedule import Schedule 5 from Phase import Phase5 from RecurringPhaseSequence import RecurringPhaseSequence 6 6 from PIL import Image, ImageTk 7 from copy import copy 8 import pandas as pd 7 from pathlib import Path 9 8 import os 10 9 import math … … 24 23 self.count = 0 25 24 self.currentValue = 0 26 self.default_config = pd.read_csv("default_config.csv", sep=',', header=0, 27 names=('Titel', 'Values'), index_col=False, 28 keep_default_na=False) 29 self.photo = ImageTk.PhotoImage(file='flowtimer_startbg_new.png') 30 self.show_config = pd.read_csv("default_config.csv", usecols=[0, 1]) 25 config = Path(__file__).parent / 'configs' / 'default.json' 26 with open(config) as config_file: 27 self.schedule = Schedule(RecurringPhaseSequence.from_json(config_file.read()).unrolled()) 28 self.photo = ImageTk.PhotoImage(file=Path(__file__).parent / 'resources' / 'flowtimer_startbg_new.png') 29 print(self.schedule.current_phase) 30 self.show_config = self.schedule.current_phase.title 31 31 self.config_state = 'default' 32 print(self.schedule) 32 33 33 34 self.build_gui() … … 95 96 font="courier 14", width=20, command=self.quit_app) 96 97 self.quit_button.pack(side='left', fill='both', ipady=20, expand=True) 97 98 df = self.default_config99 repeat_of_phases = df['Values'][3]100 101 phase_1 = Phase(title=df['Titel'][0], duration=df['Values'][0])102 phase_2 = Phase(title=df['Titel'][1], duration=df['Values'][1])103 phase_3 = Phase(title=df['Titel'][2], duration=df['Values'][2])104 105 if repeat_of_phases == 1:106 phase_list = [phase_1, phase_2, phase_3]107 108 if repeat_of_phases == 2:109 phase_list = [phase_1, phase_2, phase_3, copy(phase_2), copy(phase_3)]110 111 if repeat_of_phases == 3:112 phase_list = [phase_1, phase_2, phase_3, copy(phase_2), copy(phase_3),113 copy(phase_2), copy(phase_3)]114 115 if repeat_of_phases == 4:116 phase_list = [phase_1, phase_2, phase_3, copy(phase_2), copy(phase_3),117 copy(phase_2), copy(phase_3), copy(phase_2), copy(phase_3)]118 119 if repeat_of_phases == 5:120 phase_list = [phase_1, phase_2, phase_3, copy(phase_2), copy(phase_3),121 copy(phase_2), copy(phase_3), copy(phase_2), copy(phase_3),122 copy(phase_2), copy(phase_3)]123 124 self.repeats = repeat_of_phases125 126 self.schedule = Schedule(phase_list)127 98 128 99 def tick(self): … … 254 225 def change_config(self): 255 226 self.config_state = 'user' 256 self.config_files = [("all files", "*. csv")]227 self.config_files = [("all files", "*.json")] 257 228 self.answer = filedialog.askopenfilename(parent=root, 258 initialdir= os.chdir("./configs"),229 initialdir=Path(__file__).parent / 'configs', 259 230 title="Please choose a config file:", 260 231 filetypes=self.config_files) 261 self.user_config = pd.read_csv(self.answer, sep=',', header=0, 262 names=('Titel', 'Values'), 263 index_col=False, keep_default_na=False) 264 self.choosed_config = pd.read_csv(self.answer, usecols=[0, 1]) 265 self.df = self.user_config 266 self.label_config_text.config(text=self.choosed_config) 267 df = self.user_config 268 repeat_of_phases = df['Values'][3] 269 270 phase_1 = Phase(title=df['Titel'][0], duration=df['Values'][0]) 271 phase_2 = Phase(title=df['Titel'][1], duration=df['Values'][1]) 272 phase_3 = Phase(title=df['Titel'][2], duration=df['Values'][2]) 273 274 if repeat_of_phases == 1: 275 phase_list = [phase_1, phase_2, phase_3] 276 277 if repeat_of_phases == 2: 278 phase_list = [phase_1, phase_2, phase_3, copy(phase_2), copy(phase_3)] 279 280 if repeat_of_phases == 3: 281 phase_list = [phase_1, phase_2, phase_3, copy(phase_2), copy(phase_3), 282 copy(phase_2), copy(phase_3)] 283 284 if repeat_of_phases == 4: 285 phase_list = [phase_1, phase_2, phase_3, copy(phase_2), copy(phase_3), 286 copy(phase_2), copy(phase_3), 287 copy(phase_2), copy(phase_3)] 288 289 if repeat_of_phases == 5: 290 phase_list = [phase_1, phase_2, phase_3, copy(phase_2), copy(phase_3), 291 copy(phase_2), copy(phase_3), copy(phase_2), copy(phase_3), 292 copy(phase_2), copy(phase_3)] 293 294 self.repeats = repeat_of_phases 295 296 self.schedule = Schedule(phase_list) 232 with open(self.answer) as config_file: 233 self.schedule = Schedule(RecurringPhaseSequence.from_json(config_file.read()).unrolled()) 297 234 298 235 … … 301 238 root.geometry("1280x860") 302 239 root.config(bg='black') 303 root.iconphoto(False, ImageTk.PhotoImage(Image.open( 'icon_bombtimer.png')))240 root.iconphoto(False, ImageTk.PhotoImage(Image.open(Path(__file__).parent / 'resources' / 'icon_bombtimer.png'))) 304 241 305 242 app = TimerApp(root) -
tests/test_schedule.py
r729b23d r37ae3b7 13 13 assert schedule.current_phase == phase1 14 14 assert schedule.state == "initial" 15 assert schedule.currentValue == 016 15 17 16 def test_schedule_start(self):
Note:
See TracChangeset
for help on using the changeset viewer.