diff options
Diffstat (limited to 'helpers/action.py')
-rw-r--r-- | helpers/action.py | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/helpers/action.py b/helpers/action.py index eaa419b..99cd399 100644 --- a/helpers/action.py +++ b/helpers/action.py | |||
@@ -6,6 +6,7 @@ from . import debug_print | |||
6 | class Action: | 6 | class Action: |
7 | action_types = [ | 7 | action_types = [ |
8 | 'command', | 8 | 'command', |
9 | 'interrupt_wait', | ||
9 | 'pause', | 10 | 'pause', |
10 | 'play', | 11 | 'play', |
11 | 'seek', | 12 | 'seek', |
@@ -88,7 +89,11 @@ class Action: | |||
88 | for music in self.music_list(music): | 89 | for music in self.music_list(music): |
89 | music.seek(value=value, delta=delta) | 90 | music.seek(value=value, delta=delta) |
90 | 91 | ||
91 | def stop(self, music=None, fade_out=0, wait=False, **kwargs): | 92 | def interrupt_wait(self, wait_id=None): |
93 | self.mapping.interrupt_wait(wait_id) | ||
94 | |||
95 | def stop(self, music=None, fade_out=0, wait=False, | ||
96 | set_wait_id=None, **kwargs): | ||
92 | previous = None | 97 | previous = None |
93 | for music in self.music_list(music): | 98 | for music in self.music_list(music): |
94 | if music.is_loaded_paused() or music.is_loaded_playing(): | 99 | if music.is_loaded_paused() or music.is_loaded_playing(): |
@@ -99,7 +104,10 @@ class Action: | |||
99 | music.stop(fade_out=fade_out) | 104 | music.stop(fade_out=fade_out) |
100 | 105 | ||
101 | if previous is not None: | 106 | if previous is not None: |
102 | previous.stop(fade_out=fade_out, wait=wait) | 107 | previous.stop( |
108 | fade_out=fade_out, | ||
109 | wait=wait, | ||
110 | set_wait_id=set_wait_id) | ||
103 | 111 | ||
104 | def stop_all_actions(self, **kwargs): | 112 | def stop_all_actions(self, **kwargs): |
105 | self.mapping.stop_all_running() | 113 | self.mapping.stop_all_running() |
@@ -110,7 +118,10 @@ class Action: | |||
110 | else: | 118 | else: |
111 | self.mapping.set_master_volume(value, delta=delta, fade=fade) | 119 | self.mapping.set_master_volume(value, delta=delta, fade=fade) |
112 | 120 | ||
113 | def wait(self, duration=0, music=None, **kwargs): | 121 | def wait(self, duration=0, music=None, set_wait_id=None, **kwargs): |
122 | if set_wait_id is not None: | ||
123 | self.mapping.add_wait_id(set_wait_id, self) | ||
124 | |||
114 | self.sleep_event = threading.Event() | 125 | self.sleep_event = threading.Event() |
115 | 126 | ||
116 | if music is not None: | 127 | if music is not None: |
@@ -123,6 +134,9 @@ class Action: | |||
123 | def command_print(self, command="", **kwargs): | 134 | def command_print(self, command="", **kwargs): |
124 | return "running command {}".format(command) | 135 | return "running command {}".format(command) |
125 | 136 | ||
137 | def interrupt_wait_print(self, wait_id=None, **kwargs): | ||
138 | return "interrupt wait with id {}".format(wait_id) | ||
139 | |||
126 | def pause_print(self, music=None, **kwargs): | 140 | def pause_print(self, music=None, **kwargs): |
127 | if music is not None: | 141 | if music is not None: |
128 | return "pausing « {} »".format(music.name) | 142 | return "pausing « {} »".format(music.name) |
@@ -161,7 +175,9 @@ class Action: | |||
161 | 175 | ||
162 | return message | 176 | return message |
163 | 177 | ||
164 | def stop_print(self, music=None, fade_out=0, wait=False, **kwargs): | 178 | def stop_print(self, music=None, fade_out=0, wait=False, |
179 | set_wait_id=None, **kwargs): | ||
180 | |||
165 | message = "stopping " | 181 | message = "stopping " |
166 | if music is not None: | 182 | if music is not None: |
167 | message += "music « {} »".format(music.name) | 183 | message += "music « {} »".format(music.name) |
@@ -171,7 +187,11 @@ class Action: | |||
171 | if fade_out > 0: | 187 | if fade_out > 0: |
172 | message += " with {}s fadeout".format(fade_out) | 188 | message += " with {}s fadeout".format(fade_out) |
173 | if wait: | 189 | if wait: |
174 | message += " (waiting the end of fadeout)" | 190 | if set_wait_id is not None: |
191 | message += " (waiting the end of fadeout, with id {})"\ | ||
192 | .format(set_wait_id) | ||
193 | else: | ||
194 | message += " (waiting the end of fadeout)" | ||
175 | 195 | ||
176 | return message | 196 | return message |
177 | 197 | ||
@@ -217,17 +237,22 @@ class Action: | |||
217 | 237 | ||
218 | return message | 238 | return message |
219 | 239 | ||
220 | def wait_print(self, duration=0, music=None, **kwargs): | 240 | def wait_print(self, duration=0, music=None, set_wait_id=None, **kwargs): |
241 | message = "" | ||
221 | if music is None: | 242 | if music is None: |
222 | return "waiting {}s" \ | 243 | message += "waiting {}s" \ |
223 | .format(duration) | 244 | .format(duration) |
224 | elif duration == 0: | 245 | elif duration == 0: |
225 | return "waiting the end of « {} »" \ | 246 | message += "waiting the end of « {} »" \ |
226 | .format(music.name) | 247 | .format(music.name) |
227 | else: | 248 | else: |
228 | return "waiting the end of « {} » + {}s" \ | 249 | message += "waiting the end of « {} » + {}s" \ |
229 | .format(music.name, duration) | 250 | .format(music.name, duration) |
230 | 251 | ||
252 | if set_wait_id is not None: | ||
253 | message += " (setting id = {})".format(set_wait_id) | ||
254 | |||
255 | return message | ||
231 | 256 | ||
232 | # Interruptions | 257 | # Interruptions |
233 | def wait_interrupt(self, duration=0, music=None, **kwargs): | 258 | def wait_interrupt(self, duration=0, music=None, **kwargs): |