]>
git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blob - music_sampler/app_blocks/playlist.py
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
10 __all__
= ["PlayList",
11 "PlayListIcons", "PlayListIcon",
12 "PlayListNames", "PlayListName",
13 "PlayListTimes", "PlayListTime"]
15 class PlayList(RelativeLayout
):
16 playlist
= ListProperty([])
18 def __init__(self
, **kwargs
):
19 super(PlayList
, self
).__init
__(**kwargs
)
20 Clock
.schedule_interval(self
.update_playlist
, 0.5)
22 def update_playlist(self
, dt
):
23 if self
.parent
is None or 'Mapping' not in self
.parent
.ids
:
26 open_files
= self
.parent
.ids
['Mapping'].open_files
28 for music_file
in open_files
.values():
29 if not music_file
.is_in_use():
32 time_info
= "{}/{}".format(
33 duration_to_min_sec(music_file
.sound_position
),
34 duration_to_min_sec(music_file
.sound_duration
))
36 if music_file
.is_loaded_paused():
37 playlist
.append(["⏸", music_file
.name
, time_info
, False])
39 playlist
.append(["⏵", music_file
.name
, time_info
, True])
40 self
.playlist
= playlist
43 class PlayListIcons(StackLayout
):
44 def __init__(self
, **kwargs
):
45 super(PlayListIcons
, self
).__init
__(**kwargs
)
48 def on_parent(self
, instance
, parent
):
49 parent
.bind(playlist
=self
.update_playlist_icons
)
51 def update_playlist_icons(self
, instance
, playlist
):
52 for icon
in self
.icons
:
53 self
.remove_widget(icon
)
55 for icon
, filename
, time_info
, playing
in playlist
:
56 icon_label
= PlayListIcon(text
=icon
)
57 self
.add_widget(icon_label
)
58 self
.icons
.append(icon_label
)
60 class PlayListIcon(Label
):
61 def __init__(self
, text
='', **kwargs
):
62 super(PlayListIcon
, self
).__init
__(**kwargs
)
65 def on_parent(self
, instance
, parent
):
66 if parent
is not None:
67 self
.font_size
= math
.ceil(2 * math
.sqrt(parent
.parent
.parent
.key_size
))
68 self
.height
= parent
.parent
.labels_height
71 class PlayListNames(StackLayout
):
72 def __init__(self
, **kwargs
):
73 super(PlayListNames
, self
).__init
__(**kwargs
)
76 def on_parent(self
, instance
, parent
):
77 parent
.bind(playlist
=self
.update_playlist_names
)
79 def update_playlist_names(self
, instance
, playlist
):
80 for name
in self
.names
:
81 self
.remove_widget(name
)
83 for icon
, filename
, time_info
, playing
in playlist
:
84 name_label
= PlayListName(text
=filename
, is_playing
=playing
)
85 self
.add_widget(name_label
)
86 self
.names
.append(name_label
)
88 class PlayListName(Label
):
89 def __init__(self
, text
='', is_playing
=False, **kwargs
):
90 super(PlayListName
, self
).__init
__(**kwargs
)
92 self
.bold
= is_playing
94 def on_parent(self
, instance
, parent
):
95 if parent
is not None:
96 self
.font_size
= math
.ceil(2 * math
.sqrt(parent
.parent
.parent
.key_size
))
97 self
.height
= parent
.parent
.labels_height
99 class PlayListTimes(StackLayout
):
100 def __init__(self
, **kwargs
):
101 super(PlayListTimes
, self
).__init
__(**kwargs
)
104 def on_parent(self
, instance
, parent
):
105 parent
.bind(playlist
=self
.update_playlist_times
)
107 def update_playlist_times(self
, instance
, playlist
):
108 for time
in self
.times
:
109 self
.remove_widget(time
)
111 for icon
, filename
, time_info
, playing
in playlist
:
112 time_label
= PlayListTime(text
=time_info
)
113 self
.add_widget(time_label
)
114 self
.times
.append(time_label
)
116 class PlayListTime(Label
):
117 def __init__(self
, text
='', **kwargs
):
118 super(PlayListTime
, self
).__init
__(**kwargs
)
121 def on_parent(self
, instance
, parent
):
122 if parent
is not None:
123 self
.font_size
= math
.ceil(2 * math
.sqrt(parent
.parent
.parent
.key_size
))
124 self
.height
= parent
.parent
.labels_height