Changeset 36c9ef5 in flowtimer


Ignore:
Timestamp:
08/22/24 19:50:01 (9 months ago)
Author:
Enrico Schwass <ennoausberlin@…>
Branches:
guix
Children:
bd94da0
Parents:
5741f6d
Message:

more adoptions for block_list

Location:
flowtimer
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • flowtimer/RecurringPhaseSequence.py

    r5741f6d r36c9ef5  
    4545    @property
    4646    def title(self):
    47         return self.current_phase.title
     47        return self._title
    4848
    4949    def is_sequence(self):
     
    8282        self.state = "running"
    8383
     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
    8498    def tick(self, ticks):
    8599        if not self.finished():
  • flowtimer/Schedule.py

    r5741f6d r36c9ef5  
    11import json
     2
     3"""
     4I represent a Schedule consisting of blocks. Blocks can be a single phase or
     5a sequence of phases.
     6"""
    27
    38
    49class Schedule:
    510
    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]
    915        self.state = "initial"
    1016
     
    1420    def start(self):
    1521        self.state = "running"
    16         self.current_phase.start()
     22        self.current_block.start()
    1723
    1824    def pause(self):
     
    2632
    2733    def abort(self):
    28         self.current_phase.abort()
     34        self.current_block.abort()
    2935        self.state = "finished"
    3036
    3137    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):
    3339            self.state = "finished"
    34             print("Finished")
    3540            return True
    3641        else:
     
    3843
    3944    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()
    4247        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]
    4553
    46     def ticks_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()]))
    4957
    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:]
    5462        return []
    5563
    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)
    5967
    6068    def tick(self, duration):
    6169        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():
    6573                    self.abort()
    6674                else:
  • flowtimer/main.py

    r5741f6d r36c9ef5  
    88import datetime
    99
    10 now = datetime.datetime.now()
    11 date = now.strftime("%m/%d/%Y")
    12 time = now.strftime("%H:%M:%S")
    13 
    1410
    1511class TimerApp(tk.Frame):
    1612
    17     def __init__(self, parent):
     13    def __init__(self, parent, tickspeed):
    1814
    1915        super().__init__(parent)
    2016        self.parent = parent
     17        self.tick_speed = tickspeed
    2118        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()
    2720        self.photo = ImageTk.PhotoImage(file=Path(__file__).parent /
    2821                                        'resources' / 'flowtimer_startbg_new.png')
    29         print(self.schedule.current_phase.title)
    30         self.show_config = self.schedule.current_phase.title
    3122        self.config_state = 'default'
    3223
     
    5950
    6051        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)
    6253        self.config_button.pack(side='right', padx=10, pady=10, expand=False)
    6354
    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(),
    6556                                          bg='white', font="serif 10", justify='right')
    6657        self.label_config_text.pack()
     
    9687                                     font="courier 14", width=20, command=self.quit_app)
    9788        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()}"
    98117
    99118    def tick(self):
     
    105124        if self.schedule.state == 'initial':
    106125            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) + "..."))
    108127            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())
    112129            self.schedule.start()
    113             self.schedule.tick(1)
     130            self.schedule.tick(1*self.tick_speed)
    114131        else:
    115132            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) % 60
     133                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
    119136                self.progressbar.update()
    120137                self.label_sequence.configure(self.start_color(root))
     
    122139                self.label_sequence.config(bg=self.random_color(self.label_sequence))
    123140                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")
    131143            else:
    132144                self.label_sequence.configure(self.time_out_color(root))
     
    150162    def skip(self):
    151163        self.schedule.skip()
    152         self.currentValue = 0
    153164
    154165    def toggle_tick(self):
     
    171182    def random_color(self, widget):
    172183        # 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":
    175185            widget.configure(bg="blue")
    176186            self.label_sequence.config(text=("\n" + "Besprechung"))
    177187            self.center_frame.configure(bg="blue")
    178         if self.schedule.current_phase.title == "Tasking":
     188        if self.schedule.current_block.title == "Tasking":
    179189            widget.configure(bg="green")
    180190            self.label_sequence.config(text=("\n" + "Intensivphase"))
    181191            self.center_frame.configure(bg="green")
    182         if self.schedule.current_phase.title == "Work":
     192        if self.schedule.current_block.title == "Work":
    183193            widget.configure(bg="gold")
    184194            self.label_sequence.config(text=("\n" + "Synchronisation"))
     
    196206        widget.configure(bg="red")
    197207
    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):
    202216        self.config_state = 'user'
    203217        self.config_files = [("all files", "*.json")]
     
    206220                                                 title="Please choose a config file:",
    207221                                                 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
     225now = datetime.datetime.now()
     226date = now.strftime("%m/%d/%Y")
     227time = now.strftime("%H:%M:%S")
    211228
    212229root = tk.Tk()
     
    216233root.iconphoto(False, ImageTk.PhotoImage(Image.open(Path(__file__).parent / 'resources' / 'icon_bombtimer.png')))
    217234
    218 app = TimerApp(root)
     235app = TimerApp(root, tickspeed=1)
    219236
    220237app.mainloop()
Note: See TracChangeset for help on using the changeset viewer.