aboutsummaryrefslogtreecommitdiff
path: root/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'helpers')
-rw-r--r--helpers/__init__.py31
1 files changed, 21 insertions, 10 deletions
diff --git a/helpers/__init__.py b/helpers/__init__.py
index ec7da22..8570008 100644
--- a/helpers/__init__.py
+++ b/helpers/__init__.py
@@ -18,12 +18,13 @@ class Action:
18 'wait', 18 'wait',
19 ] 19 ]
20 20
21 def __init__(self, action, **kwargs): 21 def __init__(self, action, key, **kwargs):
22 if action in self.action_types: 22 if action in self.action_types:
23 self.action = action 23 self.action = action
24 else: 24 else:
25 raise Exception("Unknown action {}".format(action)) 25 raise Exception("Unknown action {}".format(action))
26 26
27 self.key = key
27 self.arguments = kwargs 28 self.arguments = kwargs
28 29
29 def ready(self): 30 def ready(self):
@@ -59,7 +60,7 @@ class Action:
59 mixer.stop() 60 mixer.stop()
60 61
61 def stop_all_actions(self, **kwargs): 62 def stop_all_actions(self, **kwargs):
62 Key.running = [] 63 self.key.mapping.stop_all_running()
63 64
64 def volume(self, music = None, value = 100, **kwargs): 65 def volume(self, music = None, value = 100, **kwargs):
65 pass 66 pass
@@ -136,7 +137,6 @@ class Key:
136 default_inner_color = (255, 255, 255) 137 default_inner_color = (255, 255, 255)
137 mapped_inner_color = ( 0, 255, 0) 138 mapped_inner_color = ( 0, 255, 0)
138 mapped_unready_inner_color = (255, 165, 0) 139 mapped_unready_inner_color = (255, 165, 0)
139 running = []
140 140
141 def __init__(self, mapping, key_name, key_sym, top, left, width = 48, height = 48, disabled = False): 141 def __init__(self, mapping, key_name, key_sym, top, left, width = 48, height = 48, disabled = False):
142 self.mapping = mapping 142 self.mapping = mapping
@@ -217,19 +217,17 @@ class Key:
217 return all(action.ready() for action in self.actions) 217 return all(action.ready() for action in self.actions)
218 218
219 def add_action(self, action_name, **arguments): 219 def add_action(self, action_name, **arguments):
220 self.actions.append(Action(action_name, **arguments)) 220 self.actions.append(Action(action_name, self, **arguments))
221 221
222 def do_actions(self): 222 def do_actions(self):
223 print("running actions for {}".format(self.key_sym)) 223 print("running actions for {}".format(self.key_sym))
224 Key.running.append(self) 224 start_time = time.time()
225 self.mapping.start_running(self, start_time)
225 for action in self.actions: 226 for action in self.actions:
226 #FIXME: si on stop_all_actions et qu'on relance, "self" est de 227 if self.mapping.keep_running(self, start_time):
227 #nouveau dans Key.running
228 if self in Key.running:
229 action.run() 228 action.run()
230 229
231 if self in Key.running: 230 self.mapping.finished_running(self, start_time)
232 Key.running.remove(self)
233 231
234 def list_actions(self, surface): 232 def list_actions(self, surface):
235 # FIXME: Todo 233 # FIXME: Todo
@@ -354,6 +352,7 @@ class Mapping:
354 self.background = Surface(self.SIZE).convert() 352 self.background = Surface(self.SIZE).convert()
355 self.background.fill((250, 250, 250)) 353 self.background.fill((250, 250, 250))
356 self.keys = {} 354 self.keys = {}
355 self.running = []
357 for key in self.KEYS: 356 for key in self.KEYS:
358 self.keys[key[0]] = Key(self, *key[0:4], **key[4]) 357 self.keys[key[0]] = Key(self, *key[0:4], **key[4])
359 358
@@ -389,6 +388,18 @@ class Mapping:
389 return self.keys[key] 388 return self.keys[key]
390 return None 389 return None
391 390
391 def stop_all_running(self):
392 self.running = []
393
394 def start_running(self, key, start_time):
395 self.running.append((key, start_time))
396
397 def keep_running(self, key, start_time):
398 return (key, start_time) in self.running
399
400 def finished_running(self, key, start_time):
401 if (key, start_time) in self.running:
402 self.running.remove((key, start_time))
392 403
393 404
394class MusicFile: 405class MusicFile: