]>
git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blob - music_sampler/app_blocks/playlist.py
5894995bc71aa66a3b692e89f0460452a10a5d2c
1 from kivy
.uix
.label
import Label
2 from kivy
.uix
.stacklayout
import StackLayout
3 from kivy
.uix
.relativelayout
import RelativeLayout
4 from kivy
.properties
import ListProperty
5 from kivy
.clock
import Clock
6 from ..helpers
import duration_to_min_sec
7 from ..lock
import Lock
10 "PlayListIcons", "PlayListIcon",
11 "PlayListNames", "PlayListName",
12 "PlayListTimes", "PlayListTime"]
14 playlist_lock
= Lock("playlist")
16 class PlayList(RelativeLayout
):
17 playlist
= ListProperty([])
19 def __init__(self
, **kwargs
):
20 super(PlayList
, self
).__init
__(**kwargs
)
21 Clock
.schedule_interval(self
.update_playlist
, 0.5)
23 def update_playlist(self
, dt
):
24 if self
.parent
is None or 'Mapping' not in self
.parent
.ids
:
27 open_files
= self
.parent
.ids
['Mapping'].open_files
29 for music_file
in open_files
.values():
30 if not music_file
.is_in_use():
33 time_info
= "{}/{}".format(
34 duration_to_min_sec(music_file
.sound_position
),
35 duration_to_min_sec(music_file
.sound_duration
))
37 if music_file
.is_loaded_paused():
38 playlist
.append(["⏸", music_file
.name
, time_info
, False])
40 playlist
.append(["⏵", music_file
.name
, time_info
, True])
42 self
.playlist
= playlist
45 class PlayListIcons(StackLayout
):
46 def __init__(self
, **kwargs
):
47 super(PlayListIcons
, self
).__init
__(**kwargs
)
50 def on_parent(self
, instance
, parent
):
51 parent
.bind(playlist
=self
.update_playlist_icons
)
53 def update_playlist_icons(self
, instance
, playlist
):
54 icons_length
= len(self
.icons
)
56 for index
, [icon
, filename
, time_info
, playing
] in enumerate(playlist
):
57 if index
>= icons_length
:
58 icon_label
= PlayListIcon(text
=icon
)
59 self
.add_widget(icon_label
)
60 self
.icons
.append(icon_label
)
62 self
.icons
[index
].text
= icon
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
])
68 class PlayListIcon(Label
):
69 def __init__(self
, text
='', **kwargs
):
70 super(PlayListIcon
, self
).__init
__(**kwargs
)
73 def on_parent(self
, instance
, parent
):
74 if parent
is not None:
75 parent
.bind(font_size
=self
.update_font_size
)
76 parent
.bind(labels_height
=self
.update_height
)
78 def update_height(self
, instance
, height
):
81 def update_font_size(self
, instance
, font_size
):
82 self
.font_size
= font_size
84 class PlayListNames(StackLayout
):
85 def __init__(self
, **kwargs
):
86 super(PlayListNames
, self
).__init
__(**kwargs
)
89 def on_parent(self
, instance
, parent
):
90 parent
.bind(playlist
=self
.update_playlist_names
)
92 def update_playlist_names(self
, instance
, playlist
):
93 names_length
= len(self
.names
)
95 for index
, [icon
, filename
, time_info
, playing
] in enumerate(playlist
):
96 if index
>= names_length
:
97 name_label
= PlayListName(text
=filename
, is_playing
=playing
)
98 self
.add_widget(name_label
)
99 self
.names
.append(name_label
)
101 self
.names
[index
].text
= filename
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
])
107 class PlayListName(Label
):
108 def __init__(self
, text
='', is_playing
=False, **kwargs
):
109 super(PlayListName
, self
).__init
__(**kwargs
)
111 self
.bold
= is_playing
113 def on_parent(self
, instance
, parent
):
114 if parent
is not None:
115 parent
.bind(font_size
=self
.update_font_size
)
116 parent
.bind(labels_height
=self
.update_height
)
118 def update_height(self
, instance
, height
):
121 def update_font_size(self
, instance
, font_size
):
122 self
.font_size
= font_size
124 class PlayListTimes(StackLayout
):
125 def __init__(self
, **kwargs
):
126 super(PlayListTimes
, self
).__init
__(**kwargs
)
129 def on_parent(self
, instance
, parent
):
130 parent
.bind(playlist
=self
.update_playlist_times
)
132 def update_playlist_times(self
, instance
, playlist
):
133 times_length
= len(self
.times
)
135 for index
, [icon
, filename
, time_info
, playing
] in enumerate(playlist
):
136 if index
>= times_length
:
137 time_label
= PlayListTime(text
=time_info
)
138 self
.add_widget(time_label
)
139 self
.times
.append(time_label
)
141 self
.times
[index
].text
= time_info
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
])
147 class PlayListTime(Label
):
148 def __init__(self
, text
='', **kwargs
):
149 super(PlayListTime
, self
).__init
__(**kwargs
)
152 def on_parent(self
, instance
, parent
):
153 if parent
is not None:
154 parent
.bind(font_size
=self
.update_font_size
)
155 parent
.bind(labels_height
=self
.update_height
)
157 def update_height(self
, instance
, height
):
160 def update_font_size(self
, instance
, font_size
):
161 self
.font_size
= font_size