]>
Commit | Line | Data |
---|---|---|
1 | import threading | |
2 | ||
3 | def run(action, duration=0, music=None, set_wait_id=None, **kwargs): | |
4 | action.mapping.add_wait(action, wait_id=set_wait_id) | |
5 | ||
6 | action.sleep_event = threading.Event() | |
7 | action.sleep_event_timer = threading.Timer( | |
8 | duration, | |
9 | action.sleep_event.set) | |
10 | ||
11 | if music is not None: | |
12 | music.wait_end() | |
13 | ||
14 | action.sleep_event_timer.start() | |
15 | action.sleep_event.wait() | |
16 | ||
17 | def description(action, duration=0, music=None, set_wait_id=None, **kwargs): | |
18 | formats = [] | |
19 | message = "" | |
20 | if music is None: | |
21 | message += "waiting {}s" | |
22 | formats.append(duration) | |
23 | elif duration == 0: | |
24 | message += "waiting the end of « {} »" | |
25 | formats.append(music.name) | |
26 | else: | |
27 | message += "waiting the end of « {} » + {}s" | |
28 | formats.append(music.name) | |
29 | formats.append(duration) | |
30 | ||
31 | if set_wait_id is not None: | |
32 | message += " (setting id = {})" | |
33 | formats.append(set_wait_id) | |
34 | ||
35 | return _(message).format(*formats) | |
36 | ||
37 | def interrupt(action, duration=0, music=None, **kwargs): | |
38 | if action.sleep_event is not None: | |
39 | action.sleep_event.set() | |
40 | action.sleep_event_timer.cancel() | |
41 | if music is not None: | |
42 | music.wait_event.set() |