Changeset 58e7315 in flowtimer


Ignore:
Timestamp:
08/29/24 16:33:22 (9 months ago)
Author:
Enrico Schwass <ennoausberlin@…>
Branches:
guix
Children:
ab10343
Parents:
80996d0
Message:

support for color scheme added

Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • flowtimer/main.py

    r80996d0 r58e7315  
    44from PIL import Image, ImageTk
    55from pathlib import Path
    6 import datetime
    76import argparse
    8 
     7import json
    98from Schedule import Schedule
    109
     
    1211class TimerApp(tk.Frame):
    1312
    14     def __init__(self, parent, tick_speed, config_file, autostart):
     13    def __init__(self, parent, tick_speed, config_file, color_file, autostart):
    1514
    1615        super().__init__(parent)
     
    2221        print("Config:", config_file)
    2322        self.schedule = self.load_config(config_file)
    24 
     23        self.color_scheme = self.load_color_file(color_file)
    2524        self.build_gui()
    2625        if autostart:
     
    7473        self.label_duration.pack(side='top', fill='both', expand=True)
    7574
    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 
    8075        self.freeze_button = tk.Button(self.button_frame, text="PLAY/PAUSE",
    8176                                       font="courier 14", width=20, command=self.toggle_play_pause)
     
    9590        else:
    9691            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)
    9795
    9896    def current_title(self):
     
    109107                    f"{len(self.schedule.current_block.phases)} "
    110108                    f"({self.schedule.current_block.passes_left})")
     109        return (f"{self.schedule.current_block.title}")
    111110
    112111    def current_time_status(self):
     
    145144                self.freeze_button.config(fg="ivory3")
    146145
    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 
    154146    def skip(self):
    155147        self.schedule.skip()
    156148
    157149    def toggle_play_pause(self):
    158         if self.schedule.paused():
     150        if not self.schedule.running():
    159151            self.freeze_button.config(relief="raised", fg='black')
    160152            self.label_sequence.config(fg="white")
     
    172164        self.parent.destroy()
    173165
     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
    174176    def change_config(self, json_string):
    175177        self.schedule = Schedule.from_json(json_string)
     
    181183                schedule = self.change_config(config_file.read())
    182184        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)
    184188            return Schedule.default()
    185189        return schedule
     
    195199
    196200
    197 now = datetime.datetime.now()
    198 date = now.strftime("%m/%d/%Y")
    199 time = now.strftime("%H:%M:%S")
    200 
    201201parser = argparse.ArgumentParser(description="Load specified config file and autostart if needed")
    202202parser.add_argument('--start', dest='autostart', action='store_true', default=False,
    203203                    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',
     204parser.add_argument('--config', dest='config_file', required=False,
     205                    default=Path(__file__).parent / 'configs' / 'default.json',
    205206                    help='use --config /path/to/config_file.json to specify the configuration of the timer')
    206 
     207parser.add_argument('--color', dest='color_file', required=False,
     208                    default=Path(__file__).parent / 'configs' / 'colors.json')
    207209args = parser.parse_args()
    208210
    209211root = tk.Tk()
    210 root.title("--=> flowtimer <=-- " + "  date: " + date + "  time: " + time)
     212root.title(args.config_file)
    211213root.geometry("1280x860")
    212214root.config(bg='black')
     
    218220               tick_speed=1,
    219221               config_file=args.config_file,
     222               color_file=args.color_file,
    220223               autostart=args.autostart)
    221224
  • pyproject.toml

    r80996d0 r58e7315  
    99authors = ["See Contributors"]
    1010homepage = "https://kokyou.org:8080/playground/browser/flowtimer"
    11 repository = "kokyou.org:/srv/git/flowtimer.git"
     11repository = "https://kokyou.org:/srv/git/flowtimer.git"
    1212license = "MIT"
    1313readme = "README.md"
Note: See TracChangeset for help on using the changeset viewer.