aboutsummaryrefslogtreecommitdiff
path: root/music_sampler
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2016-07-29 23:22:27 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2016-07-29 23:22:27 +0200
commitca3264c828e5220e9d729152572de7a4600149b4 (patch)
tree9e3432824b3e3a8bb5c7d588711d0560dd2ddca8 /music_sampler
parent0a557acb3e9842114e752270fa8863ae1890c402 (diff)
downloadMusicSampler-ca3264c828e5220e9d729152572de7a4600149b4.tar.gz
MusicSampler-ca3264c828e5220e9d729152572de7a4600149b4.tar.zst
MusicSampler-ca3264c828e5220e9d729152572de7a4600149b4.zip
Leave application correctly when clicking on the cross button
Diffstat (limited to 'music_sampler')
-rw-r--r--music_sampler/app.py4
-rw-r--r--music_sampler/mapping.py24
2 files changed, 17 insertions, 11 deletions
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):
47 super(Screen, self).__init__(**kwargs) 47 super(Screen, self).__init__(**kwargs)
48 self.unfocused_widget = UnfocusedOverlay() 48 self.unfocused_widget = UnfocusedOverlay()
49 Window.bind(focus=self.focus_changed) 49 Window.bind(focus=self.focus_changed)
50 Window.on_request_close = self.on_request_close
50 51
51 def focus_changed(self, instance, focus): 52 def focus_changed(self, instance, focus):
52 if Config.no_focus_warning: 53 if Config.no_focus_warning:
@@ -56,6 +57,9 @@ class Screen(FloatLayout):
56 else: 57 else:
57 self.remove_widget(self.unfocused_widget) 58 self.remove_widget(self.unfocused_widget)
58 59
60 def on_request_close(self, *args, **kwargs):
61 self.ids["Mapping"].leave_application()
62
59class MusicSamplerApp(App): 63class MusicSamplerApp(App):
60 def build(self): 64 def build(self):
61 Window.size = (913, 563) 65 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):
124 threading.Thread(name="MSKeyAction", target=key.run, 124 threading.Thread(name="MSKeyAction", target=key.run,
125 args=['-'.join(modifiers)]).start() 125 args=['-'.join(modifiers)]).start()
126 elif 'ctrl' in modifiers and (keycode[0] == 113 or keycode[0] == '99'): 126 elif 'ctrl' in modifiers and (keycode[0] == 113 or keycode[0] == '99'):
127 self.keyboard.unbind(on_key_down=self.on_keyboard_down) 127 self.leave_application()
128 self.stop_all_running()
129 for music in self.open_files.values():
130 music.stop()
131 for thread in threading.enumerate():
132 if thread.getName()[0:2] == "MS":
133 thread.join()
134 elif thread.__class__ == threading.Timer:
135 thread.cancel()
136 thread.join()
137
138 sys.exit() 128 sys.exit()
139 elif 'ctrl' in modifiers and keycode[0] == 114: 129 elif 'ctrl' in modifiers and keycode[0] == 114:
140 threading.Thread(name="MSReload", target=self.reload).start() 130 threading.Thread(name="MSReload", target=self.reload).start()
141 return True 131 return True
142 132
133 def leave_application(self):
134 self.keyboard.unbind(on_key_down=self.on_keyboard_down)
135 self.stop_all_running()
136 for music in self.open_files.values():
137 music.stop()
138 for thread in threading.enumerate():
139 if thread.getName()[0:2] == "MS":
140 thread.join()
141 elif thread.__class__ == threading.Timer:
142 thread.cancel()
143 thread.join()
144
143 # Helpers 145 # Helpers
144 def allowed_modifiers(self, modifiers): 146 def allowed_modifiers(self, modifiers):
145 allowed = [] 147 allowed = []