aboutsummaryrefslogtreecommitdiff
path: root/music_sampler/app_blocks/actionlist.py
diff options
context:
space:
mode:
Diffstat (limited to 'music_sampler/app_blocks/actionlist.py')
-rw-r--r--music_sampler/app_blocks/actionlist.py84
1 files changed, 84 insertions, 0 deletions
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 @@
1from kivy.uix.label import Label
2from kivy.uix.stacklayout import StackLayout
3from kivy.uix.relativelayout import RelativeLayout
4from kivy.properties import ListProperty, StringProperty
5
6import math
7
8__all__ = ["ActionList",
9 "ActionListIcons", "ActionListIcon",
10 "ActionListDescriptions", "ActionListDescription"]
11
12class ActionList(RelativeLayout):
13 action_title = StringProperty("")
14 action_list = ListProperty([])
15
16 def update_list(self, key, action_descriptions):
17 self.action_title = "actions linked to key {}:".format(key.key_sym)
18 action_list = []
19
20 for [action, status] in action_descriptions:
21 if status == "done":
22 icon = "✓"
23 elif status == "current":
24 icon = "✅"
25 else:
26 icon = " "
27 action_list.append([icon, action])
28 self.action_list = action_list
29
30class ActionListIcons(StackLayout):
31 def __init__(self, **kwargs):
32 super(ActionListIcons, self).__init__(**kwargs)
33 self.icons = []
34
35 def on_parent(self, instance, parent):
36 parent.bind(action_list=self.update_actionlist_icons)
37
38 def update_actionlist_icons(self, instance, actionlist):
39 for icon in self.icons:
40 self.remove_widget(icon)
41 self.icons = []
42 for icon, description in actionlist:
43 icon_label = ActionListIcon(text=icon)
44 self.add_widget(icon_label)
45 self.icons.append(icon_label)
46
47class ActionListIcon(Label):
48 def __init__(self, text='', **kwargs):
49 super(ActionListIcon, self).__init__(**kwargs)
50 self.text = text
51
52 def on_parent(self, instance, parent):
53 if parent is not None:
54 self.font_size = math.ceil(2 * math.sqrt(parent.parent.parent.key_size))
55 self.height = parent.parent.labels_height
56
57class ActionListDescriptions(StackLayout):
58 def __init__(self, **kwargs):
59 super(ActionListDescriptions, self).__init__(**kwargs)
60 self.descriptions = []
61
62 def on_parent(self, instance, parent):
63 parent.bind(action_list=self.update_actionlist_descriptions)
64
65 def update_actionlist_descriptions(self, instance, actionlist):
66 for description in self.descriptions:
67 self.remove_widget(description)
68 self.descriptions = []
69 for icon, description in actionlist:
70 description_label = ActionListDescription(text=description)
71 self.add_widget(description_label)
72 self.descriptions.append(description_label)
73
74class ActionListDescription(Label):
75 def __init__(self, text='', **kwargs):
76 super(ActionListDescription, self).__init__(**kwargs)
77 self.text = text
78
79 def on_parent(self, instance, parent):
80 if parent is not None:
81 self.font_size = math.ceil(2 * math.sqrt(parent.parent.parent.key_size))
82 self.height = parent.parent.labels_height
83
84