aboutsummaryrefslogtreecommitdiff
path: root/music_sampler/app_blocks
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2016-07-29 01:04:24 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2016-07-29 01:04:24 +0200
commit4d1dfc89066e8dbccf7e5049686895de6fcb32d2 (patch)
treec2560a9ac1c15d08e69924e55d93d448768bdec3 /music_sampler/app_blocks
parent182b6ab1544840ac1827dc95e7f6cd0f1c8d4862 (diff)
downloadMusicSampler-4d1dfc89066e8dbccf7e5049686895de6fcb32d2.tar.gz
MusicSampler-4d1dfc89066e8dbccf7e5049686895de6fcb32d2.tar.zst
MusicSampler-4d1dfc89066e8dbccf7e5049686895de6fcb32d2.zip
Lock widget modifications and reuse labels in actionlist/playlist
Diffstat (limited to 'music_sampler/app_blocks')
-rw-r--r--music_sampler/app_blocks/actionlist.py68
-rw-r--r--music_sampler/app_blocks/playlist.py97
2 files changed, 114 insertions, 51 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
diff --git a/music_sampler/app_blocks/playlist.py b/music_sampler/app_blocks/playlist.py
index b704d4d..5894995 100644
--- a/music_sampler/app_blocks/playlist.py
+++ b/music_sampler/app_blocks/playlist.py
@@ -4,14 +4,15 @@ from kivy.uix.relativelayout import RelativeLayout
4from kivy.properties import ListProperty 4from kivy.properties import ListProperty
5from kivy.clock import Clock 5from kivy.clock import Clock
6from ..helpers import duration_to_min_sec 6from ..helpers import duration_to_min_sec
7 7from ..lock import Lock
8import math
9 8
10__all__ = ["PlayList", 9__all__ = ["PlayList",
11 "PlayListIcons", "PlayListIcon", 10 "PlayListIcons", "PlayListIcon",
12 "PlayListNames", "PlayListName", 11 "PlayListNames", "PlayListName",
13 "PlayListTimes", "PlayListTime"] 12 "PlayListTimes", "PlayListTime"]
14 13
14playlist_lock = Lock("playlist")
15
15class PlayList(RelativeLayout): 16class PlayList(RelativeLayout):
16 playlist = ListProperty([]) 17 playlist = ListProperty([])
17 18
@@ -37,7 +38,8 @@ class PlayList(RelativeLayout):
37 playlist.append(["⏸", music_file.name, time_info, False]) 38 playlist.append(["⏸", music_file.name, time_info, False])
38 else: 39 else:
39 playlist.append(["⏵", music_file.name, time_info, True]) 40 playlist.append(["⏵", music_file.name, time_info, True])
40 self.playlist = playlist 41 with playlist_lock:
42 self.playlist = playlist
41 43
42 44
43class PlayListIcons(StackLayout): 45class PlayListIcons(StackLayout):
@@ -49,13 +51,19 @@ class PlayListIcons(StackLayout):
49 parent.bind(playlist=self.update_playlist_icons) 51 parent.bind(playlist=self.update_playlist_icons)
50 52
51 def update_playlist_icons(self, instance, playlist): 53 def update_playlist_icons(self, instance, playlist):
52 for icon in self.icons: 54 icons_length = len(self.icons)
53 self.remove_widget(icon) 55 index = -1
54 self.icons = [] 56 for index, [icon, filename, time_info, playing] in enumerate(playlist):
55 for icon, filename, time_info, playing in playlist: 57 if index >= icons_length:
56 icon_label = PlayListIcon(text=icon) 58 icon_label = PlayListIcon(text=icon)
57 self.add_widget(icon_label) 59 self.add_widget(icon_label)
58 self.icons.append(icon_label) 60 self.icons.append(icon_label)
61 else:
62 self.icons[index].text = icon
63
64 if index+1 < icons_length:
65 self.clear_widgets(children=self.icons[index+1:icons_length])
66 del(self.icons[index+1:icons_length])
59 67
60class PlayListIcon(Label): 68class PlayListIcon(Label):
61 def __init__(self, text='', **kwargs): 69 def __init__(self, text='', **kwargs):
@@ -64,9 +72,14 @@ class PlayListIcon(Label):
64 72
65 def on_parent(self, instance, parent): 73 def on_parent(self, instance, parent):
66 if parent is not None: 74 if parent is not None:
67 self.font_size = math.ceil(2 * math.sqrt(parent.parent.parent.key_size)) 75 parent.bind(font_size=self.update_font_size)
68 self.height = parent.parent.labels_height 76 parent.bind(labels_height=self.update_height)
77
78 def update_height(self, instance, height):
79 self.height = height
69 80
81 def update_font_size(self, instance, font_size):
82 self.font_size = font_size
70 83
71class PlayListNames(StackLayout): 84class PlayListNames(StackLayout):
72 def __init__(self, **kwargs): 85 def __init__(self, **kwargs):
@@ -77,13 +90,19 @@ class PlayListNames(StackLayout):
77 parent.bind(playlist=self.update_playlist_names) 90 parent.bind(playlist=self.update_playlist_names)
78 91
79 def update_playlist_names(self, instance, playlist): 92 def update_playlist_names(self, instance, playlist):
80 for name in self.names: 93 names_length = len(self.names)
81 self.remove_widget(name) 94 index = -1
82 self.names = [] 95 for index, [icon, filename, time_info, playing] in enumerate(playlist):
83 for icon, filename, time_info, playing in playlist: 96 if index >= names_length:
84 name_label = PlayListName(text=filename, is_playing=playing) 97 name_label = PlayListName(text=filename, is_playing=playing)
85 self.add_widget(name_label) 98 self.add_widget(name_label)
86 self.names.append(name_label) 99 self.names.append(name_label)
100 else:
101 self.names[index].text = filename
102
103 if index+1 < names_length:
104 self.clear_widgets(children=self.names[index+1:names_length])
105 del(self.names[index+1:names_length])
87 106
88class PlayListName(Label): 107class PlayListName(Label):
89 def __init__(self, text='', is_playing=False, **kwargs): 108 def __init__(self, text='', is_playing=False, **kwargs):
@@ -93,8 +112,14 @@ class PlayListName(Label):
93 112
94 def on_parent(self, instance, parent): 113 def on_parent(self, instance, parent):
95 if parent is not None: 114 if parent is not None:
96 self.font_size = math.ceil(2 * math.sqrt(parent.parent.parent.key_size)) 115 parent.bind(font_size=self.update_font_size)
97 self.height = parent.parent.labels_height 116 parent.bind(labels_height=self.update_height)
117
118 def update_height(self, instance, height):
119 self.height = height
120
121 def update_font_size(self, instance, font_size):
122 self.font_size = font_size
98 123
99class PlayListTimes(StackLayout): 124class PlayListTimes(StackLayout):
100 def __init__(self, **kwargs): 125 def __init__(self, **kwargs):
@@ -105,13 +130,19 @@ class PlayListTimes(StackLayout):
105 parent.bind(playlist=self.update_playlist_times) 130 parent.bind(playlist=self.update_playlist_times)
106 131
107 def update_playlist_times(self, instance, playlist): 132 def update_playlist_times(self, instance, playlist):
108 for time in self.times: 133 times_length = len(self.times)
109 self.remove_widget(time) 134 index = -1
110 self.times = [] 135 for index, [icon, filename, time_info, playing] in enumerate(playlist):
111 for icon, filename, time_info, playing in playlist: 136 if index >= times_length:
112 time_label = PlayListTime(text=time_info) 137 time_label = PlayListTime(text=time_info)
113 self.add_widget(time_label) 138 self.add_widget(time_label)
114 self.times.append(time_label) 139 self.times.append(time_label)
140 else:
141 self.times[index].text = time_info
142
143 if index+1 < times_length:
144 self.clear_widgets(children=self.times[index+1:times_length])
145 del(self.times[index+1:times_length])
115 146
116class PlayListTime(Label): 147class PlayListTime(Label):
117 def __init__(self, text='', **kwargs): 148 def __init__(self, text='', **kwargs):
@@ -120,6 +151,12 @@ class PlayListTime(Label):
120 151
121 def on_parent(self, instance, parent): 152 def on_parent(self, instance, parent):
122 if parent is not None: 153 if parent is not None:
123 self.font_size = math.ceil(2 * math.sqrt(parent.parent.parent.key_size)) 154 parent.bind(font_size=self.update_font_size)
124 self.height = parent.parent.labels_height 155 parent.bind(labels_height=self.update_height)
156
157 def update_height(self, instance, height):
158 self.height = height
159
160 def update_font_size(self, instance, font_size):
161 self.font_size = font_size
125 162