From: Ismaƫl Bouya Date: Wed, 27 Jul 2016 00:17:39 +0000 (+0200) Subject: Add other_only flag to stop_all_actions X-Git-Tag: 1.0.0~13 X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FProjets%2FPython%2FMusicSampler.git;a=commitdiff_plain;h=62a8b07a2264101fd6d9c201267966e3c5de0cd4 Add other_only flag to stop_all_actions --- diff --git a/helpers/action.py b/helpers/action.py index 6ac47b1..4b5a71d 100644 --- a/helpers/action.py +++ b/helpers/action.py @@ -80,10 +80,11 @@ class Action: error_print("Unknown action {}".format(self.action)) self.fail() - def on_enter_loaded_running(self): + def on_enter_loaded_running(self, key_start_time): debug_print(self.description()) if hasattr(actions, self.action): - getattr(actions, self.action).run(self, **self.arguments) + getattr(actions, self.action).run(self, + key_start_time=key_start_time, **self.arguments) def poll_loaded(self): self.key.callback_action_ready(self, diff --git a/helpers/actions/stop_all_actions.py b/helpers/actions/stop_all_actions.py index f3fc5fb..4ea875a 100644 --- a/helpers/actions/stop_all_actions.py +++ b/helpers/actions/stop_all_actions.py @@ -1,5 +1,14 @@ -def run(action, **kwargs): - action.mapping.stop_all_running() +def run(action, key_start_time=0, other_only=False, **kwargs): + if other_only: + action.mapping.stop_all_running( + except_key=action.key, + key_start_time=key_start_time) + else: + action.mapping.stop_all_running() -def description(action, **kwargs): - return "stopping all actions" +def description(action, other_only=False, **kwargs): + message = "stopping all actions" + if other_only: + message += " except this key" + + return message diff --git a/helpers/key.py b/helpers/key.py index 2f94153..b5c1af9 100644 --- a/helpers/key.py +++ b/helpers/key.py @@ -191,7 +191,7 @@ class Key(ButtonBehavior, Widget): for self.current_action in self.actions: if self.parent.keep_running(self, start_time): self.list_actions() - self.current_action.run() + self.current_action.run(start_time) self.list_actions(last_action_finished=True) self.parent.finished_running(self, start_time) diff --git a/helpers/mapping.py b/helpers/mapping.py index dbc1a81..bb20e67 100644 --- a/helpers/mapping.py +++ b/helpers/mapping.py @@ -169,11 +169,13 @@ class Mapping(RelativeLayout): self.ready_color = [1, 165/255, 0, 1] ## Some global actions - def stop_all_running(self): + def stop_all_running(self, except_key=None, key_start_time=0): running = self.running - self.running = [] + self.running = [r for r in running\ + if r[0] == except_key and r[1] == key_start_time] for (key, start_time) in running: - key.interrupt() + if (key, start_time) != (except_key, key_start_time): + key.interrupt() # Master volume methods @property