diff options
Diffstat (limited to 'helpers/action.py')
-rw-r--r-- | helpers/action.py | 101 |
1 files changed, 59 insertions, 42 deletions
diff --git a/helpers/action.py b/helpers/action.py index 1a2abe2..218c316 100644 --- a/helpers/action.py +++ b/helpers/action.py | |||
@@ -51,58 +51,64 @@ class Action: | |||
51 | return self.mapping.open_files.values() | 51 | return self.mapping.open_files.values() |
52 | 52 | ||
53 | # Actions | 53 | # Actions |
54 | def command(self, command = "", **kwargs): | 54 | def command(self, command="", **kwargs): |
55 | # FIXME: todo | 55 | # FIXME: todo |
56 | pass | 56 | pass |
57 | 57 | ||
58 | def pause(self, music = None, **kwargs): | 58 | def pause(self, music=None, **kwargs): |
59 | for music in self.music_list(music): | 59 | for music in self.music_list(music): |
60 | if music.is_loaded_playing(): | 60 | if music.is_loaded_playing(): |
61 | music.pause() | 61 | music.pause() |
62 | 62 | ||
63 | def unpause(self, music = None, **kwargs): | 63 | def unpause(self, music=None, **kwargs): |
64 | for music in self.music_list(music): | 64 | for music in self.music_list(music): |
65 | if music.is_loaded_paused(): | 65 | if music.is_loaded_paused(): |
66 | music.unpause() | 66 | music.unpause() |
67 | 67 | ||
68 | def play(self, music = None, fade_in = 0, start_at = 0, | 68 | def play(self, music=None, fade_in=0, start_at=0, |
69 | restart_if_running = False, volume = 100, | 69 | restart_if_running=False, volume=100, |
70 | loop = 0, | 70 | loop=0, **kwargs): |
71 | **kwargs): | ||
72 | for music in self.music_list(music): | 71 | for music in self.music_list(music): |
73 | if restart_if_running: | 72 | if restart_if_running: |
74 | if music.is_not_stopped(): | 73 | if music.is_not_stopped(): |
75 | music.stop() | 74 | music.stop() |
76 | music.play(volume = volume, fade_in = fade_in, start_at = start_at, loop = loop) | 75 | music.play( |
77 | else: | 76 | volume=volume, |
78 | if not music.is_not_stopped(): | 77 | fade_in=fade_in, |
79 | music.play(volume = volume, fade_in = fade_in, start_at = start_at, loop = loop) | 78 | start_at=start_at, |
80 | 79 | loop=loop) | |
81 | def seek(self, music = None, value = 0, delta = False, **kwargs): | 80 | elif not music.is_not_stopped(): |
81 | music.play( | ||
82 | volume=volume, | ||
83 | fade_in=fade_in, | ||
84 | start_at=start_at, | ||
85 | loop=loop) | ||
86 | |||
87 | def seek(self, music=None, value=0, delta=False, **kwargs): | ||
82 | for music in self.music_list(music): | 88 | for music in self.music_list(music): |
83 | music.seek(value = value, delta = delta) | 89 | music.seek(value=value, delta=delta) |
84 | 90 | ||
85 | def stop(self, music = None, fade_out = 0, wait = False, **kwargs): | 91 | def stop(self, music=None, fade_out=0, wait=False, **kwargs): |
86 | previous = None | 92 | previous = None |
87 | for music in self.music_list(music): | 93 | for music in self.music_list(music): |
88 | if music.is_loaded_paused() or music.is_loaded_playing(): | 94 | if music.is_loaded_paused() or music.is_loaded_playing(): |
89 | if previous is not None: | 95 | if previous is not None: |
90 | previous.stop(fade_out = fade_out) | 96 | previous.stop(fade_out=fade_out) |
91 | previous = music | 97 | previous = music |
92 | 98 | ||
93 | if previous is not None: | 99 | if previous is not None: |
94 | previous.stop(fade_out = fade_out, wait = wait) | 100 | previous.stop(fade_out=fade_out, wait=wait) |
95 | 101 | ||
96 | def stop_all_actions(self, **kwargs): | 102 | def stop_all_actions(self, **kwargs): |
97 | self.mapping.stop_all_running() | 103 | self.mapping.stop_all_running() |
98 | 104 | ||
99 | def volume(self, music = None, value = 100, delta = False, **kwargs): | 105 | def volume(self, music=None, value=100, delta=False, **kwargs): |
100 | if music is not None: | 106 | if music is not None: |
101 | music.set_volume(value, delta = delta) | 107 | music.set_volume(value, delta=delta) |
102 | else: | 108 | else: |
103 | self.mapping.set_master_volume(value, delta = delta) | 109 | self.mapping.set_master_volume(value, delta=delta) |
104 | 110 | ||
105 | def wait(self, duration = 0, music = None, **kwargs): | 111 | def wait(self, duration=0, music=None, **kwargs): |
106 | self.sleep_event = threading.Event() | 112 | self.sleep_event = threading.Event() |
107 | 113 | ||
108 | if music is not None: | 114 | if music is not None: |
@@ -112,23 +118,23 @@ class Action: | |||
112 | self.sleep_event.wait() | 118 | self.sleep_event.wait() |
113 | 119 | ||
114 | # Action messages | 120 | # Action messages |
115 | def command_print(self, command = "", **kwargs): | 121 | def command_print(self, command="", **kwargs): |
116 | return "running command {}".format(command) | 122 | return "running command {}".format(command) |
117 | 123 | ||
118 | def pause_print(self, music = None, **kwargs): | 124 | def pause_print(self, music=None, **kwargs): |
119 | if music is not None: | 125 | if music is not None: |
120 | return "pausing « {} »".format(music.name) | 126 | return "pausing « {} »".format(music.name) |
121 | else: | 127 | else: |
122 | return "pausing all musics" | 128 | return "pausing all musics" |
123 | 129 | ||
124 | def unpause_print(self, music = None, **kwargs): | 130 | def unpause_print(self, music=None, **kwargs): |
125 | if music is not None: | 131 | if music is not None: |
126 | return "unpausing « {} »".format(music.name) | 132 | return "unpausing « {} »".format(music.name) |
127 | else: | 133 | else: |
128 | return "unpausing all musics" | 134 | return "unpausing all musics" |
129 | 135 | ||
130 | def play_print(self, music = None, fade_in = 0, start_at = 0, | 136 | def play_print(self, music=None, fade_in=0, start_at=0, |
131 | restart_if_running = False, volume = 100, loop = 0, **kwargs): | 137 | restart_if_running=False, volume=100, loop=0, **kwargs): |
132 | message = "starting " | 138 | message = "starting " |
133 | if music is not None: | 139 | if music is not None: |
134 | message += "« {} »".format(music.name) | 140 | message += "« {} »".format(music.name) |
@@ -153,7 +159,7 @@ class Action: | |||
153 | 159 | ||
154 | return message | 160 | return message |
155 | 161 | ||
156 | def stop_print(self, music = None, fade_out = 0, wait = False, **kwargs): | 162 | def stop_print(self, music=None, fade_out=0, wait=False, **kwargs): |
157 | message = "stopping " | 163 | message = "stopping " |
158 | if music is not None: | 164 | if music is not None: |
159 | message += "music « {} »".format(music.name) | 165 | message += "music « {} »".format(music.name) |
@@ -170,41 +176,52 @@ class Action: | |||
170 | def stop_all_actions_print(self, **kwargs): | 176 | def stop_all_actions_print(self, **kwargs): |
171 | return "stopping all actions" | 177 | return "stopping all actions" |
172 | 178 | ||
173 | def seek_print(self, music = None, value = 0, delta = False, **kwargs): | 179 | def seek_print(self, music=None, value=0, delta=False, **kwargs): |
174 | if delta: | 180 | if delta: |
175 | if music is not None: | 181 | if music is not None: |
176 | return "moving music « {} » by {:+d}s".format(music.name, value) | 182 | return "moving music « {} » by {:+d}s" \ |
183 | .format(music.name, value) | ||
177 | else: | 184 | else: |
178 | return "moving all musics by {:+d}s".format(value) | 185 | return "moving all musics by {:+d}s" \ |
186 | .format(value) | ||
179 | else: | 187 | else: |
180 | if music is not None: | 188 | if music is not None: |
181 | return "moving music « {} » to position {}s".format(music.name, value) | 189 | return "moving music « {} » to position {}s" \ |
190 | .format(music.name, value) | ||
182 | else: | 191 | else: |
183 | return "moving all musics to position {}s".format(value) | 192 | return "moving all musics to position {}s" \ |
193 | .format(value) | ||
184 | 194 | ||
185 | def volume_print(self, music = None, value = 100, delta = False, **kwargs): | 195 | def volume_print(self, music=None, value=100, delta=False, **kwargs): |
186 | if delta: | 196 | if delta: |
187 | if music is not None: | 197 | if music is not None: |
188 | return "{:+d}% to volume of « {} »".format(value, music.name) | 198 | return "{:+d}% to volume of « {} »" \ |
199 | .format(value, music.name) | ||
189 | else: | 200 | else: |
190 | return "{:+d}% to volume".format(value) | 201 | return "{:+d}% to volume" \ |
202 | .format(value) | ||
191 | else: | 203 | else: |
192 | if music is not None: | 204 | if music is not None: |
193 | return "setting volume of « {} » to {}%".format(music.name, value) | 205 | return "setting volume of « {} » to {}%" \ |
206 | .format(music.name, value) | ||
194 | else: | 207 | else: |
195 | return "setting volume to {}%".format(value) | 208 | return "setting volume to {}%" \ |
209 | .format(value) | ||
196 | 210 | ||
197 | def wait_print(self, duration = 0, music = None, **kwargs): | 211 | def wait_print(self, duration=0, music=None, **kwargs): |
198 | if music is None: | 212 | if music is None: |
199 | return "waiting {}s".format(duration) | 213 | return "waiting {}s" \ |
214 | .format(duration) | ||
200 | elif duration == 0: | 215 | elif duration == 0: |
201 | return "waiting the end of « {} »".format(music.name) | 216 | return "waiting the end of « {} »" \ |
217 | .format(music.name) | ||
202 | else: | 218 | else: |
203 | return "waiting the end of « {} » + {}s".format(music.name, duration) | 219 | return "waiting the end of « {} » + {}s" \ |
220 | .format(music.name, duration) | ||
204 | 221 | ||
205 | 222 | ||
206 | # Interruptions | 223 | # Interruptions |
207 | def wait_interrupt(self, duration = 0, music = None, **kwargs): | 224 | def wait_interrupt(self, duration=0, music=None, **kwargs): |
208 | if self.sleep_event is not None: | 225 | if self.sleep_event is not None: |
209 | self.sleep_event.set() | 226 | self.sleep_event.set() |
210 | if music is not None: | 227 | if music is not None: |