diff options
-rw-r--r-- | config.yml | 2 | ||||
-rw-r--r-- | helpers.py | 45 | ||||
-rw-r--r-- | run.py | 24 | ||||
-rw-r--r-- | run.spec | 33 |
4 files changed, 91 insertions, 13 deletions
@@ -34,5 +34,5 @@ keys: | |||
34 | - volume: | 34 | - volume: |
35 | value: 90 | 35 | value: 90 |
36 | 'p': | 36 | 'p': |
37 | - run: | 37 | - command: |
38 | command: une_super_commande_de_feu_d'artifice | 38 | command: une_super_commande_de_feu_d'artifice |
@@ -3,9 +3,9 @@ from pygame import * | |||
3 | 3 | ||
4 | class Action: | 4 | class Action: |
5 | action_types = [ | 5 | action_types = [ |
6 | 'command', | ||
6 | 'pause', | 7 | 'pause', |
7 | 'play', | 8 | 'play', |
8 | 'run', | ||
9 | 'stop', | 9 | 'stop', |
10 | 'volume', | 10 | 'volume', |
11 | 'wait', | 11 | 'wait', |
@@ -22,10 +22,30 @@ class Action: | |||
22 | def run(self, callback): | 22 | def run(self, callback): |
23 | getattr(self, self.action)(callback, **self.arguments) | 23 | getattr(self, self.action)(callback, **self.arguments) |
24 | 24 | ||
25 | def stop(self, callback, musique = None, fade_out = 0): | 25 | def command(self, callback, command = "", **kwargs): |
26 | pass | ||
27 | |||
28 | def pause(self, callback, music = None, **kwargs): | ||
29 | pass | ||
30 | |||
31 | def play(self, callback, | ||
32 | music = None, | ||
33 | fade_in = 0, | ||
34 | restart_if_running = False, | ||
35 | volume = 100, | ||
36 | **kwargs): | ||
37 | pass | ||
38 | |||
39 | def stop(self, callback, music = None, fade_out = 0, **kwargs): | ||
26 | print('stopping') | 40 | print('stopping') |
27 | return callback() | 41 | return callback() |
28 | 42 | ||
43 | def volume(self, callback, music = None, value = 100, **kwargs): | ||
44 | pass | ||
45 | |||
46 | def wait(self, callback, time = 0, **kwargs): | ||
47 | pass | ||
48 | |||
29 | class Key: | 49 | class Key: |
30 | row_positions = { | 50 | row_positions = { |
31 | 'first': 5, | 51 | 'first': 5, |
@@ -106,7 +126,22 @@ class Key: | |||
106 | if len(self.actions) > 0: | 126 | if len(self.actions) > 0: |
107 | self.actions[0].run(self.next_action) | 127 | self.actions[0].run(self.next_action) |
108 | 128 | ||
109 | def find_from_unicode(key_sym): | 129 | def list_actions(self, surface): |
130 | print("bouh", self.key_sym) | ||
131 | surface.fill((255, 0, 0)) | ||
132 | |||
133 | def find_by_key_num(key_num): | ||
134 | if key_num in Mapping.KEYS: | ||
135 | return Mapping.KEYS[key_num] | ||
136 | return None | ||
137 | |||
138 | def find_by_collidepoint(position): | ||
139 | for key in Mapping.KEYS: | ||
140 | if Mapping.KEYS[key].collidepoint(position): | ||
141 | return Mapping.KEYS[key] | ||
142 | return None | ||
143 | |||
144 | def find_by_unicode(key_sym): | ||
110 | for key in Mapping.KEYS: | 145 | for key in Mapping.KEYS: |
111 | if Mapping.KEYS[key].key_sym == key_sym: | 146 | if Mapping.KEYS[key].key_sym == key_sym: |
112 | return Mapping.KEYS[key] | 147 | return Mapping.KEYS[key] |
@@ -294,7 +329,7 @@ def parse_config(): | |||
294 | seen_files = {} | 329 | seen_files = {} |
295 | 330 | ||
296 | for mapped_key in config['keys']: | 331 | for mapped_key in config['keys']: |
297 | key = Key.find_from_unicode(mapped_key) | 332 | key = Key.find_by_unicode(mapped_key) |
298 | if key is None: | 333 | if key is None: |
299 | continue | 334 | continue |
300 | 335 | ||
@@ -317,7 +352,7 @@ def parse_config(): | |||
317 | if filename not in seen_files: | 352 | if filename not in seen_files: |
318 | seen_files[filename] = MusicFile.new(filename) | 353 | seen_files[filename] = MusicFile.new(filename) |
319 | 354 | ||
320 | action_args['file'] = seen_files[filename] | 355 | action_args['music'] = seen_files[filename] |
321 | 356 | ||
322 | else: | 357 | else: |
323 | action_args[argument] = action[action_name][argument] | 358 | action_args[argument] = action[action_name][argument] |
@@ -1,6 +1,10 @@ | |||
1 | import sys | ||
2 | |||
3 | if getattr(sys, 'frozen', False): | ||
4 | os.chdir(sys._MEIPASS) | ||
5 | |||
1 | import pygame | 6 | import pygame |
2 | import pydub | 7 | import pydub |
3 | import sys | ||
4 | import helpers | 8 | import helpers |
5 | 9 | ||
6 | pygame.mixer.pre_init(frequency = 44100) | 10 | pygame.mixer.pre_init(frequency = 44100) |
@@ -13,6 +17,8 @@ background = pygame.Surface(screen.get_size()) | |||
13 | background = background.convert() | 17 | background = background.convert() |
14 | background.fill((250, 250, 250)) | 18 | background.fill((250, 250, 250)) |
15 | 19 | ||
20 | action_surface = pygame.Surface((600, 250)).convert() | ||
21 | action_surface.fill((0,0,0)) | ||
16 | helpers.parse_config() | 22 | helpers.parse_config() |
17 | 23 | ||
18 | for key_name in helpers.Mapping.KEYS: | 24 | for key_name in helpers.Mapping.KEYS: |
@@ -20,6 +26,8 @@ for key_name in helpers.Mapping.KEYS: | |||
20 | key.draw(background) | 26 | key.draw(background) |
21 | 27 | ||
22 | screen.blit(background, (0, 0)) | 28 | screen.blit(background, (0, 0)) |
29 | screen.blit(action_surface, (10, 330)) | ||
30 | |||
23 | pygame.display.flip() | 31 | pygame.display.flip() |
24 | 32 | ||
25 | contexts = [ | 33 | contexts = [ |
@@ -38,12 +46,14 @@ while 1: | |||
38 | sys.exit() | 46 | sys.exit() |
39 | 47 | ||
40 | if context == 'normal': | 48 | if context == 'normal': |
41 | if event.type == pygame.KEYDOWN and event.key in helpers.Mapping.KEYS: | 49 | if event.type == pygame.KEYDOWN: |
42 | helpers.Mapping.KEYS[event.key].do_actions() | 50 | key = helpers.Key.find_by_key_num(event.key) |
43 | if event.type == pygame.MOUSEBUTTONUP: | 51 | if key is not None: |
44 | for key in helpers.Mapping.KEYS: | 52 | key.do_actions() |
45 | if helpers.Mapping.KEYS[key].collidepoint(pygame.mouse.get_pos()): | 53 | elif event.type == pygame.MOUSEBUTTONUP: |
46 | helpers.Mapping.KEYS[key].do_actions() | 54 | key = helpers.Key.find_by_collidepoint(pygame.mouse.get_pos()) |
55 | if key is not None: | ||
56 | key.list_actions(action_surface) | ||
47 | 57 | ||
48 | pygame.display.flip() | 58 | pygame.display.flip() |
49 | 59 | ||
diff --git a/run.spec b/run.spec new file mode 100644 index 0000000..ec27125 --- /dev/null +++ b/run.spec | |||
@@ -0,0 +1,33 @@ | |||
1 | # -*- mode: python -*- | ||
2 | |||
3 | block_cipher = None | ||
4 | |||
5 | a = Analysis(['run.py'], | ||
6 | pathex=['/home/immae/temp/soundplant_alternative'], | ||
7 | binaries=None, | ||
8 | datas=[('config.yml', '.')], | ||
9 | hiddenimports=[ | ||
10 | 'six', | ||
11 | 'packaging', | ||
12 | 'packaging.version', | ||
13 | 'packaging.specifiers', | ||
14 | 'packaging.requirements' | ||
15 | ], | ||
16 | hookspath=[], | ||
17 | runtime_hooks=[], | ||
18 | excludes=[], | ||
19 | win_no_prefer_redirects=False, | ||
20 | win_private_assemblies=False, | ||
21 | cipher=block_cipher) | ||
22 | pyz = PYZ(a.pure, a.zipped_data, | ||
23 | cipher=block_cipher) | ||
24 | exe = EXE(pyz, | ||
25 | a.scripts, | ||
26 | a.binaries, | ||
27 | a.zipfiles, | ||
28 | a.datas, | ||
29 | name='run', | ||
30 | debug=False, | ||
31 | strip=False, | ||
32 | upx=True, | ||
33 | console=True ) | ||