X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=helpers%2Fkey.py;h=c21f9ae2a0bf8ffa60f927e5646a6f65528c8b50;hb=b17aed6aba689f484a4932d99b30aff1bdee7176;hp=bf46eebc73237520770daeb01dc225448a4685e4;hpb=e4917bcc6c5355a82f05880a389d0a1fd868561d;p=perso%2FImmae%2FProjets%2FPython%2FMusicSampler.git diff --git a/helpers/key.py b/helpers/key.py index bf46eeb..c21f9ae 100644 --- a/helpers/key.py +++ b/helpers/key.py @@ -30,7 +30,8 @@ class Key(ButtonBehavior, Widget): { 'trigger': 'fail', 'source': 'configuring', - 'dest': 'failed' + 'dest': 'failed', + 'after': 'key_loaded_callback' }, { 'trigger': 'success', @@ -42,6 +43,7 @@ class Key(ButtonBehavior, Widget): 'trigger': 'no_config', 'source': 'configuring', 'dest': 'loaded_no_config', + 'after': 'key_loaded_callback' }, { 'trigger': 'load', @@ -51,28 +53,32 @@ class Key(ButtonBehavior, Widget): { 'trigger': 'fail', 'source': 'loading', - 'dest': 'failed' + 'dest': 'failed', + 'after': 'key_loaded_callback' }, { 'trigger': 'success', 'source': 'loading', - 'dest': 'loaded' + 'dest': 'loaded', + 'after': 'key_loaded_callback' }, { 'trigger': 'no_actions', 'source': 'loading', 'dest': 'loaded_no_actions', + 'after': 'key_loaded_callback' }, { 'trigger': 'reload', - 'source': 'loaded', - 'dest': 'configuring' + 'source': ['loaded','failed'], + 'dest': 'configuring', + 'after': 'key_loaded_callback' }, { 'trigger': 'run', 'source': 'loaded', 'dest': 'loaded_running', - 'after': 'finish', + 'after': ['run_actions', 'finish'], # if a child, like loaded_no_actions, has no transitions, then it is # bubbled to the parent, and we don't want that. 'conditions': ['is_loaded'] @@ -90,6 +96,18 @@ class Key(ButtonBehavior, Widget): description = ListProperty([]) state = StringProperty("") + def get_alias_line_color(self): + if self.is_loaded_running(): + return [0, 0, 0, 1] + else: + return [120/255, 120/255, 120/255, 1] + + def set_alias_line_color(self): + pass + + line_color = AliasProperty(get_alias_line_color, set_alias_line_color, + bind=['state']) + def get_alias_color(self): if self.is_loaded_inactive(): return [1, 1, 1, 1] @@ -107,6 +125,8 @@ class Key(ButtonBehavior, Widget): def __init__(self, **kwargs): self.actions = [] + self.current_action = None + Machine(model=self, states=self.STATES, transitions=self.TRANSITIONS, initial='initial', ignore_invalid_triggers=True, queued=True) @@ -150,18 +170,16 @@ class Key(ButtonBehavior, Widget): else: self.no_actions() - def on_enter_loaded_running(self): + def run_actions(self, modifiers): self.parent.parent.ids['KeyList'].append(self.key_sym) debug_print("running actions for {}".format(self.key_sym)) start_time = time.time() self.parent.start_running(self, start_time) - action_number = 0 for self.current_action in self.actions: if self.parent.keep_running(self, start_time): - self.list_actions(action_number=action_number + 0.5) + self.list_actions() self.current_action.run() - action_number += 1 - self.list_actions(action_number=action_number) + self.list_actions(last_action_finished=True) self.parent.finished_running(self, start_time) @@ -171,6 +189,9 @@ class Key(ButtonBehavior, Widget): self.current_action.interrupt() # Callbacks + def key_loaded_callback(self): + self.parent.key_loaded_callback() + def callback_action_ready(self, action, success): if not success: self.fail() @@ -181,6 +202,7 @@ class Key(ButtonBehavior, Widget): def set_description(self, description): if description[0] is not None: self.description_title = str(description[0]) + self.description = [] for desc in description[1 :]: if desc is None: self.description.append("") @@ -195,6 +217,23 @@ class Key(ButtonBehavior, Widget): def add_action(self, action_name, **arguments): self.actions.append(Action(action_name, self, **arguments)) - def list_actions(self, action_number=0): - self.parent.parent.ids['ActionList'].update_list(self, action_number) - + def list_actions(self, last_action_finished=False): + not_running = (not self.is_loaded_running()) + current_action_seen = False + action_descriptions = [] + for action in self.actions: + if not_running: + state = "inactive" + elif last_action_finished: + state = "done" + elif current_action_seen: + state = "pending" + elif action == self.current_action: + current_action_seen = True + state = "current" + else: + state = "done" + action_descriptions.append([action.description(), state]) + self.parent.parent.ids['ActionList'].update_list( + self, + action_descriptions)