Changeset a438158 in flowtimer
- Timestamp:
- 08/23/24 17:38:20 (9 months ago)
- Branches:
- guix
- Children:
- 0ec1bff
- Parents:
- bd94da0
- Location:
- flowtimer
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
flowtimer/Phase.py
rbd94da0 ra438158 51 51 52 52 def is_sequence(self): 53 return False 53 return False 54 54 55 55 def abort(self): -
flowtimer/RecurringPhaseSequence.py
rbd94da0 ra438158 73 73 74 74 def finished(self): 75 return (self.passes_left < 1) and (not self.upcoming_phases_in_pass()) 75 return ((self.passes_left < 1) and 76 (not self.upcoming_phases_in_pass() and 77 self.current_phase.finished())) 76 78 77 79 def abort(self): … … 88 90 return 89 91 else: 92 print("Sequence finished") 90 93 if self.passes_left == 0: 91 94 self.abort() -
flowtimer/Schedule.py
rbd94da0 ra438158 1 1 import json 2 from flowtimer.Phase import Phase 3 from flowtimer.RecurringPhaseSequence import RecurringPhaseSequence 2 4 3 5 """ 4 6 I represent a Schedule consisting of blocks. Blocks can be a single phase or 5 a sequence of phases. 7 a sequence of phases. 6 8 """ 7 9 … … 9 11 class Schedule: 10 12 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] 13 def __init__(self, title, blocks): 14 assert blocks is not [] 15 self.title = title 16 self.blocks = blocks 17 self.current_block = blocks[0] 15 18 self.state = "initial" 19 20 @classmethod 21 def default_json_string(cls): 22 return json.dumps( 23 {"title": "Default", 24 "blocks": [ 25 {"type": "Phase", 26 "title": "MorningHuddle", 27 "initial_ticks": 900 28 }, 29 {"type": "Sequence", 30 "title": "AM", 31 "sequence": [ 32 { 33 "title": "Tasking", 34 "initial_ticks": 120 35 }, 36 { 37 "title": "Working", 38 "initial_ticks": 5400 39 }, 40 { 41 "title": "Syncing", 42 "initial_ticks": 300 43 }, 44 { 45 "title": "Break", 46 "initial_ticks": 600 47 } 48 ], 49 "initial_repetitions": 2 50 } 51 ] 52 } 53 ) 54 55 @classmethod 56 def from_json(cls, a_json_string): 57 def custom_object_hook(d): 58 if 'title' in d and 'blocks' in d: 59 return Schedule(d['title'], d['blocks']) 60 if 'title' in d and 'initial_ticks' in d: 61 return Phase(d['title'], d['initial_ticks']) 62 if 'sequence' in d and 'initial_repetitions' in d: 63 return RecurringPhaseSequence(d["title"], d['sequence'], d['initial_repetitions']) 64 print("Wrong format") 65 return d 66 return json.loads(a_json_string, object_hook=custom_object_hook) 67 68 @classmethod 69 def default(cls): 70 return cls.from_json(cls.default_json_string()) 16 71 17 72 def to_json(self): … … 36 91 37 92 def finished(self): 38 if (self.current_block.finished()) and (self.block _list[-1] == self.current_block):93 if (self.current_block.finished()) and (self.blocks[-1] == self.current_block): 39 94 self.state = "finished" 40 95 return True … … 43 98 44 99 def skip(self): 45 if self.current_block.is_sequence :100 if self.current_block.is_sequence(): 46 101 self.current_block.skip() 47 else: 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] 102 print("Skip the next phase in sequence") 103 return 104 if self.current_block_is_final(): 105 print("Time over") 106 self.abort() 107 return 108 print("Jump to next block") 109 index = self.blocks.index(self.current_block) 110 self.current_block = self.blocks[index+1] 111 return 53 112 54 113 def total_ticks_left(self): … … 57 116 58 117 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:]118 index = self.blocks.index(self.current_block) 119 if index < len(self.blocks): 120 return self.blocks[index+1:] 62 121 return [] 63 122 64 123 def current_block_is_final(self): 65 index = self.block _list.index(self.current_block)66 return index == (len(self.block _list) - 1)124 index = self.blocks.index(self.current_block) 125 return index == (len(self.blocks) - 1) 67 126 68 def tick(self, duration):127 def tick(self, ticks): 69 128 if not self.finished(): 70 self.current_block.tick( duration)129 self.current_block.tick(ticks) 71 130 if self.current_block.finished(): 72 131 if self.current_block_is_final(): -
flowtimer/configs/default.json
rbd94da0 ra438158 1 1 { "title": "Default", 2 " schedule": [2 "blocks": [ 3 3 {"type": "Phase", 4 4 "title": "MorningHuddle", -
flowtimer/main.py
rbd94da0 ra438158 3 3 from tkinter import filedialog 4 4 from Schedule import Schedule 5 from RecurringPhaseSequence import RecurringPhaseSequence6 5 from PIL import Image, ImageTk 7 6 from pathlib import Path … … 162 161 def skip(self): 163 162 self.schedule.skip() 163 if self.schedule.finished(): 164 print("finished") 164 165 165 166 def toggle_tick(self): … … 207 208 208 209 def change_config(self, json_string): 209 self.schedule = Schedule ([RecurringPhaseSequence.from_json(json_string)])210 self.schedule = Schedule.from_json(json_string) 210 211 211 212 def load_config(self, file_name=Path(__file__).parent / 'configs' / 'default.json'):
Note:
See TracChangeset
for help on using the changeset viewer.