Changeset c251a80 in flowtimer


Ignore:
Timestamp:
08/29/24 15:21:23 (9 months ago)
Author:
Enrico Schwass <ennoausberlin@…>
Branches:
guix
Children:
80996d0
Parents:
7a52e57
Message:

command line argument parser added and README.md updated

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • README.md

    r7a52e57 rc251a80  
    1818- Python 3.x
    1919
     20### Test without install
     21   ```bash
     22   git clone --branch guix https://gitlab.kid.local:/legacy/flowtimer.git
     23   cd flowtimer
     24
     25   guix shell python python:tk python-pillow --
     26   export PYTHONPATH=$PYTHONPATH:./
     27   python3 flowtimer/main.py
     28   ```
     29
    2030### Installation
    2131
    22321. Clone the repository:
    2333   ```bash
    24    git clone --branch guix https://gitlab.kid.local:/legacy/flowtimer.git
    25    cd flowtimer
     34    git clone --branch guix https://gitlab.kid.local:/legacy/flowtimer.git
     35        cd flowtimer
    2636   ```
     372. Install the app and required dependencies
     38   ```bash
     39        pip3 install .
    2740
    28 2. Install the required dependencies:
    29    ```bash
    30    pip3 install .
    3141   ```
    32 
    3342### Usage
    3443
     
    1011102. **Run Flowtimer:**
    102111   ```bash
    103    python flowtimer.py --config /path/to/config_file.json
     112   python3 flowtimer.py --start --config /path/to/config_file.json
    104113   ```
    105114
     
    109118   To change the timings or the order of phases, simply edit the JSON file and rerun the script.
    110119
    111 ### Default Configuration
    112 
    113 If no configuration file is provided, Flowtimer will use the following default settings:
    114 
    115 - 25 minutes of work
    116 - 5 minutes of short break
    117 - 4 work sessions before a 15-minute long break
    118120
    119121### Command-line Options
     
    125127
    126128```bash
    127 python flowtimer.py --config myconfig.json
     129python3 flowtimer.py --config myconfig.json
    128130```
    129131
  • flowtimer/main.py

    r7a52e57 rc251a80  
    11import tkinter as tk
    22import tkinter.ttk as ttk
    3 from tkinter import filedialog
    4 from Schedule import Schedule
     3from tkinter import filedialog, messagebox
    54from PIL import Image, ImageTk
    65from pathlib import Path
    76import datetime
     7import argparse
     8
     9from Schedule import Schedule
    810
    911
    1012class TimerApp(tk.Frame):
    1113
    12     def __init__(self, parent, tickspeed):
     14    def __init__(self, parent, tick_speed, config_file, autostart):
    1315
    1416        super().__init__(parent)
    1517        self.parent = parent
    16         self.tick_speed = tickspeed
    17         self.count = 0
    18         self.load_config()
     18        self.tick_speed = tick_speed
    1919        self.photo = ImageTk.PhotoImage(file=Path(__file__).parent /
    2020                                        'resources' / 'flowtimer_startbg_new.png')
    2121        self.config_state = 'default'
     22        print("Config:", config_file)
     23        self.schedule = self.load_config(config_file)
    2224
    2325        self.build_gui()
     26        if autostart:
     27            self.start()
    2428
    2529    def build_gui(self):
     
    170174    def change_config(self, json_string):
    171175        self.schedule = Schedule.from_json(json_string)
     176        return self.schedule
    172177
    173178    def load_config(self, file_name=Path(__file__).parent / 'configs' / 'default.json'):
    174         with open(file_name) as config_file:
    175             self.change_config(config_file.read())
     179        try:
     180            with open(file_name) as config_file:
     181                schedule = self.change_config(config_file.read())
     182        except Exception as e:
     183            messagebox.showerror('Config error', f'Can not load {file_name}\n\nDefault loaded instead')
     184            return Schedule.default()
     185        return schedule
    176186
    177187    def select_config(self):
     
    189199time = now.strftime("%H:%M:%S")
    190200
     201parser = argparse.ArgumentParser(description="Load specified config file and autostart if needed")
     202parser.add_argument('--start', dest='autostart', action='store_true', default=False,
     203                    required=False, help='use --start to autostart the timer with the given config')
     204parser.add_argument('--config', dest='config_file', required=False, default=Path(__file__).parent / 'configs' / 'default.json',
     205                    help='use --config /path/to/config_file.json to specify the configuration of the timer')
     206
     207args = parser.parse_args()
     208
    191209root = tk.Tk()
    192210root.title("--=> flowtimer <=-- " + "  date: " + date + "  time: " + time)
    193211root.geometry("1280x860")
    194212root.config(bg='black')
    195 root.iconphoto(False, ImageTk.PhotoImage(Image.open(Path(__file__).parent / 'resources' / 'icon_bombtimer.png')))
    196 
    197 app = TimerApp(root, tickspeed=1)
     213root.iconphoto(False, ImageTk.PhotoImage(Image.open(Path(__file__).parent /
     214                                                    'resources' /
     215                                                    'icon_bombtimer.png')))
     216
     217app = TimerApp(root,
     218               tick_speed=1,
     219               config_file=args.config_file,
     220               autostart=args.autostart)
    198221
    199222app.mainloop()
Note: See TracChangeset for help on using the changeset viewer.