aboutsummaryrefslogtreecommitdiff
path: root/helpers/actions/wait.py
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2016-07-26 16:35:05 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2016-07-26 16:35:05 +0200
commite4917bcc6c5355a82f05880a389d0a1fd868561d (patch)
tree56f030600ad200632d0e9030c3b470dcb846215d /helpers/actions/wait.py
parentdb905e0706ab9a1f92102e86f677c66371be4621 (diff)
parentc4f4f2a1d330d8e09021619bbb8dcaac4df0a602 (diff)
downloadMusicSampler-e4917bcc6c5355a82f05880a389d0a1fd868561d.tar.gz
MusicSampler-e4917bcc6c5355a82f05880a389d0a1fd868561d.tar.zst
MusicSampler-e4917bcc6c5355a82f05880a389d0a1fd868561d.zip
Merge branch 'actions_cleanup'
Diffstat (limited to 'helpers/actions/wait.py')
-rw-r--r--helpers/actions/wait.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/helpers/actions/wait.py b/helpers/actions/wait.py
new file mode 100644
index 0000000..f7d2a78
--- /dev/null
+++ b/helpers/actions/wait.py
@@ -0,0 +1,38 @@
1import threading
2
3def run(action, duration=0, music=None, set_wait_id=None, **kwargs):
4 if set_wait_id is not None:
5 action.mapping.add_wait_id(set_wait_id, action)
6
7 action.sleep_event = threading.Event()
8 action.sleep_event_timer = threading.Timer(duration, action.sleep_event.set)
9
10 if music is not None:
11 music.wait_end()
12
13 action.sleep_event_timer.start()
14 action.sleep_event.wait()
15
16def description(action, duration=0, music=None, set_wait_id=None, **kwargs):
17 message = ""
18 if music is None:
19 message += "waiting {}s" \
20 .format(duration)
21 elif duration == 0:
22 message += "waiting the end of « {} »" \
23 .format(music.name)
24 else:
25 message += "waiting the end of « {} » + {}s" \
26 .format(music.name, duration)
27
28 if set_wait_id is not None:
29 message += " (setting id = {})".format(set_wait_id)
30
31 return message
32
33def interrupt(action, duration=0, music=None, **kwargs):
34 if action.sleep_event is not None:
35 action.sleep_event.set()
36 action.sleep_event_timer.cancel()
37 if music is not None:
38 music.wait_event.set()