diff options
Diffstat (limited to 'helpers')
-rw-r--r-- | helpers/__init__.py | 10 | ||||
-rw-r--r-- | helpers/action.py | 8 | ||||
-rw-r--r-- | helpers/key.py | 38 | ||||
-rw-r--r-- | helpers/music_file.py | 2 |
4 files changed, 51 insertions, 7 deletions
diff --git a/helpers/__init__.py b/helpers/__init__.py index b1723ee..b7acbf5 100644 --- a/helpers/__init__.py +++ b/helpers/__init__.py | |||
@@ -47,3 +47,13 @@ def parse_config(mapping): | |||
47 | action_args[argument] = action[action_name][argument] | 47 | action_args[argument] = action[action_name][argument] |
48 | 48 | ||
49 | key.add_action(action_name, **action_args) | 49 | key.add_action(action_name, **action_args) |
50 | |||
51 | for key_property in config['key_properties']: | ||
52 | key = mapping.find_by_unicode(key_property) | ||
53 | if key is None: | ||
54 | continue | ||
55 | |||
56 | if 'description' in config['key_properties'][key_property]: | ||
57 | key.set_description(config['key_properties'][key_property]['description']) | ||
58 | if 'color' in config['key_properties'][key_property]: | ||
59 | key.set_color(config['key_properties'][key_property]['color']) | ||
diff --git a/helpers/action.py b/helpers/action.py index 97873a0..5afe437 100644 --- a/helpers/action.py +++ b/helpers/action.py | |||
@@ -74,10 +74,14 @@ class Action: | |||
74 | else: | 74 | else: |
75 | pass | 75 | pass |
76 | 76 | ||
77 | def wait(self, duration = 0, **kwargs): | 77 | def wait(self, duration = 0, music = None, **kwargs): |
78 | # FIXME: Make it stoppable | 78 | # FIXME: Make it stoppable |
79 | # http://stackoverflow.com/questions/29082268/python-time-sleep-vs-event-wait | 79 | # http://stackoverflow.com/questions/29082268/python-time-sleep-vs-event-wait |
80 | time.sleep(duration) | 80 | if music is None: |
81 | time.sleep(duration) | ||
82 | else: | ||
83 | # TODO | ||
84 | music.wait_end() | ||
81 | 85 | ||
82 | def command_print(self, command = "", **kwargs): | 86 | def command_print(self, command = "", **kwargs): |
83 | return "running command {}".format(command) | 87 | return "running command {}".format(command) |
diff --git a/helpers/key.py b/helpers/key.py index 6997e70..9a6cb3b 100644 --- a/helpers/key.py +++ b/helpers/key.py | |||
@@ -18,7 +18,8 @@ class Key: | |||
18 | lighter_outer_color = (200, 200, 200) | 18 | lighter_outer_color = (200, 200, 200) |
19 | default_inner_color = (255, 255, 255) | 19 | default_inner_color = (255, 255, 255) |
20 | mapped_inner_color = ( 0, 255, 0) | 20 | mapped_inner_color = ( 0, 255, 0) |
21 | mapped_unready_inner_color = (255, 165, 0) | 21 | mapped_unready_inner_color = ( 0, 255, 0, 100) |
22 | #mapped_unready_inner_color = (255, 165, 0) | ||
22 | 23 | ||
23 | def __init__(self, mapping, draw_lock, key_name, key_sym, top, left, width = 48, height = 48, disabled = False): | 24 | def __init__(self, mapping, draw_lock, key_name, key_sym, top, left, width = 48, height = 48, disabled = False): |
24 | self.draw_lock = draw_lock | 25 | self.draw_lock = draw_lock |
@@ -50,13 +51,16 @@ class Key: | |||
50 | 51 | ||
51 | self.inner_color = self.default_inner_color | 52 | self.inner_color = self.default_inner_color |
52 | self.actions = [] | 53 | self.actions = [] |
54 | self.description = [] | ||
55 | self.custom_color = None | ||
56 | self.custom_unready_color = None | ||
53 | 57 | ||
54 | def square(self, all_actions_ready): | 58 | def square(self, all_actions_ready): |
55 | if self.has_actions(): | 59 | if self.has_actions(): |
56 | if all_actions_ready: | 60 | if all_actions_ready: |
57 | self.inner_color = self.mapped_inner_color | 61 | self.inner_color = self.custom_color or self.mapped_inner_color |
58 | else: | 62 | else: |
59 | self.inner_color = self.mapped_unready_inner_color | 63 | self.inner_color = self.custom_unready_color or self.mapped_unready_inner_color |
60 | 64 | ||
61 | return RoundedRect((0, 0, self.width, self.height), | 65 | return RoundedRect((0, 0, self.width, self.height), |
62 | self.outer_color, self.inner_color, self.linewidth) | 66 | self.outer_color, self.inner_color, self.linewidth) |
@@ -67,6 +71,14 @@ class Key: | |||
67 | position[1] - self.position[1] | 71 | position[1] - self.position[1] |
68 | ) | 72 | ) |
69 | 73 | ||
74 | def set_description(self, description): | ||
75 | self.description = description | ||
76 | |||
77 | def set_color(self, color): | ||
78 | self.custom_color = tuple(color) | ||
79 | color.append(100) | ||
80 | self.custom_unready_color = tuple(color) | ||
81 | |||
70 | def draw(self, background_surface): | 82 | def draw(self, background_surface): |
71 | self.draw_lock.acquire() | 83 | self.draw_lock.acquire() |
72 | all_actions_ready = self.all_actions_ready() | 84 | all_actions_ready = self.all_actions_ready() |
@@ -75,11 +87,27 @@ class Key: | |||
75 | 87 | ||
76 | if getattr(sys, 'frozen', False): | 88 | if getattr(sys, 'frozen', False): |
77 | police = pygame.font.Font(sys._MEIPASS + "/Ubuntu-Regular.ttf", 14) | 89 | police = pygame.font.Font(sys._MEIPASS + "/Ubuntu-Regular.ttf", 14) |
90 | text_police = pygame.font.Font(sys._MEIPASS + "/Ubuntu-Regular.ttf", 10) | ||
78 | else: | 91 | else: |
79 | police = pygame.font.Font("Ubuntu-Regular.ttf", 14) | 92 | police = pygame.font.Font("Ubuntu-Regular.ttf", 14) |
93 | text_police = pygame.font.Font("Ubuntu-Regular.ttf", 10) | ||
80 | 94 | ||
95 | police.set_bold(True) | ||
81 | text = police.render(self.key_sym, True, (0,0,0)) | 96 | text = police.render(self.key_sym, True, (0,0,0)) |
82 | self.surface.blit(text, (5,5)) | 97 | self.surface.blit(text, (5,5)) |
98 | |||
99 | is_first_line = True | ||
100 | offset = 11 + text_police.get_linesize() | ||
101 | first_line_offset = 18 | ||
102 | for description in self.description: | ||
103 | text = text_police.render(description, True, (0,0,0)) | ||
104 | if is_first_line: | ||
105 | self.surface.blit(text, (first_line_offset, 9)) | ||
106 | is_first_line = False | ||
107 | else: | ||
108 | self.surface.blit(text, (5, offset)) | ||
109 | offset += text_police.get_linesize() | ||
110 | |||
83 | background_surface.blit(self.surface, self.position) | 111 | background_surface.blit(self.surface, self.position) |
84 | self.draw_lock.release() | 112 | self.draw_lock.release() |
85 | 113 | ||
@@ -114,8 +142,8 @@ class Key: | |||
114 | 142 | ||
115 | def list_actions(self, screen): | 143 | def list_actions(self, screen): |
116 | action_descriptions = [action.description() for action in self.actions] | 144 | action_descriptions = [action.description() for action in self.actions] |
117 | print("actions linked to key {}:".format(self.key_sym)) | 145 | #print("actions linked to key {}:".format(self.key_sym)) |
118 | print("\t" + "\n\t".join(action_descriptions)) | 146 | #print("\t" + "\n\t".join(action_descriptions)) |
119 | self.draw_lock.acquire() | 147 | self.draw_lock.acquire() |
120 | surface = pygame.Surface((800, 250)).convert() | 148 | surface = pygame.Surface((800, 250)).convert() |
121 | surface.fill((250, 250, 250)) | 149 | surface.fill((250, 250, 250)) |
diff --git a/helpers/music_file.py b/helpers/music_file.py index 36a7dd9..b834104 100644 --- a/helpers/music_file.py +++ b/helpers/music_file.py | |||
@@ -56,3 +56,5 @@ class MusicFile: | |||
56 | value = 100 | 56 | value = 100 |
57 | self.sound.set_volume(value / 100) | 57 | self.sound.set_volume(value / 100) |
58 | 58 | ||
59 | def wait_end(self): | ||
60 | pass | ||