]>
git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blob - playlist.py
706e4fc32c9654febe6450abb7b5559050aebff7
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
, mainthread
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)
24 def update_playlist(self
, dt
):
25 if self
.parent
is None or 'Mapping' not in self
.parent
.ids
:
28 open_files
= self
.parent
.ids
['Mapping'].open_files
30 for music_file
in open_files
.values():
31 if not music_file
.is_in_use():
34 time_info
= "{}/{}".format(
35 duration_to_min_sec(music_file
.sound_position
),
36 duration_to_min_sec(music_file
.sound_duration
))
38 if music_file
.is_loaded_paused():
39 playlist
.append(["⏸", music_file
.name
, time_info
, False])
41 playlist
.append(["⏵", music_file
.name
, time_info
, True])
43 self
.playlist
= playlist
46 class PlayListIcons(StackLayout
):
47 def __init__(self
, **kwargs
):
48 super(PlayListIcons
, self
).__init
__(**kwargs
)
51 def on_parent(self
, instance
, parent
):
52 parent
.bind(playlist
=self
.update_playlist_icons
)
54 def update_playlist_icons(self
, instance
, playlist
):
55 icons_length
= len(self
.icons
)
57 for index
, [icon
, filename
, time_info
, playing
] in enumerate(playlist
):
58 if index
>= icons_length
:
59 icon_label
= PlayListIcon(text
=icon
)
60 self
.add_widget(icon_label
)
61 self
.icons
.append(icon_label
)
63 self
.icons
[index
].text
= icon
65 if index
+1 < icons_length
:
66 self
.clear_widgets(children
=self
.icons
[index
+1:icons_length
])
67 del(self
.icons
[index
+1:icons_length
])
69 class PlayListIcon(Label
):
70 def __init__(self
, text
='', **kwargs
):
71 super(PlayListIcon
, self
).__init
__(**kwargs
)
74 def on_parent(self
, instance
, parent
):
75 if parent
is not None:
76 parent
.bind(font_size
=self
.update_font_size
)
77 parent
.bind(labels_height
=self
.update_height
)
79 def update_height(self
, instance
, height
):
82 def update_font_size(self
, instance
, font_size
):
83 self
.font_size
= font_size
85 class PlayListNames(StackLayout
):
86 def __init__(self
, **kwargs
):
87 super(PlayListNames
, self
).__init
__(**kwargs
)
90 def on_parent(self
, instance
, parent
):
91 parent
.bind(playlist
=self
.update_playlist_names
)
93 def update_playlist_names(self
, instance
, playlist
):
94 names_length
= len(self
.names
)
96 for index
, [icon
, filename
, time_info
, playing
] in enumerate(playlist
):
97 if index
>= names_length
:
98 name_label
= PlayListName(text
=filename
, is_playing
=playing
)
99 self
.add_widget(name_label
)
100 self
.names
.append(name_label
)
102 self
.names
[index
].text
= filename
104 if index
+1 < names_length
:
105 self
.clear_widgets(children
=self
.names
[index
+1:names_length
])
106 del(self
.names
[index
+1:names_length
])
108 class PlayListName(Label
):
109 def __init__(self
, text
='', is_playing
=False, **kwargs
):
110 super(PlayListName
, self
).__init
__(**kwargs
)
112 self
.bold
= is_playing
114 def on_parent(self
, instance
, parent
):
115 if parent
is not None:
116 parent
.bind(font_size
=self
.update_font_size
)
117 parent
.bind(labels_height
=self
.update_height
)
119 def update_height(self
, instance
, height
):
122 def update_font_size(self
, instance
, font_size
):
123 self
.font_size
= font_size
125 class PlayListTimes(StackLayout
):
126 def __init__(self
, **kwargs
):
127 super(PlayListTimes
, self
).__init
__(**kwargs
)
130 def on_parent(self
, instance
, parent
):
131 parent
.bind(playlist
=self
.update_playlist_times
)
133 def update_playlist_times(self
, instance
, playlist
):
134 times_length
= len(self
.times
)
136 for index
, [icon
, filename
, time_info
, playing
] in enumerate(playlist
):
137 if index
>= times_length
:
138 time_label
= PlayListTime(text
=time_info
)
139 self
.add_widget(time_label
)
140 self
.times
.append(time_label
)
142 self
.times
[index
].text
= time_info
144 if index
+1 < times_length
:
145 self
.clear_widgets(children
=self
.times
[index
+1:times_length
])
146 del(self
.times
[index
+1:times_length
])
148 class PlayListTime(Label
):
149 def __init__(self
, text
='', **kwargs
):
150 super(PlayListTime
, self
).__init
__(**kwargs
)
153 def on_parent(self
, instance
, parent
):
154 if parent
is not None:
155 parent
.bind(font_size
=self
.update_font_size
)
156 parent
.bind(labels_height
=self
.update_height
)
158 def update_height(self
, instance
, height
):
161 def update_font_size(self
, instance
, font_size
):
162 self
.font_size
= font_size