]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blame - music_sampler.py
Make kivy compatible with pyinstaller
[perso/Immae/Projets/Python/MusicSampler.git] / music_sampler.py
CommitLineData
4b2d79ca
IB
1from kivy.app import App
2from kivy.uix.floatlayout import FloatLayout
3from kivy.uix.relativelayout import RelativeLayout
4from kivy.properties import ListProperty, StringProperty
5from kivy.clock import Clock
6from kivy.core.window import Window
bb69f62e 7from kivy.lang import Builder
4b2d79ca
IB
8from helpers.key import Key
9from helpers.mapping import Mapping
10
bb69f62e
IB
11import sys
12
13if getattr(sys, 'frozen', False):
14 Builder.load_file(sys._MEIPASS + '/musicsampler.kv')
15
4b2d79ca
IB
16class PlayList(RelativeLayout):
17 playlist = ListProperty([])
18
19 def __init__(self, **kwargs):
20 super(PlayList, self).__init__(**kwargs)
21 Clock.schedule_interval(self.update_playlist, 0.5)
22
23 def update_playlist(self, dt):
24 if self.parent is None or 'Mapping' not in self.parent.ids:
25 return True
26
27 open_files = self.parent.ids['Mapping'].open_files
28 self.playlist = []
29 for music_file in open_files.values():
30 if not music_file.is_playing():
31 continue
32 if music_file.is_paused():
33 self.playlist.append(["⏸", music_file.name, False])
34 else:
35 self.playlist.append(["⏵", music_file.name, True])
189bf90c 36
189bf90c 37
4b2d79ca
IB
38class ActionList(RelativeLayout):
39 action_title = StringProperty("")
40 action_list = ListProperty([])
189bf90c 41
4b2d79ca
IB
42 def update_list(self, key, action_number = 0):
43 self.action_title = "actions linked to key {}:".format(key.key_sym)
44 self.action_list = []
189bf90c 45
4b2d79ca 46 action_descriptions = [action.description() for action in key.actions]
e7f8dab4 47
4b2d79ca
IB
48 for index, description in enumerate(action_descriptions):
49 if index < int(action_number):
50 icon = "✓"
51 elif index + 0.5 == action_number:
52 icon = "✅"
53 else:
54 icon = " "
be27763f 55
4b2d79ca 56 self.action_list.append([icon, description])
189bf90c 57
4b2d79ca
IB
58class Screen(FloatLayout):
59 pass
189bf90c 60
4b2d79ca
IB
61class MusicSamplerApp(App):
62 def build(self):
63 Window.size = (913, 563)
9de92b6d 64
4b2d79ca 65 return Screen()
9de92b6d 66
4b2d79ca
IB
67if __name__ == '__main__':
68 MusicSamplerApp().run()