]>
Commit | Line | Data |
---|---|---|
c4f4f2a1 IB |
1 | import threading |
2 | ||
3 | def run(action, duration=0, music=None, set_wait_id=None, **kwargs): | |
21ffec31 | 4 | action.mapping.add_wait(action, wait_id=set_wait_id) |
c4f4f2a1 IB |
5 | |
6 | action.sleep_event = threading.Event() | |
6c42e32d IB |
7 | action.sleep_event_timer = threading.Timer( |
8 | duration, | |
9 | action.sleep_event.set) | |
c4f4f2a1 IB |
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): | |
6a327173 | 18 | formats = [] |
c4f4f2a1 IB |
19 | message = "" |
20 | if music is None: | |
6a327173 IB |
21 | message += "waiting {}s" |
22 | formats.append(duration) | |
c4f4f2a1 | 23 | elif duration == 0: |
6a327173 IB |
24 | message += "waiting the end of « {} »" |
25 | formats.append(music.name) | |
c4f4f2a1 | 26 | else: |
6a327173 IB |
27 | message += "waiting the end of « {} » + {}s" |
28 | formats.append(music.name) | |
29 | formats.append(duration) | |
c4f4f2a1 IB |
30 | |
31 | if set_wait_id is not None: | |
6a327173 IB |
32 | message += " (setting id = {})" |
33 | formats.append(set_wait_id) | |
c4f4f2a1 | 34 | |
6a327173 | 35 | return _(message).format(*formats) |
c4f4f2a1 IB |
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() |