]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blobdiff - music_sampler/app_blocks/actionlist.py
Use labels stacking to build actionlist
[perso/Immae/Projets/Python/MusicSampler.git] / 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 (file)
index 0000000..70fe3f4
--- /dev/null
@@ -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
+
+