X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=music_sampler%2Fapp.py;h=3fd6f510c2236ae490c1b116aadb53a44f6d6972;hb=HEAD;hp=81c47a7bcf65a206cf435e3f23b1060ee9c05cb7;hpb=6ebe62478a49df22c55ef6a2b1200473500a7f80;p=perso%2FImmae%2FProjets%2FPython%2FMusicSampler.git diff --git a/music_sampler/app.py b/music_sampler/app.py index 81c47a7..3fd6f51 100644 --- a/music_sampler/app.py +++ b/music_sampler/app.py @@ -1,4 +1,4 @@ -from .helpers import parse_args, register_fonts, duration_to_min_sec, path +from .helpers import parse_args, dump_config, register_fonts, path parse_args() @@ -7,14 +7,21 @@ kivy.require("1.9.1") from kivy.app import App from kivy.uix.floatlayout import FloatLayout from kivy.uix.relativelayout import RelativeLayout +from kivy.uix.label import Label from kivy.properties import ListProperty, StringProperty -from kivy.clock import Clock from kivy.core.window import Window from kivy.lang import Builder + +dump_config() +register_fonts() + + +from .helpers import Config from .key import Key from .mapping import Mapping -register_fonts() +from .app_blocks.actionlist import * +from .app_blocks.playlist import * class KeyList(RelativeLayout): keylist = ListProperty([]) @@ -33,52 +40,26 @@ class KeyList(RelativeLayout): if len(self.keylist) > 2: self.third_key = self.keylist[2] -class PlayList(RelativeLayout): - playlist = ListProperty([]) - - def __init__(self, **kwargs): - super(PlayList, self).__init__(**kwargs) - Clock.schedule_interval(self.update_playlist, 0.5) - - def update_playlist(self, dt): - if self.parent is None or 'Mapping' not in self.parent.ids: - return True - - open_files = self.parent.ids['Mapping'].open_files - self.playlist = [] - for music_file in open_files.values(): - if not music_file.is_in_use(): - continue - - text = "{}/{}".format( - duration_to_min_sec(music_file.sound_position), - duration_to_min_sec(music_file.sound_duration)) - - if music_file.is_loaded_paused(): - self.playlist.append(["⏸", music_file.name, text, False]) - else: - self.playlist.append(["⏵", music_file.name, text, True]) - - -class ActionList(RelativeLayout): - action_title = StringProperty("") - action_list = ListProperty([]) - - def update_list(self, key, action_descriptions): - self.action_title = "actions linked to key {}:".format(key.key_sym) - self.action_list = [] - - for [action, status] in action_descriptions: - if status == "done": - icon = "✓" - elif status == "current": - icon = "✅" - else: - icon = " " - self.action_list.append([icon, action]) +class UnfocusedOverlay(Label): + pass class Screen(FloatLayout): - pass + def __init__(self, **kwargs): + super(Screen, self).__init__(**kwargs) + self.unfocused_widget = UnfocusedOverlay() + Window.bind(focus=self.focus_changed) + Window.on_request_close = self.on_request_close + + def focus_changed(self, instance, focus): + if not Config.focus_warning: + return + if not focus: + self.add_widget(self.unfocused_widget) + else: + self.remove_widget(self.unfocused_widget) + + def on_request_close(self, *args, **kwargs): + self.ids["Mapping"].leave_application() class MusicSamplerApp(App): def build(self): @@ -87,5 +68,6 @@ class MusicSamplerApp(App): return Screen() def main(): - Builder.load_file(path() + "/music_sampler.kv") + with open(path() + "/music_sampler.kv", encoding='utf8') as f: + Builder.load_string(f.read()) MusicSamplerApp().run()