From c4f4f2a1d330d8e09021619bbb8dcaac4df0a602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Tue, 26 Jul 2016 16:27:51 +0200 Subject: Move actions to separate files --- helpers/actions/stop.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 helpers/actions/stop.py (limited to 'helpers/actions/stop.py') diff --git a/helpers/actions/stop.py b/helpers/actions/stop.py new file mode 100644 index 0000000..88cc66d --- /dev/null +++ b/helpers/actions/stop.py @@ -0,0 +1,42 @@ +def run(action, music=None, fade_out=0, wait=False, + set_wait_id=None, **kwargs): + previous = None + for music in action.music_list(music): + if music.is_loaded_paused() or music.is_loaded_playing(): + if previous is not None: + previous.stop(fade_out=fade_out) + previous = music + else: + music.stop(fade_out=fade_out) + + if previous is not None: + action.waiting_music = previous + previous.stop( + fade_out=fade_out, + wait=wait, + set_wait_id=set_wait_id) + +def description(action, music=None, fade_out=0, wait=False, + set_wait_id=None, **kwargs): + + message = "stopping " + if music is not None: + message += "music « {} »".format(music.name) + else: + message += "all musics" + + if fade_out > 0: + message += " with {}s fadeout".format(fade_out) + if wait: + if set_wait_id is not None: + message += " (waiting the end of fadeout, with id {})"\ + .format(set_wait_id) + else: + message += " (waiting the end of fadeout)" + + return message + +def interrupt(action, music=None, fade_out=0, wait=False, + set_wait_id=None, **kwargs): + if action.waiting_music is not None: + action.waiting_music.wait_event.set() -- cgit v1.2.3