X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=music_sampler%2Fkey.py;h=e524c350d86c3cf7cb0ceb6a378ee9edd25724b5;hb=a9324e30da6292f53f008f1b827779c7f8e2fcdf;hp=68e6f0454a84b9576c2d8421cbecbc5bfb4643fa;hpb=d88794ab3f5e9ce896fa58224dd8c6b1ec33b8b6;p=perso%2FImmae%2FProjets%2FPython%2FMusicSampler.git 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 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()