]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blame - music_sampler/actions/wait.py
Make music_sampler multilingual
[perso/Immae/Projets/Python/MusicSampler.git] / music_sampler / actions / wait.py
CommitLineData
c4f4f2a1
IB
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()
6c42e32d
IB
8 action.sleep_event_timer = threading.Timer(
9 duration,
10 action.sleep_event.set)
c4f4f2a1
IB
11
12 if music is not None:
13 music.wait_end()
14
15 action.sleep_event_timer.start()
16 action.sleep_event.wait()
17
18def description(action, duration=0, music=None, set_wait_id=None, **kwargs):
6a327173 19 formats = []
c4f4f2a1
IB
20 message = ""
21 if music is None:
6a327173
IB
22 message += "waiting {}s"
23 formats.append(duration)
c4f4f2a1 24 elif duration == 0:
6a327173
IB
25 message += "waiting the end of « {} »"
26 formats.append(music.name)
c4f4f2a1 27 else:
6a327173
IB
28 message += "waiting the end of « {} » + {}s"
29 formats.append(music.name)
30 formats.append(duration)
c4f4f2a1
IB
31
32 if set_wait_id is not None:
6a327173
IB
33 message += " (setting id = {})"
34 formats.append(set_wait_id)
c4f4f2a1 35
6a327173 36 return _(message).format(*formats)
c4f4f2a1
IB
37
38def interrupt(action, duration=0, music=None, **kwargs):
39 if action.sleep_event is not None:
40 action.sleep_event.set()
41 action.sleep_event_timer.cancel()
42 if music is not None:
43 music.wait_event.set()