]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blobdiff - run.py
Add stub commands
[perso/Immae/Projets/Python/MusicSampler.git] / run.py
diff --git a/run.py b/run.py
index 69494d76a793de54d68e7f3d19ccdd6fc44b9b96..9797c918073f4baa8033f85634b9c5163efc34e9 100644 (file)
--- 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()