From ca3264c828e5220e9d729152572de7a4600149b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Fri, 29 Jul 2016 23:22:27 +0200 Subject: Leave application correctly when clicking on the cross button --- music_sampler/app.py | 4 ++++ music_sampler/mapping.py | 24 +++++++++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) (limited to 'music_sampler') diff --git a/music_sampler/app.py b/music_sampler/app.py index ac1944a..e7c90db 100644 --- a/music_sampler/app.py +++ b/music_sampler/app.py @@ -47,6 +47,7 @@ class Screen(FloatLayout): 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 Config.no_focus_warning: @@ -56,6 +57,9 @@ class Screen(FloatLayout): 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) diff --git a/music_sampler/mapping.py b/music_sampler/mapping.py index 74feec8..e589ac0 100644 --- a/music_sampler/mapping.py +++ b/music_sampler/mapping.py @@ -124,22 +124,24 @@ class Mapping(RelativeLayout): threading.Thread(name="MSKeyAction", target=key.run, args=['-'.join(modifiers)]).start() elif 'ctrl' in modifiers and (keycode[0] == 113 or keycode[0] == '99'): - self.keyboard.unbind(on_key_down=self.on_keyboard_down) - self.stop_all_running() - for music in self.open_files.values(): - music.stop() - for thread in threading.enumerate(): - if thread.getName()[0:2] == "MS": - thread.join() - elif thread.__class__ == threading.Timer: - thread.cancel() - thread.join() - + self.leave_application() sys.exit() elif 'ctrl' in modifiers and keycode[0] == 114: threading.Thread(name="MSReload", target=self.reload).start() return True + def leave_application(self): + self.keyboard.unbind(on_key_down=self.on_keyboard_down) + self.stop_all_running() + for music in self.open_files.values(): + music.stop() + for thread in threading.enumerate(): + if thread.getName()[0:2] == "MS": + thread.join() + elif thread.__class__ == threading.Timer: + thread.cancel() + thread.join() + # Helpers def allowed_modifiers(self, modifiers): allowed = [] -- cgit v1.2.3