]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/commitdiff
Use labels stacking to build actionlist
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Thu, 28 Jul 2016 19:55:29 +0000 (21:55 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Thu, 28 Jul 2016 20:11:26 +0000 (22:11 +0200)
music_sampler/app.py
music_sampler/app_blocks/__init__.py
music_sampler/app_blocks/actionlist.py [new file with mode: 0644]
music_sampler/music_sampler.kv

index 510cb4492c5d86d286678f7a96cefe899531164a..cce396972172268307e49a2a14e61665c79b9e22 100644 (file)
@@ -16,6 +16,7 @@ from .mapping import Mapping
 
 register_fonts()
 
+from .app_blocks.actionlist import *
 from .app_blocks.playlist import *
 
 class KeyList(RelativeLayout):
@@ -35,23 +36,6 @@ class KeyList(RelativeLayout):
         if len(self.keylist) > 2:
             self.third_key  = self.keylist[2]
 
-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)
-        self.action_list = []
-
-        for [action, status] in action_descriptions:
-            if status == "done":
-                icon = "✓"
-            elif status == "current":
-                icon = "✅"
-            else:
-                icon = " "
-            self.action_list.append([icon, action])
-
 class Screen(FloatLayout):
     pass
 
index c412eb1656309ed29cdf70d35c47fb2636ea7785..82c3ec7c6655908050a430850560054c023be3bc 100644 (file)
@@ -1 +1,2 @@
+from . import actionlist
 from . import playlist
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
+
+
index 8e94da8767eb92c6d2c9b383f57472166dacd62d..afb99e411907a9e0c7de411bdb9f98a3f2d5f68a 100644 (file)
 
 <ActionList>:
   size_hint: None, None
+  labels_height: self.parent.max_height or 1
   canvas:
     Color:
       rgba: 250./255, 250./255, 250./255, 1
     Rectangle:
       pos:  0, 0
       size: self.width, self.height
-
   Label:
     id: action_list_title
     font_name: "Ubuntu"
     valign: "top"
     size_hint: None, None
     size: self.texture_size[0], self.parent.height
-  Label:
-    id: action_list_icons
-    font_name: "Symbola"
-    font_size: math.ceil(2 * math.sqrt(self.parent.parent.key_size or 10))
-    line_height: self.parent.parent.symbola_line_height or 1
-    color: 0, 0, 0, 1
-    text: "\n".join(map(lambda x: x[0], self.parent.action_list))
-    text_size: None, self.parent.height
-    halign: "left"
-    valign: "top"
-    size_hint: None, None
-    size: self.texture_size[0], self.parent.height - 3 * self.line_height * self.font_size
-  Label:
-    id: action_list_names
-    font_name: "Ubuntu"
-    font_size: math.ceil(2 * math.sqrt(self.parent.parent.key_size or 10))
-    line_height: self.parent.parent.ubuntu_regular_line_height or 1
-    color: 0, 0, 0, 1
-    text: "\n".join(map(lambda x: x[1], self.parent.action_list))
-    text_size: None, self.parent.height
-    halign: "left"
-    valign: "top"
-    size_hint: None, None
-    pos: 15, self.y
-    size: self.texture_size[0], self.parent.height - 3 * self.line_height * self.font_size
-  
+  ActionListIcons:
+    orientation: 'lr-tb'
+    size_hint: 0.02, 0.9
+    pos_hint: { 'x': 0, 'top': 0.9 }
+  ActionListDescriptions:
+    orientation: 'lr-tb'
+    size_hint: 0.98, 0.9
+    pos_hint: { 'x': 0.02, 'top': 0.9 }
+
+<ActionListIcon>:
+  font_name: "Symbola"
+  color: 0, 0, 0, 1
+  text_size: None, None
+  halign: "left"
+  size_hint: None, None
+  width: self.texture_size[0]
+
+<ActionListDescription>:
+  font_name: "Ubuntu"
+  color: 0, 0, 0, 1
+  text_size: self.width, None
+  shorten: True
+  shorten_from: "right"
+  split_str: ""
+  halign: "left"
+  size_hint: 1, None
+
 <PlayList>:
   size_hint: None, None
   labels_height: self.parent.max_height or 1
   color: 0, 0, 0, 1
   text_size: None, None
   halign: "left"
-  size_hint: 1, None
+  size_hint: None, None
   width: self.texture_size[0]
 
 <PlayListName>:
   font_name: "Ubuntu"
   color: 0, 0, 0, 1
-  text_size: None, None
+  text_size: self.width, None
+  shorten: True
+  shorten_from: "right"
+  split_str: ""
   halign: "left"
-  size_hint: None, None
-  width: self.texture_size[0]
+  size_hint: 1, None
 
 <PlayListTime>:
   canvas.before: