From a9324e30da6292f53f008f1b827779c7f8e2fcdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Mon, 19 Sep 2016 14:02:12 +0200 Subject: Use @mainthread decorator where necessary --- music_sampler/app_blocks/actionlist.py | 3 +++ music_sampler/app_blocks/playlist.py | 3 ++- music_sampler/key.py | 10 ++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/music_sampler/app_blocks/actionlist.py b/music_sampler/app_blocks/actionlist.py index f48072f..59315de 100644 --- a/music_sampler/app_blocks/actionlist.py +++ b/music_sampler/app_blocks/actionlist.py @@ -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 = _( diff --git a/music_sampler/app_blocks/playlist.py b/music_sampler/app_blocks/playlist.py index 5894995..706e4fc 100644 --- a/music_sampler/app_blocks/playlist.py +++ b/music_sampler/app_blocks/playlist.py @@ -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 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() -- cgit v1.2.3