From fba0caf0417cbb4e5b370e16e4b0c855c74094c1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Isma=C3=ABl=20Bouya?= Date: Tue, 21 Jun 2016 00:08:27 +0200 Subject: [PATCH] Cleanup some constants --- helpers/key.py | 16 ++-------------- helpers/mapping.py | 36 ++++++++++++++++++++++++++---------- music_sampler.py | 4 ++-- 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/helpers/key.py b/helpers/key.py index e643dc2..612758f 100644 --- a/helpers/key.py +++ b/helpers/key.py @@ -6,15 +6,6 @@ import sys import pygame class Key: - row_positions = { - 'first': 0, - 'second': 50, - 'third': 100, - 'fourth': 150, - 'fifth': 200, - 'sixth': 250, - } - default_outer_color = (120, 120, 120) lighter_outer_color = (200, 200, 200) default_inner_color = (255, 255, 255) @@ -27,11 +18,7 @@ class Key: self.key_name = key_name self.key_sym = key_sym - if isinstance(top, str): - self.top = self.row_positions[top] - else: - self.top = top - + self.top = top self.left = left self.width = width self.height = height @@ -41,6 +28,7 @@ class Key: self.rect = (self.left, self.top, self.right, self.bottom) self.position = (self.left, self.top) + self.disabled = disabled if disabled: self.outer_color = self.lighter_outer_color diff --git a/helpers/mapping.py b/helpers/mapping.py index 84e9941..58aaf3d 100644 --- a/helpers/mapping.py +++ b/helpers/mapping.py @@ -7,6 +7,15 @@ class Mapping: HEIGHT = 298 SIZE = WIDTH, HEIGHT + ROW_POSITIONS = { + 'first': 0, + 'second': 50, + 'third': 100, + 'fourth': 150, + 'fifth': 200, + 'sixth': 250, + } + KEYS = [ (pygame.K_ESCAPE, 'ESC', 'first', 0, {}), @@ -26,17 +35,17 @@ class Mapping: (pygame.K_F12, 'F12', 'first', 700, {}), - (178, '²', 'second', 0, {}), + (178, '²', 'second', 0, {}), (pygame.K_AMPERSAND, '&', 'second', 50, {}), - (233, 'é', 'second', 100, {}), + (233, 'é', 'second', 100, {}), (pygame.K_QUOTEDBL, '"', 'second', 150, {}), (pygame.K_QUOTE, "'", 'second', 200, {}), (pygame.K_LEFTPAREN, '(', 'second', 250, {}), (pygame.K_MINUS, '-', 'second', 300, {}), - (232, 'è', 'second', 350, {}), + (232, 'è', 'second', 350, {}), (pygame.K_UNDERSCORE, '_', 'second', 400, {}), - (231, 'ç', 'second', 450, {}), - (224, 'à', 'second', 500, {}), + (231, 'ç', 'second', 450, {}), + (224, 'à', 'second', 500, {}), (pygame.K_RIGHTPAREN, ')', 'second', 550, {}), (pygame.K_EQUALS, '=', 'second', 600, {}), @@ -57,9 +66,9 @@ class Mapping: (pygame.K_CARET, '^', 'third', 575, {}), (pygame.K_DOLLAR, '$', 'third', 625, {}), - (pygame.K_RETURN, 'Enter', 'third', 692, { 'width': 56, 'height': 98 }), + (pygame.K_RETURN, 'Enter', 'third', 692, { 'width': 56, 'height': 98 }), - (pygame.K_CAPSLOCK, 'CAPS', 'fourth', 0, { 'width': 88, 'disabled': True }), + (pygame.K_CAPSLOCK, 'CAPS', 'fourth', 0, { 'width': 88, 'disabled': True }), (pygame.K_q, 'q', 'fourth', 90, {}), (pygame.K_s, 's', 'fourth', 140, {}), @@ -71,7 +80,7 @@ class Mapping: (pygame.K_k, 'k', 'fourth', 440, {}), (pygame.K_l, 'l', 'fourth', 490, {}), (pygame.K_m, 'm', 'fourth', 540, {}), - (249, 'ù', 'fourth', 590, {}), + (249, 'ù', 'fourth', 590, {}), (pygame.K_ASTERISK, '*', 'fourth', 640, {}), @@ -96,7 +105,7 @@ class Mapping: (pygame.K_LALT, 'LAlt', 'sixth', 165, { 'disabled': True }), (pygame.K_SPACE, 'Espace', 'sixth', 215, { 'width': 248 }), (pygame.K_MODE, 'AltGr', 'sixth', 465, { 'disabled': True }), - (314, 'Compose', 'sixth', 515, { 'disabled': True }), + (314, 'Compose', 'sixth', 515, { 'disabled': True }), (pygame.K_RCTRL, 'RCtrl', 'sixth', 565, { 'width': 63, 'disabled': True }), @@ -122,7 +131,14 @@ class Mapping: self.keys = {} self.running = [] for key in self.KEYS: - self.keys[key[0]] = Key(self, self.draw_lock, *key[0:4], **key[4]) + if key[2] in self.ROW_POSITIONS: + position = self.ROW_POSITIONS[key[2]] + else: + position = key[2] + self.keys[key[0]] = Key(self, + self.draw_lock, + key[0], key[1], position, key[3], + **key[4]) def draw(self): for key_name in self.keys: diff --git a/music_sampler.py b/music_sampler.py index 8ebfaa3..c17f7bf 100644 --- a/music_sampler.py +++ b/music_sampler.py @@ -47,7 +47,7 @@ while 1: if context == 'normal': if event.type == pygame.KEYDOWN: key = mapping.find_by_key_num(event.key) - if key is not None: + if key is not None and not key.disabled: threading.Thread(name = "MSKeyAction", target=key.do_actions).start() threading.Thread(name = "MSClic", target=key.list_actions, args = [screen]).start() elif event.type == pygame.MOUSEBUTTONUP: @@ -65,10 +65,10 @@ while 1: for music_file in open_files.values(): police.set_bold(False) if music_file.is_playing(): - icon = icon_police.render("⏵", True, (0,0,0)) if music_file.is_paused(): icon = icon_police.render("⏸", True, (0,0,0)) else: + icon = icon_police.render("⏵", True, (0,0,0)) police.set_bold(True) text = police.render(music_file.name, True, (0,0,0)) surface.blit(icon, (0, offset)) -- 2.41.0