From 60aa2bed939858f9aec4252071c8efd99baac7e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Thu, 28 Jul 2016 21:55:29 +0200 Subject: Use labels stacking to build actionlist --- music_sampler/app_blocks/actionlist.py | 84 ++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 music_sampler/app_blocks/actionlist.py (limited to 'music_sampler/app_blocks/actionlist.py') diff --git a/music_sampler/app_blocks/actionlist.py b/music_sampler/app_blocks/actionlist.py new file mode 100644 index 0000000..70fe3f4 --- /dev/null +++ b/music_sampler/app_blocks/actionlist.py @@ -0,0 +1,84 @@ +from kivy.uix.label import Label +from kivy.uix.stacklayout import StackLayout +from kivy.uix.relativelayout import RelativeLayout +from kivy.properties import ListProperty, StringProperty + +import math + +__all__ = ["ActionList", + "ActionListIcons", "ActionListIcon", + "ActionListDescriptions", "ActionListDescription"] + +class ActionList(RelativeLayout): + action_title = StringProperty("") + action_list = ListProperty([]) + + def update_list(self, key, action_descriptions): + self.action_title = "actions linked to key {}:".format(key.key_sym) + action_list = [] + + for [action, status] in action_descriptions: + if status == "done": + icon = "✓" + elif status == "current": + icon = "✅" + else: + icon = " " + action_list.append([icon, action]) + self.action_list = action_list + +class ActionListIcons(StackLayout): + def __init__(self, **kwargs): + super(ActionListIcons, self).__init__(**kwargs) + self.icons = [] + + def on_parent(self, instance, parent): + parent.bind(action_list=self.update_actionlist_icons) + + def update_actionlist_icons(self, instance, actionlist): + for icon in self.icons: + self.remove_widget(icon) + self.icons = [] + for icon, description in actionlist: + icon_label = ActionListIcon(text=icon) + self.add_widget(icon_label) + self.icons.append(icon_label) + +class ActionListIcon(Label): + def __init__(self, text='', **kwargs): + super(ActionListIcon, self).__init__(**kwargs) + self.text = text + + def on_parent(self, instance, parent): + if parent is not None: + self.font_size = math.ceil(2 * math.sqrt(parent.parent.parent.key_size)) + self.height = parent.parent.labels_height + +class ActionListDescriptions(StackLayout): + def __init__(self, **kwargs): + super(ActionListDescriptions, self).__init__(**kwargs) + self.descriptions = [] + + def on_parent(self, instance, parent): + parent.bind(action_list=self.update_actionlist_descriptions) + + def update_actionlist_descriptions(self, instance, actionlist): + for description in self.descriptions: + self.remove_widget(description) + self.descriptions = [] + for icon, description in actionlist: + description_label = ActionListDescription(text=description) + self.add_widget(description_label) + self.descriptions.append(description_label) + +class ActionListDescription(Label): + def __init__(self, text='', **kwargs): + super(ActionListDescription, self).__init__(**kwargs) + self.text = text + + def on_parent(self, instance, parent): + if parent is not None: + self.font_size = math.ceil(2 * math.sqrt(parent.parent.parent.key_size)) + self.height = parent.parent.labels_height + + -- cgit v1.2.3