]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blobdiff - music_sampler/app.py
Add config
[perso/Immae/Projets/Python/MusicSampler.git] / music_sampler / app.py
index 510cb4492c5d86d286678f7a96cefe899531164a..3fd6f510c2236ae490c1b116aadb53a44f6d6972 100644 (file)
@@ -1,4 +1,4 @@
-from .helpers import parse_args, register_fonts, path
+from .helpers import parse_args, dump_config, register_fonts, path
 
 parse_args()
 
@@ -6,16 +6,21 @@ import kivy
 kivy.require("1.9.1")
 from kivy.app import App
 from kivy.uix.floatlayout import FloatLayout
-from kivy.uix.stacklayout import StackLayout
 from kivy.uix.relativelayout import RelativeLayout
+from kivy.uix.label import Label
 from kivy.properties import ListProperty, StringProperty
 from kivy.core.window import Window
 from kivy.lang import Builder
-from .key import Key
-from .mapping import Mapping
 
+dump_config()
 register_fonts()
 
+
+from .helpers import Config
+from .key import Key
+from .mapping import Mapping
+
+from .app_blocks.actionlist import *
 from .app_blocks.playlist import *
 
 class KeyList(RelativeLayout):
@@ -35,25 +40,26 @@ class KeyList(RelativeLayout):
         if len(self.keylist) > 2:
             self.third_key  = self.keylist[2]
 
-class ActionList(RelativeLayout):
-    action_title = StringProperty("")
-    action_list = ListProperty([])
+class UnfocusedOverlay(Label):
+    pass
 
-    def update_list(self, key, action_descriptions):
-        self.action_title = "actions linked to key {}:".format(key.key_sym)
-        self.action_list = []
+class Screen(FloatLayout):
+    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
 
-        for [action, status] in action_descriptions:
-            if status == "done":
-                icon = "✓"
-            elif status == "current":
-                icon = "✅"
-            else:
-                icon = " "
-            self.action_list.append([icon, action])
+    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)
 
-class Screen(FloatLayout):
-    pass
+    def on_request_close(self, *args, **kwargs):
+        self.ids["Mapping"].leave_application()
 
 class MusicSamplerApp(App):
     def build(self):
@@ -62,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()