aboutsummaryrefslogtreecommitdiff
path: root/music_sampler/app_blocks/playlist.py
diff options
context:
space:
mode:
Diffstat (limited to 'music_sampler/app_blocks/playlist.py')
-rw-r--r--music_sampler/app_blocks/playlist.py97
1 files changed, 67 insertions, 30 deletions
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