X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=run.py;h=9797c918073f4baa8033f85634b9c5163efc34e9;hb=d8ab67c745b78d0b2f5896cf6642004b3951433c;hp=69494d76a793de54d68e7f3d19ccdd6fc44b9b96;hpb=8f88a3e417d6eff7666571eccf0b6ad453c88ccd;p=perso%2FImmae%2FProjets%2FPython%2FMusicSampler.git 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()