diff options
Diffstat (limited to 'helpers/actions/wait.py')
-rw-r--r-- | helpers/actions/wait.py | 38 |
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 @@ | |||
1 | import threading | ||
2 | |||
3 | def 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 | |||
16 | def 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 | |||
33 | def 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() | ||