Changeset 813e855 in flowtimer


Ignore:
Timestamp:
08/30/24 00:12:27 (9 months ago)
Author:
Enrico Schwass <ennoausberlin@…>
Branches:
guix
Children:
8f41b95
Parents:
0384305
Message:

predicates renamed

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • flowtimer/Phase.py

    r0384305 r813e855  
    5656        self._state = "aborted"
    5757
    58     def aborted(self):
     58    def is_aborted(self):
    5959        return self.state == "aborted"
    6060
     
    6969        self._state = "paused"
    7070
    71     def running(self):
     71    def is_running(self):
    7272        return self._state == "running"
    7373        # return self.time_left > 0
    7474
    75     def completed(self):
    76         return self._state == "completed"
     75    def is_terminated(self):
     76        return (self.is_completed() or self.is_aborted())
    7777
    78     def paused(self):
     78    def is_completed(self):
     79        return self.ticks_left < 1
     80
     81    def is_paused(self):
    7982        return self._state == "paused"
    8083
  • flowtimer/RecurringPhaseSequence.py

    r0384305 r813e855  
    3333        assert phases is not []
    3434        self._title = title
    35         self.state = "initial"
     35        self._state = "initial"
    3636        self.phases = phases
    3737        self.current_phase = phases[0]
     
    7474            sum([each.ticks_left for each in self.upcoming_phases_in_pass()]))
    7575
    76     def completed(self):
     76    def state(self):
     77        if self.is_completed():
     78            return "completed"
     79        return self._state
     80
     81    def is_final_round(self):
     82        return self.passes_left == 0
     83
     84    def is_completed(self):
    7785        return ((self.passes_left < 1) and
    7886                (not self.upcoming_phases_in_pass() and
    79                  self.current_phase.completed()))
     87                 self.current_phase.is_completed()))
     88
     89    def is_terminated(self):
     90        return (self.is_aborted() or self.is_completed())
     91
     92    def is_aborted(self):
     93        return self._state == 'aborted'
    8094
    8195    def abort(self):
    8296        self.current_phase.abort()
    83         self.state = "aborted"
     97        self._state = "aborted"
    8498
    8599    def start(self):
    86         self.state = "running"
     100        self._state = "running"
    87101
    88102    def skip(self):
     
    92106            return
    93107        else:
    94             if self.passes_left == 0:
     108            if self.is_final_round():
    95109                self.abort()
    96110                return
     
    110124            self.passes_left -= 1
    111125            if self.passes_left < 1:
    112                 self.state = "completed"
     126                self._state = "completed"
    113127            else:
    114128                self.current_phase.reset()
     
    116130
    117131    def tick(self, ticks):
    118         if not self.completed():
     132        if not self.is_completed():
    119133            result = self.current_phase.tick(ticks)
    120             if self.current_phase.completed():
     134            if self.current_phase.is_completed():
    121135                self.advance_to_next_phase()
    122136                result = self.tick(abs(result))
    123137                return
    124 #        if self.completed():
    125 #            self.advance_to_next_phase()
    126138
    127139    def unrolled(self):
  • flowtimer/Schedule.py

    r0384305 r813e855  
    119119
    120120    def is_completed(self):
    121         if (self.current_block.completed()) and (self.current_block_is_final()):
     121        if (self.current_block.is_completed()) and (self.current_block_is_final()):
    122122            return True
    123123        else:
     
    137137
    138138    def skip(self):
     139        if self.current_block.is_sequence():
     140            print("Skip the next phase in sequence")
     141            self.current_block.skip()
     142            if self.current_block.is_terminated():
     143                if self.upcoming_blocks():
     144                    self.current_block = self.upcoming_blocks()[0]
     145                else:
     146                    self.abort()
     147            return
    139148        if self.current_block_is_final():
    140149            print("Time over")
    141150            self.abort()
    142             return
    143         if self.current_block.is_sequence():
    144             print("Skip the next phase in sequence")
    145             self.current_block.skip()
    146             if self.current_block.completed():
    147                 self.current_block = self.upcoming_blocks()[0]
    148151            return
    149152        index = self.blocks.index(self.current_block)
     
    173176        if not self.is_completed():
    174177            self.current_block.tick(ticks)
    175             if self.current_block.completed():
     178            if self.current_block.is_completed():
    176179                if self.current_block_is_final():
    177180                    self._state = "completed"
  • flowtimer/main.py

    r0384305 r813e855  
    6969                                           orient="horizontal", length=600, mode="determinate")
    7070        self.progressbar["maximum"] = 59
    71         self.progressbar.pack(side='top')
     71        self.progressbar.pack(side='top', ipady=30)
    7272        self.label_duration = tk.Label(self.center_frame, bg='green')
    7373        self.label_duration.pack(side='top', fill='both', expand=True)
     
    124124        current_process = self.after(1000, self.tick)
    125125        if self.schedule.is_terminated():
    126             self.label_sequence.config(text=("\n" + "\nTime over !"),
     126            self.label_sequence.config(text="Time over !", font='times 22',
    127127                                       bg=self.colors_for_phase("Completed").get('sequence_label'),
    128128                                       fg="white")
    129             self.label_duration.config(text="", bg=self.colors_for_phase("Completed").get('duration_label'),
     129            self.label_duration.config(text="",
     130                                       bg=self.colors_for_phase("Completed").get('duration_label'),
    130131                                       fg="white")
    131132            self.progressbar.pack_forget()
     
    147148                                       fg="white")
    148149            self.label_duration.config(text=self.current_time_status(), font='times 22',
    149                                        bg=colors.get('duration_label'),
     150                                       bg=colors.get('widget'),
    150151                                       fg="white")
    151152            self.center_frame.configure(bg=colors.get('center_frame'))
  • tests/test_phase.py

    r0384305 r813e855  
    2020        phase.start()
    2121        assert phase.state == "running"
    22         assert phase.running() is True
     22        assert phase.is_running() is True
    2323
    2424    def test_phase_pause(self):
     
    2727        phase.pause()
    2828        assert phase.state == "paused"
    29         assert phase.paused() is True
     29        assert phase.is_paused() is True
    3030
    3131    def test_phase_abort(self):
     
    3333        phase.abort()
    3434        assert phase.state == "aborted"
    35         assert phase.aborted() is True
     35        assert phase.is_aborted() is True
    3636
    3737    def test_phase_tick(self):
     
    4747        phase.tick(300)
    4848        assert phase.ticks_left == 0
    49         assert phase.completed() is True
     49        assert phase.is_completed() is True
    5050
    5151    def test_phase_tick_beyond_completion(self):
  • tests/test_recurring_phase_sequence.py

    r0384305 r813e855  
    22import json
    33
    4 from flowtimer.Phase import Phase
    54from flowtimer.RecurringPhaseSequence import RecurringPhaseSequence
    65
     
    2322        json_string = recurring_phase_sequence.to_json()
    2423        data = json.loads(json_string)
    25         assert data['state'] == "initial"
     24        assert data['_state'] == "initial"
    2625        assert data['initial_repetitions'] == 3
    2726        assert data['passes_left'] == 3
     
    2928
    3029    def test_initial_state(self, recurring_phase_sequence):
    31         assert recurring_phase_sequence.state == "initial"
     30        assert recurring_phase_sequence.state() == "initial"
    3231        assert recurring_phase_sequence.current_phase.title == "Tasking"
    3332        assert recurring_phase_sequence.passes_left == 3
     
    5756
    5857    def test_completed(self, recurring_phase_sequence):
    59         assert not recurring_phase_sequence.completed()
     58        assert not recurring_phase_sequence.is_completed()
    6059        for _ in range(3):
    6160            for phase in recurring_phase_sequence.phases:
    6261                recurring_phase_sequence.tick(phase.initial_ticks)
    63         assert recurring_phase_sequence.completed()
     62        assert recurring_phase_sequence.is_completed()
    6463
    6564    def test_abort(self, recurring_phase_sequence):
    6665        recurring_phase_sequence.abort()
    67         assert recurring_phase_sequence.state == "aborted"
    68         assert recurring_phase_sequence.current_phase.aborted()
     66        assert recurring_phase_sequence.state() == "aborted"
     67        assert recurring_phase_sequence.current_phase.is_aborted()
    6968
    7069    def test_tick_progression(self, recurring_phase_sequence):
  • tests/test_schedule.py

    r0384305 r813e855  
    2323        assert schedule.blocks == [phase1, schedule.blocks[1]]
    2424        assert schedule.current_block == phase1
    25         assert schedule.state == "initial"
     25        assert schedule.state() == "initial"
    2626
    2727    def test_default_json_string(self):
     
    4848        schedule, phase1, _, _ = setup_schedule
    4949        schedule.start()
    50         assert schedule.state == "running"
     50        assert schedule.state() == "running"
    5151        # assert phase1.ticks_left < phase1.initial_ticks  # Assuming the phase reduces ticks when started
    5252
     
    5454        schedule, _, _, _ = setup_schedule
    5555        schedule.start()
    56         assert schedule.running() is True
     56        assert schedule.is_running() is True
    5757        schedule.pause()
    58         assert schedule.running() is False
     58        assert schedule.is_running() is False
    5959
    6060    def test_paused(self, setup_schedule):
    6161        schedule, _, _, _ = setup_schedule
    6262        schedule.pause()
    63         assert schedule.paused() is True
     63        assert schedule.is_paused() is True
    6464
    6565    def test_abort(self, setup_schedule):
    6666        schedule, _, _, _ = setup_schedule
    6767        schedule.abort()
    68         assert schedule.state == "aborted"
     68        assert schedule.state() == "aborted"
    6969
    7070    def test_completed(self, setup_schedule):
     
    7474        schedule.tick(phase1.initial_ticks)  # Complete phase1
    7575        schedule.tick(sequence.initial_ticks)  # Complete sequence
    76         assert schedule.completed() is True
    77         assert schedule.state == "completed"
     76        assert schedule.is_completed() is True
     77        assert schedule.state() == "completed"
    7878
    7979    def test_advance_to_next_block(self, setup_schedule):
Note: See TracChangeset for help on using the changeset viewer.