]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/commitdiff
Improve actions listing
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Tue, 26 Jul 2016 22:51:48 +0000 (00:51 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Tue, 26 Jul 2016 22:51:48 +0000 (00:51 +0200)
helpers/key.py
music_sampler.py

index 9099f00925b28e0764aa4eb6f6afa1743a595993..c21f9ae2a0bf8ffa60f927e5646a6f65528c8b50 100644 (file)
@@ -78,7 +78,7 @@ class Key(ButtonBehavior, Widget):
             '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']
@@ -125,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)
@@ -168,18 +170,16 @@ class Key(ButtonBehavior, Widget):
         else:
             self.no_actions()
 
-    def on_enter_loaded_running(self, modifiers):
+    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)
 
@@ -217,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)
index 41b71be5bd1bd96502b18981c96725bef8554446..c10b6349701210a2ce583bb88543559a6fb0dd4f 100644 (file)
@@ -62,21 +62,18 @@ class ActionList(RelativeLayout):
     action_title = StringProperty("")
     action_list = ListProperty([])
 
-    def update_list(self, key, action_number = 0):
+    def update_list(self, key, action_descriptions):
         self.action_title = "actions linked to key {}:".format(key.key_sym)
         self.action_list = []
 
-        action_descriptions = [action.description() for action in key.actions]
-
-        for index, description in enumerate(action_descriptions):
-            if index < int(action_number):
+        for [action, status] in action_descriptions:
+            if status == "done":
                 icon = "✓"
-            elif index + 0.5 == action_number:
+            elif status == "current":
                 icon = "✅"
             else:
                 icon = " "
-
-            self.action_list.append([icon, description])
+            self.action_list.append([icon, action])
 
 class Screen(FloatLayout):
     pass