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