aboutsummaryrefslogtreecommitdiff
path: root/helpers
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2016-06-21 00:08:27 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2016-06-21 00:08:27 +0200
commitfba0caf0417cbb4e5b370e16e4b0c855c74094c1 (patch)
tree685005b11cee601592575adfdc2b40a72f403a33 /helpers
parent5c327cc405f11575446915627d1bbf0c14323b67 (diff)
downloadMusicSampler-fba0caf0417cbb4e5b370e16e4b0c855c74094c1.tar.gz
MusicSampler-fba0caf0417cbb4e5b370e16e4b0c855c74094c1.tar.zst
MusicSampler-fba0caf0417cbb4e5b370e16e4b0c855c74094c1.zip
Cleanup some constants
Diffstat (limited to 'helpers')
-rw-r--r--helpers/key.py16
-rw-r--r--helpers/mapping.py36
2 files changed, 28 insertions, 24 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
6import pygame 6import pygame
7 7
8class Key: 8class Key:
9 row_positions = {
10 'first': 0,
11 'second': 50,
12 'third': 100,
13 'fourth': 150,
14 'fifth': 200,
15 'sixth': 250,
16 }
17
18 default_outer_color = (120, 120, 120) 9 default_outer_color = (120, 120, 120)
19 lighter_outer_color = (200, 200, 200) 10 lighter_outer_color = (200, 200, 200)
20 default_inner_color = (255, 255, 255) 11 default_inner_color = (255, 255, 255)
@@ -27,11 +18,7 @@ class Key:
27 self.key_name = key_name 18 self.key_name = key_name
28 self.key_sym = key_sym 19 self.key_sym = key_sym
29 20
30 if isinstance(top, str): 21 self.top = top
31 self.top = self.row_positions[top]
32 else:
33 self.top = top
34
35 self.left = left 22 self.left = left
36 self.width = width 23 self.width = width
37 self.height = height 24 self.height = height
@@ -41,6 +28,7 @@ class Key:
41 28
42 self.rect = (self.left, self.top, self.right, self.bottom) 29 self.rect = (self.left, self.top, self.right, self.bottom)
43 self.position = (self.left, self.top) 30 self.position = (self.left, self.top)
31 self.disabled = disabled
44 32
45 if disabled: 33 if disabled:
46 self.outer_color = self.lighter_outer_color 34 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:
7 HEIGHT = 298 7 HEIGHT = 298
8 SIZE = WIDTH, HEIGHT 8 SIZE = WIDTH, HEIGHT
9 9
10 ROW_POSITIONS = {
11 'first': 0,
12 'second': 50,
13 'third': 100,
14 'fourth': 150,
15 'fifth': 200,
16 'sixth': 250,
17 }
18
10 KEYS = [ 19 KEYS = [
11 (pygame.K_ESCAPE, 'ESC', 'first', 0, {}), 20 (pygame.K_ESCAPE, 'ESC', 'first', 0, {}),
12 21
@@ -26,17 +35,17 @@ class Mapping:
26 (pygame.K_F12, 'F12', 'first', 700, {}), 35 (pygame.K_F12, 'F12', 'first', 700, {}),
27 36
28 37
29 (178, '²', 'second', 0, {}), 38 (178, '²', 'second', 0, {}),
30 (pygame.K_AMPERSAND, '&', 'second', 50, {}), 39 (pygame.K_AMPERSAND, '&', 'second', 50, {}),
31 (233, 'é', 'second', 100, {}), 40 (233, 'é', 'second', 100, {}),
32 (pygame.K_QUOTEDBL, '"', 'second', 150, {}), 41 (pygame.K_QUOTEDBL, '"', 'second', 150, {}),
33 (pygame.K_QUOTE, "'", 'second', 200, {}), 42 (pygame.K_QUOTE, "'", 'second', 200, {}),
34 (pygame.K_LEFTPAREN, '(', 'second', 250, {}), 43 (pygame.K_LEFTPAREN, '(', 'second', 250, {}),
35 (pygame.K_MINUS, '-', 'second', 300, {}), 44 (pygame.K_MINUS, '-', 'second', 300, {}),
36 (232, 'è', 'second', 350, {}), 45 (232, 'è', 'second', 350, {}),
37 (pygame.K_UNDERSCORE, '_', 'second', 400, {}), 46 (pygame.K_UNDERSCORE, '_', 'second', 400, {}),
38 (231, 'ç', 'second', 450, {}), 47 (231, 'ç', 'second', 450, {}),
39 (224, 'à', 'second', 500, {}), 48 (224, 'à', 'second', 500, {}),
40 (pygame.K_RIGHTPAREN, ')', 'second', 550, {}), 49 (pygame.K_RIGHTPAREN, ')', 'second', 550, {}),
41 (pygame.K_EQUALS, '=', 'second', 600, {}), 50 (pygame.K_EQUALS, '=', 'second', 600, {}),
42 51
@@ -57,9 +66,9 @@ class Mapping:
57 (pygame.K_CARET, '^', 'third', 575, {}), 66 (pygame.K_CARET, '^', 'third', 575, {}),
58 (pygame.K_DOLLAR, '$', 'third', 625, {}), 67 (pygame.K_DOLLAR, '$', 'third', 625, {}),
59 68
60 (pygame.K_RETURN, 'Enter', 'third', 692, { 'width': 56, 'height': 98 }), 69 (pygame.K_RETURN, 'Enter', 'third', 692, { 'width': 56, 'height': 98 }),
61 70
62 (pygame.K_CAPSLOCK, 'CAPS', 'fourth', 0, { 'width': 88, 'disabled': True }), 71 (pygame.K_CAPSLOCK, 'CAPS', 'fourth', 0, { 'width': 88, 'disabled': True }),
63 72
64 (pygame.K_q, 'q', 'fourth', 90, {}), 73 (pygame.K_q, 'q', 'fourth', 90, {}),
65 (pygame.K_s, 's', 'fourth', 140, {}), 74 (pygame.K_s, 's', 'fourth', 140, {}),
@@ -71,7 +80,7 @@ class Mapping:
71 (pygame.K_k, 'k', 'fourth', 440, {}), 80 (pygame.K_k, 'k', 'fourth', 440, {}),
72 (pygame.K_l, 'l', 'fourth', 490, {}), 81 (pygame.K_l, 'l', 'fourth', 490, {}),
73 (pygame.K_m, 'm', 'fourth', 540, {}), 82 (pygame.K_m, 'm', 'fourth', 540, {}),
74 (249, 'ù', 'fourth', 590, {}), 83 (249, 'ù', 'fourth', 590, {}),
75 (pygame.K_ASTERISK, '*', 'fourth', 640, {}), 84 (pygame.K_ASTERISK, '*', 'fourth', 640, {}),
76 85
77 86
@@ -96,7 +105,7 @@ class Mapping:
96 (pygame.K_LALT, 'LAlt', 'sixth', 165, { 'disabled': True }), 105 (pygame.K_LALT, 'LAlt', 'sixth', 165, { 'disabled': True }),
97 (pygame.K_SPACE, 'Espace', 'sixth', 215, { 'width': 248 }), 106 (pygame.K_SPACE, 'Espace', 'sixth', 215, { 'width': 248 }),
98 (pygame.K_MODE, 'AltGr', 'sixth', 465, { 'disabled': True }), 107 (pygame.K_MODE, 'AltGr', 'sixth', 465, { 'disabled': True }),
99 (314, 'Compose', 'sixth', 515, { 'disabled': True }), 108 (314, 'Compose', 'sixth', 515, { 'disabled': True }),
100 (pygame.K_RCTRL, 'RCtrl', 'sixth', 565, { 'width': 63, 'disabled': True }), 109 (pygame.K_RCTRL, 'RCtrl', 'sixth', 565, { 'width': 63, 'disabled': True }),
101 110
102 111
@@ -122,7 +131,14 @@ class Mapping:
122 self.keys = {} 131 self.keys = {}
123 self.running = [] 132 self.running = []
124 for key in self.KEYS: 133 for key in self.KEYS:
125 self.keys[key[0]] = Key(self, self.draw_lock, *key[0:4], **key[4]) 134 if key[2] in self.ROW_POSITIONS:
135 position = self.ROW_POSITIONS[key[2]]
136 else:
137 position = key[2]
138 self.keys[key[0]] = Key(self,
139 self.draw_lock,
140 key[0], key[1], position, key[3],
141 **key[4])
126 142
127 def draw(self): 143 def draw(self):
128 for key_name in self.keys: 144 for key_name in self.keys: