diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2016-07-29 01:04:24 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2016-07-29 01:04:24 +0200 |
commit | 4d1dfc89066e8dbccf7e5049686895de6fcb32d2 (patch) | |
tree | c2560a9ac1c15d08e69924e55d93d448768bdec3 /music_sampler | |
parent | 182b6ab1544840ac1827dc95e7f6cd0f1c8d4862 (diff) | |
download | MusicSampler-4d1dfc89066e8dbccf7e5049686895de6fcb32d2.tar.gz MusicSampler-4d1dfc89066e8dbccf7e5049686895de6fcb32d2.tar.zst MusicSampler-4d1dfc89066e8dbccf7e5049686895de6fcb32d2.zip |
Lock widget modifications and reuse labels in actionlist/playlist
Diffstat (limited to 'music_sampler')
-rw-r--r-- | music_sampler/app_blocks/actionlist.py | 68 | ||||
-rw-r--r-- | music_sampler/app_blocks/playlist.py | 97 | ||||
-rw-r--r-- | music_sampler/music_sampler.kv | 24 |
3 files changed, 137 insertions, 52 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 | |||
2 | from kivy.uix.stacklayout import StackLayout | 2 | from kivy.uix.stacklayout import StackLayout |
3 | from kivy.uix.relativelayout import RelativeLayout | 3 | from kivy.uix.relativelayout import RelativeLayout |
4 | from kivy.properties import ListProperty, StringProperty | 4 | from kivy.properties import ListProperty, StringProperty |
5 | 5 | from ..lock import Lock | |
6 | import math | ||
7 | 6 | ||
8 | __all__ = ["ActionList", | 7 | __all__ = ["ActionList", |
9 | "ActionListIcons", "ActionListIcon", | 8 | "ActionListIcons", "ActionListIcon", |
10 | "ActionListDescriptions", "ActionListDescription"] | 9 | "ActionListDescriptions", "ActionListDescription"] |
11 | 10 | ||
11 | actionlist_lock = Lock("playlist") | ||
12 | |||
12 | class ActionList(RelativeLayout): | 13 | class 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 | ||
30 | class ActionListIcons(StackLayout): | 32 | class 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 | ||
47 | class ActionListIcon(Label): | 55 | class 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 | ||
57 | class ActionListDescriptions(StackLayout): | 71 | class 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 | ||
74 | class ActionListDescription(Label): | 95 | class 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 | |||
4 | from kivy.properties import ListProperty | 4 | from kivy.properties import ListProperty |
5 | from kivy.clock import Clock | 5 | from kivy.clock import Clock |
6 | from ..helpers import duration_to_min_sec | 6 | from ..helpers import duration_to_min_sec |
7 | 7 | from ..lock import Lock | |
8 | import 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 | ||
14 | playlist_lock = Lock("playlist") | ||
15 | |||
15 | class PlayList(RelativeLayout): | 16 | class 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 | ||
43 | class PlayListIcons(StackLayout): | 45 | class 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 | ||
60 | class PlayListIcon(Label): | 68 | class 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 | ||
71 | class PlayListNames(StackLayout): | 84 | class 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 | ||
88 | class PlayListName(Label): | 107 | class 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 | ||
99 | class PlayListTimes(StackLayout): | 124 | class 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 | ||
116 | class PlayListTime(Label): | 147 | class 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 | ||
diff --git a/music_sampler/music_sampler.kv b/music_sampler/music_sampler.kv index 4a91896..ffc2797 100644 --- a/music_sampler/music_sampler.kv +++ b/music_sampler/music_sampler.kv | |||
@@ -204,6 +204,7 @@ | |||
204 | <ActionList>: | 204 | <ActionList>: |
205 | size_hint: None, None | 205 | size_hint: None, None |
206 | labels_height: self.parent.max_height or 1 | 206 | labels_height: self.parent.max_height or 1 |
207 | font_size: math.ceil(2 * math.sqrt(self.parent.key_size or 10)) | ||
207 | canvas: | 208 | canvas: |
208 | Color: | 209 | Color: |
209 | rgba: 250./255, 250./255, 250./255, 1 | 210 | rgba: 250./255, 250./255, 250./255, 1 |
@@ -214,7 +215,7 @@ | |||
214 | id: action_list_title | 215 | id: action_list_title |
215 | font_name: "Ubuntu" | 216 | font_name: "Ubuntu" |
216 | bold: True | 217 | bold: True |
217 | font_size: math.ceil(2 * math.sqrt(self.parent.parent.key_size or 10)) | 218 | font_size: self.parent.font_size |
218 | color: 0, 0, 0, 1 | 219 | color: 0, 0, 0, 1 |
219 | text: self.parent.action_title | 220 | text: self.parent.action_title |
220 | text_size: None, self.parent.height | 221 | text_size: None, self.parent.height |
@@ -223,15 +224,21 @@ | |||
223 | size_hint: None, None | 224 | size_hint: None, None |
224 | size: self.texture_size[0], self.parent.height | 225 | size: self.texture_size[0], self.parent.height |
225 | ActionListIcons: | 226 | ActionListIcons: |
227 | font_size: self.parent.font_size | ||
228 | labels_height: self.parent.labels_height | ||
226 | orientation: 'lr-tb' | 229 | orientation: 'lr-tb' |
227 | size_hint: 0.02, 0.9 | 230 | size_hint: 0.02, 0.9 |
228 | pos_hint: { 'x': 0, 'top': 0.9 } | 231 | pos_hint: { 'x': 0, 'top': 0.9 } |
229 | ActionListDescriptions: | 232 | ActionListDescriptions: |
233 | font_size: self.parent.font_size | ||
234 | labels_height: self.parent.labels_height | ||
230 | orientation: 'lr-tb' | 235 | orientation: 'lr-tb' |
231 | size_hint: 0.98, 0.9 | 236 | size_hint: 0.98, 0.9 |
232 | pos_hint: { 'x': 0.02, 'top': 0.9 } | 237 | pos_hint: { 'x': 0.02, 'top': 0.9 } |
233 | 238 | ||
234 | <ActionListIcon>: | 239 | <ActionListIcon>: |
240 | font_size: self.parent and self.parent.font_size or 10 | ||
241 | height: self.parent and self.parent.labels_height or 0 | ||
235 | font_name: "Symbola" | 242 | font_name: "Symbola" |
236 | color: 0, 0, 0, 1 | 243 | color: 0, 0, 0, 1 |
237 | text_size: None, None | 244 | text_size: None, None |
@@ -240,6 +247,8 @@ | |||
240 | width: self.texture_size[0] | 247 | width: self.texture_size[0] |
241 | 248 | ||
242 | <ActionListDescription>: | 249 | <ActionListDescription>: |
250 | font_size: self.parent and self.parent.font_size or 10 | ||
251 | height: self.parent and self.parent.labels_height or 0 | ||
243 | font_name: "Ubuntu" | 252 | font_name: "Ubuntu" |
244 | color: 0, 0, 0, 1 | 253 | color: 0, 0, 0, 1 |
245 | text_size: self.width, None | 254 | text_size: self.width, None |
@@ -252,6 +261,7 @@ | |||
252 | <PlayList>: | 261 | <PlayList>: |
253 | size_hint: None, None | 262 | size_hint: None, None |
254 | labels_height: self.parent.max_height or 1 | 263 | labels_height: self.parent.max_height or 1 |
264 | font_size: math.ceil(2 * math.sqrt(self.parent.key_size or 10)) | ||
255 | canvas: | 265 | canvas: |
256 | Color: | 266 | Color: |
257 | rgba: 250./255, 250./255, 250./255, 1 | 267 | rgba: 250./255, 250./255, 250./255, 1 |
@@ -259,19 +269,27 @@ | |||
259 | pos: 0, 0 | 269 | pos: 0, 0 |
260 | size: self.width, self.height | 270 | size: self.width, self.height |
261 | PlayListIcons: | 271 | PlayListIcons: |
272 | font_size: self.parent.font_size | ||
273 | labels_height: self.parent.labels_height | ||
262 | orientation: 'lr-tb' | 274 | orientation: 'lr-tb' |
263 | size_hint: 0.05, 1 | 275 | size_hint: 0.05, 1 |
264 | pos_hints: { 'x': 0, 'top': 0 } | 276 | pos_hints: { 'x': 0, 'top': 0 } |
265 | PlayListNames: | 277 | PlayListNames: |
278 | font_size: self.parent.font_size | ||
279 | labels_height: self.parent.labels_height | ||
266 | orientation: 'lr-tb' | 280 | orientation: 'lr-tb' |
267 | pos_hint: { 'x': 0.05, 'bottom': 0 } | 281 | pos_hint: { 'x': 0.05, 'bottom': 0 } |
268 | size_hint: 0.65, 1 | 282 | size_hint: 0.65, 1 |
269 | PlayListTimes: | 283 | PlayListTimes: |
284 | font_size: self.parent.font_size | ||
285 | labels_height: self.parent.labels_height | ||
270 | orientation: 'lr-tb' | 286 | orientation: 'lr-tb' |
271 | pos_hint: { 'x': 0.7, 'bottom': 0 } | 287 | pos_hint: { 'x': 0.7, 'bottom': 0 } |
272 | size_hint: 0.30, 1 | 288 | size_hint: 0.30, 1 |
273 | 289 | ||
274 | <PlayListIcon>: | 290 | <PlayListIcon>: |
291 | font_size: self.parent and self.parent.font_size or 10 | ||
292 | height: self.parent and self.parent.labels_height or 0 | ||
275 | font_name: "Symbola" | 293 | font_name: "Symbola" |
276 | color: 0, 0, 0, 1 | 294 | color: 0, 0, 0, 1 |
277 | text_size: None, None | 295 | text_size: None, None |
@@ -280,6 +298,8 @@ | |||
280 | width: self.texture_size[0] | 298 | width: self.texture_size[0] |
281 | 299 | ||
282 | <PlayListName>: | 300 | <PlayListName>: |
301 | font_size: self.parent and self.parent.font_size or 10 | ||
302 | height: self.parent and self.parent.labels_height or 0 | ||
283 | font_name: "Ubuntu" | 303 | font_name: "Ubuntu" |
284 | color: 0, 0, 0, 1 | 304 | color: 0, 0, 0, 1 |
285 | text_size: self.width, None | 305 | text_size: self.width, None |
@@ -290,6 +310,8 @@ | |||
290 | size_hint: 1, None | 310 | size_hint: 1, None |
291 | 311 | ||
292 | <PlayListTime>: | 312 | <PlayListTime>: |
313 | font_size: self.parent and self.parent.font_size or 10 | ||
314 | height: self.parent and self.parent.labels_height or 0 | ||
293 | canvas.before: | 315 | canvas.before: |
294 | Color: | 316 | Color: |
295 | rgba: 250./255, 250./255, 250./255, 1 | 317 | rgba: 250./255, 250./255, 250./255, 1 |