From 3aaddc9de62202a04ed84b3bf53e7ecab92ebf0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Sat, 23 Jul 2016 00:07:29 +0200 Subject: Add interrupt_wait action --- helpers/mapping.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'helpers/mapping.py') diff --git a/helpers/mapping.py b/helpers/mapping.py index 43cacf2..0c81af4 100644 --- a/helpers/mapping.py +++ b/helpers/mapping.py @@ -11,6 +11,7 @@ from .music_file import * from .mixer import Mixer from . import Config, gain, error_print from .music_effect import GainEffect +from .action import Action class Mapping(RelativeLayout): expected_keys = NumericProperty(0) @@ -27,6 +28,7 @@ class Mapping(RelativeLayout): self._keyboard = Window.request_keyboard(self._keyboard_closed, self) self._keyboard.bind(on_key_down=self._on_keyboard_down) self.running = [] + self.wait_ids = {} Clock.schedule_interval(self.not_all_keys_ready, 1) @property @@ -53,6 +55,18 @@ class Mapping(RelativeLayout): else: music.set_gain(db_gain) + def add_wait_id(self, wait_id, action_or_wait): + self.wait_ids[wait_id] = action_or_wait + + def interrupt_wait(self, wait_id): + if wait_id in self.wait_ids: + action_or_wait = self.wait_ids[wait_id] + del(self.wait_ids[wait_id]) + if isinstance(action_or_wait, Action): + action_or_wait.interrupt() + else: + action_or_wait.set() + def _keyboard_closed(self): self._keyboard.unbind(on_key_down=self._on_keyboard_down) self._keyboard = None -- cgit v1.2.3