From d8ab67c745b78d0b2f5896cf6642004b3951433c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Wed, 15 Jun 2016 09:34:47 +0200 Subject: Add stub commands --- config.yml | 2 +- helpers.py | 45 ++++++++++++++++++++++++++++++++++++++++----- run.py | 24 +++++++++++++++++------- run.spec | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 91 insertions(+), 13 deletions(-) create mode 100644 run.spec diff --git a/config.yml b/config.yml index 1876e1e..1384c92 100644 --- a/config.yml +++ b/config.yml @@ -34,5 +34,5 @@ keys: - volume: value: 90 'p': - - run: + - command: command: une_super_commande_de_feu_d'artifice diff --git a/helpers.py b/helpers.py index b4a0fe0..7fbfb99 100644 --- a/helpers.py +++ b/helpers.py @@ -3,9 +3,9 @@ from pygame import * class Action: action_types = [ + 'command', 'pause', 'play', - 'run', 'stop', 'volume', 'wait', @@ -22,10 +22,30 @@ class Action: def run(self, callback): getattr(self, self.action)(callback, **self.arguments) - def stop(self, callback, musique = None, fade_out = 0): + def command(self, callback, command = "", **kwargs): + pass + + def pause(self, callback, music = None, **kwargs): + pass + + def play(self, callback, + music = None, + fade_in = 0, + restart_if_running = False, + volume = 100, + **kwargs): + pass + + def stop(self, callback, music = None, fade_out = 0, **kwargs): print('stopping') return callback() + def volume(self, callback, music = None, value = 100, **kwargs): + pass + + def wait(self, callback, time = 0, **kwargs): + pass + class Key: row_positions = { 'first': 5, @@ -106,7 +126,22 @@ class Key: if len(self.actions) > 0: self.actions[0].run(self.next_action) - def find_from_unicode(key_sym): + def list_actions(self, surface): + print("bouh", self.key_sym) + surface.fill((255, 0, 0)) + + def find_by_key_num(key_num): + if key_num in Mapping.KEYS: + return Mapping.KEYS[key_num] + return None + + def find_by_collidepoint(position): + for key in Mapping.KEYS: + if Mapping.KEYS[key].collidepoint(position): + return Mapping.KEYS[key] + return None + + def find_by_unicode(key_sym): for key in Mapping.KEYS: if Mapping.KEYS[key].key_sym == key_sym: return Mapping.KEYS[key] @@ -294,7 +329,7 @@ def parse_config(): seen_files = {} for mapped_key in config['keys']: - key = Key.find_from_unicode(mapped_key) + key = Key.find_by_unicode(mapped_key) if key is None: continue @@ -317,7 +352,7 @@ def parse_config(): if filename not in seen_files: seen_files[filename] = MusicFile.new(filename) - action_args['file'] = seen_files[filename] + action_args['music'] = seen_files[filename] else: action_args[argument] = action[action_name][argument] diff --git a/run.py b/run.py index 69494d7..9797c91 100644 --- a/run.py +++ b/run.py @@ -1,6 +1,10 @@ +import sys + +if getattr(sys, 'frozen', False): + os.chdir(sys._MEIPASS) + import pygame import pydub -import sys import helpers pygame.mixer.pre_init(frequency = 44100) @@ -13,6 +17,8 @@ background = pygame.Surface(screen.get_size()) background = background.convert() background.fill((250, 250, 250)) +action_surface = pygame.Surface((600, 250)).convert() +action_surface.fill((0,0,0)) helpers.parse_config() for key_name in helpers.Mapping.KEYS: @@ -20,6 +26,8 @@ for key_name in helpers.Mapping.KEYS: key.draw(background) screen.blit(background, (0, 0)) +screen.blit(action_surface, (10, 330)) + pygame.display.flip() contexts = [ @@ -38,12 +46,14 @@ while 1: sys.exit() if context == 'normal': - if event.type == pygame.KEYDOWN and event.key in helpers.Mapping.KEYS: - helpers.Mapping.KEYS[event.key].do_actions() - if event.type == pygame.MOUSEBUTTONUP: - for key in helpers.Mapping.KEYS: - if helpers.Mapping.KEYS[key].collidepoint(pygame.mouse.get_pos()): - helpers.Mapping.KEYS[key].do_actions() + if event.type == pygame.KEYDOWN: + key = helpers.Key.find_by_key_num(event.key) + if key is not None: + key.do_actions() + elif event.type == pygame.MOUSEBUTTONUP: + key = helpers.Key.find_by_collidepoint(pygame.mouse.get_pos()) + if key is not None: + key.list_actions(action_surface) pygame.display.flip() diff --git a/run.spec b/run.spec new file mode 100644 index 0000000..ec27125 --- /dev/null +++ b/run.spec @@ -0,0 +1,33 @@ +# -*- mode: python -*- + +block_cipher = None + +a = Analysis(['run.py'], + pathex=['/home/immae/temp/soundplant_alternative'], + binaries=None, + datas=[('config.yml', '.')], + hiddenimports=[ + 'six', + 'packaging', + 'packaging.version', + 'packaging.specifiers', + 'packaging.requirements' + ], + hookspath=[], + runtime_hooks=[], + excludes=[], + win_no_prefer_redirects=False, + win_private_assemblies=False, + cipher=block_cipher) +pyz = PYZ(a.pure, a.zipped_data, + cipher=block_cipher) +exe = EXE(pyz, + a.scripts, + a.binaries, + a.zipfiles, + a.datas, + name='run', + debug=False, + strip=False, + upx=True, + console=True ) -- cgit v1.2.3