From 7d6df771f603e9642047264f967525422ef09e99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Fri, 29 Jul 2016 15:04:18 +0200 Subject: Add Unfocused overlay when focus is lost --- music_sampler/app.py | 18 +++++++++++++++++- music_sampler/helpers.py | 5 +++++ music_sampler/music_sampler.kv | 16 ++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) (limited to 'music_sampler') diff --git a/music_sampler/app.py b/music_sampler/app.py index 08a8891..ac1944a 100644 --- a/music_sampler/app.py +++ b/music_sampler/app.py @@ -7,6 +7,7 @@ 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 @@ -14,6 +15,7 @@ from kivy.lang import Builder register_fonts() +from .helpers import Config from .key import Key from .mapping import Mapping @@ -37,9 +39,23 @@ class KeyList(RelativeLayout): if len(self.keylist) > 2: self.third_key = self.keylist[2] -class Screen(FloatLayout): +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) + + def focus_changed(self, instance, focus): + if Config.no_focus_warning: + return + if not focus: + self.add_widget(self.unfocused_widget) + else: + self.remove_widget(self.unfocused_widget) + class MusicSamplerApp(App): def build(self): Window.size = (913, 563) diff --git a/music_sampler/helpers.py b/music_sampler/helpers.py index 6acaba4..2249746 100644 --- a/music_sampler/helpers.py +++ b/music_sampler/helpers.py @@ -123,6 +123,10 @@ def parse_args(): action=ListDevicesAction, help="List available sound devices" ) + parser.add_argument("--no-focus-warning", + action='store_true', + help="Don't show warning when focus is lost" + ) parser.add_argument('--', dest="args", help="Kivy arguments. All arguments after this are interpreted\ @@ -138,6 +142,7 @@ def parse_args(): Config.channels = args.channels Config.sample_width = args.sample_width Config.builtin_mixing = args.builtin_mixing + Config.no_focus_warning = args.no_focus_warning if args.music_path.endswith("/"): Config.music_path = args.music_path else: diff --git a/music_sampler/music_sampler.kv b/music_sampler/music_sampler.kv index 7abab0d..ae5dbd7 100644 --- a/music_sampler/music_sampler.kv +++ b/music_sampler/music_sampler.kv @@ -76,6 +76,22 @@ size_hint: None, None size: 2 * self.parent.width - 2 * self.parent.line_width, self.parent.height - key_label.font_size +: + canvas.before: + Color: + rgba: 1, 0, 0, 0.9 + Rectangle: + pos: 0, 0 + size: self.width, self.height + size_hint: 1, 1 + color: 1, 1, 1, 1 + valign: "middle" + halign: "center" + font_name: "Ubuntu" + font_size: self.parent and 2 * self.parent.key_size or 42 + text_size: self.size + text: "Focus lost!" + : canvas: Color: -- cgit v1.2.3