]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blame_incremental - music_sampler/app.py
Fix crash when click on unconfigured key
[perso/Immae/Projets/Python/MusicSampler.git] / music_sampler / app.py
... / ...
CommitLineData
1from .helpers import parse_args, dump_config, register_fonts, path
2
3parse_args()
4
5import kivy
6kivy.require("1.9.1")
7from kivy.app import App
8from kivy.uix.floatlayout import FloatLayout
9from kivy.uix.relativelayout import RelativeLayout
10from kivy.uix.label import Label
11from kivy.properties import ListProperty, StringProperty
12from kivy.core.window import Window
13from kivy.lang import Builder
14
15dump_config()
16register_fonts()
17
18
19from .helpers import Config
20from .key import Key
21from .mapping import Mapping
22
23from .app_blocks.actionlist import *
24from .app_blocks.playlist import *
25
26class KeyList(RelativeLayout):
27 keylist = ListProperty([])
28 first_key = StringProperty("")
29 second_key = StringProperty("")
30 third_key = StringProperty("")
31
32 def append(self, value):
33 self.keylist.insert(0, value)
34
35 def on_keylist(self, instance, new_key_list):
36 if len(self.keylist) > 0:
37 self.first_key = self.keylist[0]
38 if len(self.keylist) > 1:
39 self.second_key = self.keylist[1]
40 if len(self.keylist) > 2:
41 self.third_key = self.keylist[2]
42
43class UnfocusedOverlay(Label):
44 pass
45
46class Screen(FloatLayout):
47 def __init__(self, **kwargs):
48 super(Screen, self).__init__(**kwargs)
49 self.unfocused_widget = UnfocusedOverlay()
50 Window.bind(focus=self.focus_changed)
51 Window.on_request_close = self.on_request_close
52
53 def focus_changed(self, instance, focus):
54 if not Config.focus_warning:
55 return
56 if not focus:
57 self.add_widget(self.unfocused_widget)
58 else:
59 self.remove_widget(self.unfocused_widget)
60
61 def on_request_close(self, *args, **kwargs):
62 self.ids["Mapping"].leave_application()
63
64class MusicSamplerApp(App):
65 def build(self):
66 Window.size = (913, 563)
67
68 return Screen()
69
70def main():
71 Builder.load_file(path() + "/music_sampler.kv")
72 MusicSamplerApp().run()