]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/commitdiff
Use @mainthread decorator where necessary
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 19 Sep 2016 12:02:12 +0000 (14:02 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 19 Sep 2016 12:02:12 +0000 (14:02 +0200)
music_sampler/app_blocks/actionlist.py
music_sampler/app_blocks/playlist.py
music_sampler/key.py

index f48072f92962d34deb5ebc1549c843ad0a86af97..59315de567a76e7af155c978820850f1656c4465 100644 (file)
@@ -4,6 +4,8 @@ from kivy.uix.relativelayout import RelativeLayout
 from kivy.properties import ListProperty, StringProperty
 from ..lock import Lock
 
+from kivy.clock import mainthread
+
 __all__ = ["ActionList",
         "ActionListIcons", "ActionListIcon",
         "ActionListDescriptions", "ActionListDescription"]
@@ -14,6 +16,7 @@ class ActionList(RelativeLayout):
     action_title = StringProperty("")
     action_list = ListProperty([])
 
+    @mainthread
     def update_list(self, key, action_descriptions):
         if key.repeat_delay > 0:
             self.action_title = _(
index 5894995bc71aa66a3b692e89f0460452a10a5d2c..706e4fc32c9654febe6450abb7b5559050aebff7 100644 (file)
@@ -2,7 +2,7 @@ from kivy.uix.label import Label
 from kivy.uix.stacklayout import StackLayout
 from kivy.uix.relativelayout import RelativeLayout
 from kivy.properties import ListProperty
-from kivy.clock import Clock
+from kivy.clock import Clock, mainthread
 from ..helpers import duration_to_min_sec
 from ..lock import Lock
 
@@ -20,6 +20,7 @@ class PlayList(RelativeLayout):
         super(PlayList, self).__init__(**kwargs)
         Clock.schedule_interval(self.update_playlist, 0.5)
 
+    @mainthread
     def update_playlist(self, dt):
         if self.parent is None or 'Mapping' not in self.parent.ids:
             return True
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()