Changeset 58e7315 in flowtimer
- Timestamp:
- 08/29/24 16:33:22 (9 months ago)
- Branches:
- guix
- Children:
- ab10343
- Parents:
- 80996d0
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
flowtimer/main.py
r80996d0 r58e7315 4 4 from PIL import Image, ImageTk 5 5 from pathlib import Path 6 import datetime7 6 import argparse 8 7 import json 9 8 from Schedule import Schedule 10 9 … … 12 11 class TimerApp(tk.Frame): 13 12 14 def __init__(self, parent, tick_speed, config_file, autostart):13 def __init__(self, parent, tick_speed, config_file, color_file, autostart): 15 14 16 15 super().__init__(parent) … … 22 21 print("Config:", config_file) 23 22 self.schedule = self.load_config(config_file) 24 23 self.color_scheme = self.load_color_file(color_file) 25 24 self.build_gui() 26 25 if autostart: … … 74 73 self.label_duration.pack(side='top', fill='both', expand=True) 75 74 76 self.start_timer_button = tk.Button(self.button_frame, text="START",77 font="courier 14", width=20, command=self.start)78 self.start_timer_button.pack(side='left', fill='both', ipady=20, expand=True)79 80 75 self.freeze_button = tk.Button(self.button_frame, text="PLAY/PAUSE", 81 76 font="courier 14", width=20, command=self.toggle_play_pause) … … 95 90 else: 96 91 return self.schedule.current_block.ticks_left 92 93 def color_for_phase(self, a_title): 94 return next((d for d in self.colors if d.get('title') == a_title), None) 97 95 98 96 def current_title(self): … … 109 107 f"{len(self.schedule.current_block.phases)} " 110 108 f"({self.schedule.current_block.passes_left})") 109 return (f"{self.schedule.current_block.title}") 111 110 112 111 def current_time_status(self): … … 145 144 self.freeze_button.config(fg="ivory3") 146 145 147 def start(self):148 self.schedule.start()149 self.tick()150 self.start_timer_button['state'] = 'disabled'151 self.start_timer_button.config(fg="ivory3")152 self.config_button.pack_forget()153 154 146 def skip(self): 155 147 self.schedule.skip() 156 148 157 149 def toggle_play_pause(self): 158 if self.schedule.paused():150 if not self.schedule.running(): 159 151 self.freeze_button.config(relief="raised", fg='black') 160 152 self.label_sequence.config(fg="white") … … 172 164 self.parent.destroy() 173 165 166 def load_color_file(self, file_name=Path(__file__).parent / 'configs' / 'colors.json'): 167 try: 168 with open(file_name) as color_file: 169 colors = json.loads(color_file.read()) 170 except Exception as e: 171 with open(Path(__file__).parent / 'configs' / 'colors.json') as color_file: 172 colors = json.loads(color_file.read()) 173 print(e) 174 return colors.get('color_list', []) 175 174 176 def change_config(self, json_string): 175 177 self.schedule = Schedule.from_json(json_string) … … 181 183 schedule = self.change_config(config_file.read()) 182 184 except Exception as e: 183 messagebox.showerror('Config error', f'Can not load {file_name}\n\nDefault loaded instead') 185 messagebox.showerror('Config error', 186 f'Can not load {file_name}\n\nDefault loaded instead') 187 print(e) 184 188 return Schedule.default() 185 189 return schedule … … 195 199 196 200 197 now = datetime.datetime.now()198 date = now.strftime("%m/%d/%Y")199 time = now.strftime("%H:%M:%S")200 201 201 parser = argparse.ArgumentParser(description="Load specified config file and autostart if needed") 202 202 parser.add_argument('--start', dest='autostart', action='store_true', default=False, 203 203 required=False, help='use --start to autostart the timer with the given config') 204 parser.add_argument('--config', dest='config_file', required=False, default=Path(__file__).parent / 'configs' / 'default.json', 204 parser.add_argument('--config', dest='config_file', required=False, 205 default=Path(__file__).parent / 'configs' / 'default.json', 205 206 help='use --config /path/to/config_file.json to specify the configuration of the timer') 206 207 parser.add_argument('--color', dest='color_file', required=False, 208 default=Path(__file__).parent / 'configs' / 'colors.json') 207 209 args = parser.parse_args() 208 210 209 211 root = tk.Tk() 210 root.title( "--=> flowtimer <=-- " + " date: " + date + " time: " + time)212 root.title(args.config_file) 211 213 root.geometry("1280x860") 212 214 root.config(bg='black') … … 218 220 tick_speed=1, 219 221 config_file=args.config_file, 222 color_file=args.color_file, 220 223 autostart=args.autostart) 221 224 -
pyproject.toml
r80996d0 r58e7315 9 9 authors = ["See Contributors"] 10 10 homepage = "https://kokyou.org:8080/playground/browser/flowtimer" 11 repository = " kokyou.org:/srv/git/flowtimer.git"11 repository = "https://kokyou.org:/srv/git/flowtimer.git" 12 12 license = "MIT" 13 13 readme = "README.md"
Note:
See TracChangeset
for help on using the changeset viewer.