diff options
Diffstat (limited to 'music_sampler/key.py')
-rw-r--r-- | music_sampler/key.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/music_sampler/key.py b/music_sampler/key.py index 68e6f04..e524c35 100644 --- a/music_sampler/key.py +++ b/music_sampler/key.py | |||
@@ -9,6 +9,10 @@ import time | |||
9 | import threading | 9 | import threading |
10 | from transitions.extensions import HierarchicalMachine as Machine | 10 | from transitions.extensions import HierarchicalMachine as Machine |
11 | 11 | ||
12 | # All drawing operations should happen in the main thread | ||
13 | # https://github.com/kivy/kivy/wiki/Working-with-Python-threads-inside-a-Kivy-application | ||
14 | from kivy.clock import mainthread | ||
15 | |||
12 | class KeyMachine(Widget): | 16 | class KeyMachine(Widget): |
13 | STATES = [ | 17 | STATES = [ |
14 | 'initial', | 18 | 'initial', |
@@ -118,6 +122,7 @@ class KeyMachine(Widget): | |||
118 | def is_loaded_inactive(self): | 122 | def is_loaded_inactive(self): |
119 | return self.is_loaded_no_config() or self.is_loaded_no_actions() | 123 | return self.is_loaded_no_config() or self.is_loaded_no_actions() |
120 | 124 | ||
125 | @mainthread | ||
121 | def on_enter_configuring(self): | 126 | def on_enter_configuring(self): |
122 | self.destroy_actions() | 127 | self.destroy_actions() |
123 | self.key.unset_description() | 128 | self.key.unset_description() |
@@ -172,6 +177,7 @@ class KeyMachine(Widget): | |||
172 | self.key.repeat_protection_finished() | 177 | self.key.repeat_protection_finished() |
173 | 178 | ||
174 | # Callbacks | 179 | # Callbacks |
180 | @mainthread | ||
175 | def key_loaded_callback(self): | 181 | def key_loaded_callback(self): |
176 | self.key.parent.key_loaded_callback() | 182 | self.key.parent.key_loaded_callback() |
177 | 183 | ||
@@ -250,6 +256,10 @@ class Key(ButtonBehavior, Widget): | |||
250 | super(Key, self).__init__(**kwargs) | 256 | super(Key, self).__init__(**kwargs) |
251 | 257 | ||
252 | # Kivy events | 258 | # Kivy events |
259 | @mainthread | ||
260 | def update_state(self, value): | ||
261 | self.machine_state = value | ||
262 | |||
253 | def on_key_sym(self, key, key_sym): | 263 | def on_key_sym(self, key, key_sym): |
254 | if key_sym != "": | 264 | if key_sym != "": |
255 | self.configure() | 265 | self.configure() |