]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blobdiff - music_sampler/key.py
Use @mainthread decorator where necessary
[perso/Immae/Projets/Python/MusicSampler.git] / music_sampler / key.py
index 68e6f0454a84b9576c2d8421cbecbc5bfb4643fa..e524c350d86c3cf7cb0ceb6a378ee9edd25724b5 100644 (file)
@@ -9,6 +9,10 @@ import time
 import threading
 from transitions.extensions import HierarchicalMachine as Machine
 
+# All drawing operations should happen in the main thread
+# https://github.com/kivy/kivy/wiki/Working-with-Python-threads-inside-a-Kivy-application
+from kivy.clock import mainthread
+
 class KeyMachine(Widget):
     STATES = [
         'initial',
@@ -118,6 +122,7 @@ class KeyMachine(Widget):
     def is_loaded_inactive(self):
         return self.is_loaded_no_config() or self.is_loaded_no_actions()
 
+    @mainthread
     def on_enter_configuring(self):
         self.destroy_actions()
         self.key.unset_description()
@@ -172,6 +177,7 @@ class KeyMachine(Widget):
             self.key.repeat_protection_finished()
 
     # Callbacks
+    @mainthread
     def key_loaded_callback(self):
         self.key.parent.key_loaded_callback()
 
@@ -250,6 +256,10 @@ class Key(ButtonBehavior, Widget):
         super(Key, self).__init__(**kwargs)
 
     # Kivy events
+    @mainthread
+    def update_state(self, value):
+        self.machine_state = value
+
     def on_key_sym(self, key, key_sym):
         if key_sym != "":
             self.configure()