diff options
Diffstat (limited to 'helpers')
-rw-r--r-- | helpers/key.py | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/helpers/key.py b/helpers/key.py index 9099f00..c21f9ae 100644 --- a/helpers/key.py +++ b/helpers/key.py | |||
@@ -78,7 +78,7 @@ class Key(ButtonBehavior, Widget): | |||
78 | 'trigger': 'run', | 78 | 'trigger': 'run', |
79 | 'source': 'loaded', | 79 | 'source': 'loaded', |
80 | 'dest': 'loaded_running', | 80 | 'dest': 'loaded_running', |
81 | 'after': 'finish', | 81 | 'after': ['run_actions', 'finish'], |
82 | # if a child, like loaded_no_actions, has no transitions, then it is | 82 | # if a child, like loaded_no_actions, has no transitions, then it is |
83 | # bubbled to the parent, and we don't want that. | 83 | # bubbled to the parent, and we don't want that. |
84 | 'conditions': ['is_loaded'] | 84 | 'conditions': ['is_loaded'] |
@@ -125,6 +125,8 @@ class Key(ButtonBehavior, Widget): | |||
125 | 125 | ||
126 | def __init__(self, **kwargs): | 126 | def __init__(self, **kwargs): |
127 | self.actions = [] | 127 | self.actions = [] |
128 | self.current_action = None | ||
129 | |||
128 | Machine(model=self, states=self.STATES, | 130 | Machine(model=self, states=self.STATES, |
129 | transitions=self.TRANSITIONS, initial='initial', | 131 | transitions=self.TRANSITIONS, initial='initial', |
130 | ignore_invalid_triggers=True, queued=True) | 132 | ignore_invalid_triggers=True, queued=True) |
@@ -168,18 +170,16 @@ class Key(ButtonBehavior, Widget): | |||
168 | else: | 170 | else: |
169 | self.no_actions() | 171 | self.no_actions() |
170 | 172 | ||
171 | def on_enter_loaded_running(self, modifiers): | 173 | def run_actions(self, modifiers): |
172 | self.parent.parent.ids['KeyList'].append(self.key_sym) | 174 | self.parent.parent.ids['KeyList'].append(self.key_sym) |
173 | debug_print("running actions for {}".format(self.key_sym)) | 175 | debug_print("running actions for {}".format(self.key_sym)) |
174 | start_time = time.time() | 176 | start_time = time.time() |
175 | self.parent.start_running(self, start_time) | 177 | self.parent.start_running(self, start_time) |
176 | action_number = 0 | ||
177 | for self.current_action in self.actions: | 178 | for self.current_action in self.actions: |
178 | if self.parent.keep_running(self, start_time): | 179 | if self.parent.keep_running(self, start_time): |
179 | self.list_actions(action_number=action_number + 0.5) | 180 | self.list_actions() |
180 | self.current_action.run() | 181 | self.current_action.run() |
181 | action_number += 1 | 182 | self.list_actions(last_action_finished=True) |
182 | self.list_actions(action_number=action_number) | ||
183 | 183 | ||
184 | self.parent.finished_running(self, start_time) | 184 | self.parent.finished_running(self, start_time) |
185 | 185 | ||
@@ -217,6 +217,23 @@ class Key(ButtonBehavior, Widget): | |||
217 | def add_action(self, action_name, **arguments): | 217 | def add_action(self, action_name, **arguments): |
218 | self.actions.append(Action(action_name, self, **arguments)) | 218 | self.actions.append(Action(action_name, self, **arguments)) |
219 | 219 | ||
220 | def list_actions(self, action_number=0): | 220 | def list_actions(self, last_action_finished=False): |
221 | self.parent.parent.ids['ActionList'].update_list(self, action_number) | 221 | not_running = (not self.is_loaded_running()) |
222 | 222 | current_action_seen = False | |
223 | action_descriptions = [] | ||
224 | for action in self.actions: | ||
225 | if not_running: | ||
226 | state = "inactive" | ||
227 | elif last_action_finished: | ||
228 | state = "done" | ||
229 | elif current_action_seen: | ||
230 | state = "pending" | ||
231 | elif action == self.current_action: | ||
232 | current_action_seen = True | ||
233 | state = "current" | ||
234 | else: | ||
235 | state = "done" | ||
236 | action_descriptions.append([action.description(), state]) | ||
237 | self.parent.parent.ids['ActionList'].update_list( | ||
238 | self, | ||
239 | action_descriptions) | ||