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.py68
1 files changed, 47 insertions, 21 deletions
diff --git a/music_sampler/app_blocks/actionlist.py b/music_sampler/app_blocks/actionlist.py
index 70fe3f4..51f4b82 100644
--- a/music_sampler/app_blocks/actionlist.py
+++ b/music_sampler/app_blocks/actionlist.py
@@ -2,13 +2,14 @@ from kivy.uix.label import Label
2from kivy.uix.stacklayout import StackLayout 2from kivy.uix.stacklayout import StackLayout
3from kivy.uix.relativelayout import RelativeLayout 3from kivy.uix.relativelayout import RelativeLayout
4from kivy.properties import ListProperty, StringProperty 4from kivy.properties import ListProperty, StringProperty
5 5from ..lock import Lock
6import math
7 6
8__all__ = ["ActionList", 7__all__ = ["ActionList",
9 "ActionListIcons", "ActionListIcon", 8 "ActionListIcons", "ActionListIcon",
10 "ActionListDescriptions", "ActionListDescription"] 9 "ActionListDescriptions", "ActionListDescription"]
11 10
11actionlist_lock = Lock("playlist")
12
12class ActionList(RelativeLayout): 13class ActionList(RelativeLayout):
13 action_title = StringProperty("") 14 action_title = StringProperty("")
14 action_list = ListProperty([]) 15 action_list = ListProperty([])
@@ -25,7 +26,8 @@ class ActionList(RelativeLayout):
25 else: 26 else:
26 icon = " " 27 icon = " "
27 action_list.append([icon, action]) 28 action_list.append([icon, action])
28 self.action_list = action_list 29 with actionlist_lock:
30 self.action_list = action_list
29 31
30class ActionListIcons(StackLayout): 32class ActionListIcons(StackLayout):
31 def __init__(self, **kwargs): 33 def __init__(self, **kwargs):
@@ -36,13 +38,19 @@ class ActionListIcons(StackLayout):
36 parent.bind(action_list=self.update_actionlist_icons) 38 parent.bind(action_list=self.update_actionlist_icons)
37 39
38 def update_actionlist_icons(self, instance, actionlist): 40 def update_actionlist_icons(self, instance, actionlist):
39 for icon in self.icons: 41 icons_length = len(self.icons)
40 self.remove_widget(icon) 42 index = -1
41 self.icons = [] 43 for index, [icon, description] in enumerate(actionlist):
42 for icon, description in actionlist: 44 if index >= icons_length:
43 icon_label = ActionListIcon(text=icon) 45 icon_label = ActionListIcon(text=icon)
44 self.add_widget(icon_label) 46 self.add_widget(icon_label)
45 self.icons.append(icon_label) 47 self.icons.append(icon_label)
48 else:
49 self.icons[index].text = icon
50
51 if index+1 < icons_length:
52 self.clear_widgets(children=self.icons[index+1:icons_length])
53 del(self.icons[index+1:icons_length])
46 54
47class ActionListIcon(Label): 55class ActionListIcon(Label):
48 def __init__(self, text='', **kwargs): 56 def __init__(self, text='', **kwargs):
@@ -51,8 +59,14 @@ class ActionListIcon(Label):
51 59
52 def on_parent(self, instance, parent): 60 def on_parent(self, instance, parent):
53 if parent is not None: 61 if parent is not None:
54 self.font_size = math.ceil(2 * math.sqrt(parent.parent.parent.key_size)) 62 parent.bind(font_size=self.update_font_size)
55 self.height = parent.parent.labels_height 63 parent.bind(labels_height=self.update_height)
64
65 def update_height(self, instance, height):
66 self.height = height
67
68 def update_font_size(self, instance, font_size):
69 self.font_size = font_size
56 70
57class ActionListDescriptions(StackLayout): 71class ActionListDescriptions(StackLayout):
58 def __init__(self, **kwargs): 72 def __init__(self, **kwargs):
@@ -63,13 +77,20 @@ class ActionListDescriptions(StackLayout):
63 parent.bind(action_list=self.update_actionlist_descriptions) 77 parent.bind(action_list=self.update_actionlist_descriptions)
64 78
65 def update_actionlist_descriptions(self, instance, actionlist): 79 def update_actionlist_descriptions(self, instance, actionlist):
66 for description in self.descriptions: 80 descriptions_length = len(self.descriptions)
67 self.remove_widget(description) 81 index = -1
68 self.descriptions = [] 82 for index, [icon, description] in enumerate(actionlist):
69 for icon, description in actionlist: 83 if index >= descriptions_length:
70 description_label = ActionListDescription(text=description) 84 description_label = ActionListDescription(text=description)
71 self.add_widget(description_label) 85 self.add_widget(description_label)
72 self.descriptions.append(description_label) 86 self.descriptions.append(description_label)
87 else:
88 self.descriptions[index].text = description
89
90 if index+1 < descriptions_length:
91 self.clear_widgets(
92 children=self.descriptions[index+1:descriptions_length])
93 del(self.descriptions[index+1:descriptions_length])
73 94
74class ActionListDescription(Label): 95class ActionListDescription(Label):
75 def __init__(self, text='', **kwargs): 96 def __init__(self, text='', **kwargs):
@@ -78,7 +99,12 @@ class ActionListDescription(Label):
78 99
79 def on_parent(self, instance, parent): 100 def on_parent(self, instance, parent):
80 if parent is not None: 101 if parent is not None:
81 self.font_size = math.ceil(2 * math.sqrt(parent.parent.parent.key_size)) 102 parent.bind(font_size=self.update_font_size)
82 self.height = parent.parent.labels_height 103 parent.bind(labels_height=self.update_height)
104
105 def update_height(self, instance, height):
106 self.height = height
83 107
108 def update_font_size(self, instance, font_size):
109 self.font_size = font_size
84 110