aboutsummaryrefslogtreecommitdiff
path: root/music_sampler/app.py
blob: ce842358240d0e6cbb56206513ab539ba7b94bc7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from .helpers import parse_args, register_fonts, path

parse_args()

import kivy
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.core.window import Window
from kivy.lang import Builder

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):
    keylist = ListProperty([])
    first_key = StringProperty("")
    second_key = StringProperty("")
    third_key = StringProperty("")

    def append(self, value):
        self.keylist.insert(0, value)

    def on_keylist(self, instance, new_key_list):
        if len(self.keylist) > 0:
            self.first_key  = self.keylist[0]
        if len(self.keylist) > 1:
            self.second_key = self.keylist[1]
        if len(self.keylist) > 2:
            self.third_key  = self.keylist[2]

class UnfocusedOverlay(Label):
    pass

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

    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):
        Window.size = (913, 563)

        return Screen()

def main():
    Builder.load_file(path() + "/music_sampler.kv")
    MusicSamplerApp().run()