From 65ec4d2a87bfe0dcf1250ec8dc61225d4ed66325 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Isma=C3=ABl=20Bouya?= Date: Sun, 26 Jun 2016 23:10:17 +0200 Subject: [PATCH] Show last used keys --- helpers/key.py | 1 + music_sampler.kv | 68 ++++++++++++++++++++++++++++++++++++++++++++++-- music_sampler.py | 17 ++++++++++++ 3 files changed, 84 insertions(+), 2 deletions(-) diff --git a/helpers/key.py b/helpers/key.py index f49b3ec..ca73b87 100644 --- a/helpers/key.py +++ b/helpers/key.py @@ -83,6 +83,7 @@ class Key(ButtonBehavior, Widget): if not self.enabled: return None + self.parent.parent.ids['KeyList'].append(self.key_sym) print("running actions for {}".format(self.key_sym)) start_time = time.time() self.parent.start_running(self, start_time) diff --git a/music_sampler.kv b/music_sampler.kv index 4a44069..d21c5fb 100644 --- a/music_sampler.kv +++ b/music_sampler.kv @@ -85,14 +85,21 @@ mapping_width: self.key_size * 18 + self.key_sep * 16 + self.key_pad_sep mapping_x: self.border mapping_y: self.top - self.mapping_height - self.border + + key_list_width: 4 * (mock_ubuntu_regular.width or 0) + key_list_height: self.height - self.mapping_height - 3 * self.border + key_list_x: (self.action_list_width or 0) + 2 * self.border + key_list_y: self.border + action_list_height: self.height - self.mapping_height - 3 * self.border - action_list_width: 3 * self.width / 4 + action_list_width: 3 * self.width / 4 - self.key_list_width - self.border action_list_x: self.border action_list_y: self.border + play_list_height: self.action_list_height play_list_width: self.width - self.action_list_width - 3* self.border play_list_y: self.border - play_list_x: self.action_list_width + 2 * self.border + play_list_x: self.action_list_width + self.key_list_width + 3 * self.border min_height: min(mock_symbola.height, mock_ubuntu_regular.height, mock_ubuntu_bold.height) symbola_line_height: self.min_height / max(mock_symbola.height,1) @@ -139,11 +146,68 @@ id: ActionList pos: self.parent.action_list_x, self.parent.action_list_y size: self.parent.action_list_width, self.parent.action_list_height + KeyList: + id: KeyList + pos: self.parent.key_list_x, self.parent.key_list_y + size: self.parent.key_list_width, self.parent.key_list_height PlayList: id: PlayList pos: self.parent.play_list_x, self.parent.play_list_y size: self.parent.play_list_width, self.parent.play_list_height +: + size_hint: None, None + canvas: + Color: + rgba: 250./255, 250./255, 250./255, 1 + Rectangle: + pos: 0, 0 + size: self.width, self.height + Label: + id: key_list_first + font_name: h.path() + "fonts/Ubuntu-B.ttf" + font_size: math.ceil(2 * math.sqrt(self.parent.parent.key_size or 10)) + color: 0, 0, 0, 1 + text: self.parent.first_key + text_size: None, None + valign: "top" + size_hint: None, None + size: self.parent.width, self.texture_size[1] + pos: 0, self.parent.height - self.height + Label: + id: key_list_second + font_name: h.path() + "fonts/Ubuntu-Regular.ttf" + font_size: math.ceil(2 * math.sqrt(self.parent.parent.key_size or 10)) + color: 0, 0, 0, 1 + text: self.parent.second_key + text_size: None, None + valign: "top" + size_hint: None, None + size: self.parent.width, self.texture_size[1] + pos: 0, self.parent.height - key_list_first.height - self.height + Label: + id: key_list_third + font_name: h.path() + "fonts/Ubuntu-Regular.ttf" + font_size: math.ceil(2 * math.sqrt(self.parent.parent.key_size or 10)) + color: 0, 0, 0, 0.75 + text: self.parent.third_key + text_size: None, None + valign: "top" + size_hint: None, None + size: self.parent.width, self.texture_size[1] + pos: 0, self.parent.height - key_list_first.height - key_list_second.height - self.height + Label: + id: key_list_rest + font_name: h.path() + "fonts/Ubuntu-Regular.ttf" + font_size: math.ceil(2 * math.sqrt(self.parent.parent.key_size or 10)) + color: 0, 0, 0, 0.5 + text: "\n".join(self.parent.keylist[3:]) + text_size: None, None + valign: "top" + size_hint: None, None + size: self.parent.width, self.texture_size[1] + pos: 0, self.parent.height - key_list_first.height - key_list_second.height - key_list_third.height - self.height + : size_hint: None, None canvas: diff --git a/music_sampler.py b/music_sampler.py index 81b96c4..5e61466 100644 --- a/music_sampler.py +++ b/music_sampler.py @@ -11,6 +11,23 @@ from helpers.key import Key from helpers.mapping import Mapping import helpers +class KeyList(RelativeLayout): + keylist = ListProperty([]) + first_key = StringProperty("") + second_key = StringProperty("") + third_key = StringProperty("") + + def append(self, value): + self.keylist = [value] + self.keylist + + def on_keylist(self, instance, new_key_list): + if len(self.keylist) > 0: + self.first_key = self.keylist[0] + if len(self.keylist) > 1: + self.second_key = self.keylist[1] + if len(self.keylist) > 2: + self.third_key = self.keylist[2] + class PlayList(RelativeLayout): playlist = ListProperty([]) -- 2.41.0