aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2016-09-19 14:02:12 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2016-09-19 14:02:12 +0200
commita9324e30da6292f53f008f1b827779c7f8e2fcdf (patch)
tree042af1f7d2d0852b120e2df51995115b021d0c2d
parentd88794ab3f5e9ce896fa58224dd8c6b1ec33b8b6 (diff)
downloadMusicSampler-a9324e30da6292f53f008f1b827779c7f8e2fcdf.tar.gz
MusicSampler-a9324e30da6292f53f008f1b827779c7f8e2fcdf.tar.zst
MusicSampler-a9324e30da6292f53f008f1b827779c7f8e2fcdf.zip
Use @mainthread decorator where necessary
-rw-r--r--music_sampler/app_blocks/actionlist.py3
-rw-r--r--music_sampler/app_blocks/playlist.py3
-rw-r--r--music_sampler/key.py10
3 files changed, 15 insertions, 1 deletions
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
4from kivy.properties import ListProperty, StringProperty 4from kivy.properties import ListProperty, StringProperty
5from ..lock import Lock 5from ..lock import Lock
6 6
7from kivy.clock import mainthread
8
7__all__ = ["ActionList", 9__all__ = ["ActionList",
8 "ActionListIcons", "ActionListIcon", 10 "ActionListIcons", "ActionListIcon",
9 "ActionListDescriptions", "ActionListDescription"] 11 "ActionListDescriptions", "ActionListDescription"]
@@ -14,6 +16,7 @@ class ActionList(RelativeLayout):
14 action_title = StringProperty("") 16 action_title = StringProperty("")
15 action_list = ListProperty([]) 17 action_list = ListProperty([])
16 18
19 @mainthread
17 def update_list(self, key, action_descriptions): 20 def update_list(self, key, action_descriptions):
18 if key.repeat_delay > 0: 21 if key.repeat_delay > 0:
19 self.action_title = _( 22 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
2from kivy.uix.stacklayout import StackLayout 2from kivy.uix.stacklayout import StackLayout
3from kivy.uix.relativelayout import RelativeLayout 3from kivy.uix.relativelayout import RelativeLayout
4from kivy.properties import ListProperty 4from kivy.properties import ListProperty
5from kivy.clock import Clock 5from kivy.clock import Clock, mainthread
6from ..helpers import duration_to_min_sec 6from ..helpers import duration_to_min_sec
7from ..lock import Lock 7from ..lock import Lock
8 8
@@ -20,6 +20,7 @@ class PlayList(RelativeLayout):
20 super(PlayList, self).__init__(**kwargs) 20 super(PlayList, self).__init__(**kwargs)
21 Clock.schedule_interval(self.update_playlist, 0.5) 21 Clock.schedule_interval(self.update_playlist, 0.5)
22 22
23 @mainthread
23 def update_playlist(self, dt): 24 def update_playlist(self, dt):
24 if self.parent is None or 'Mapping' not in self.parent.ids: 25 if self.parent is None or 'Mapping' not in self.parent.ids:
25 return True 26 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
9import threading 9import threading
10from transitions.extensions import HierarchicalMachine as Machine 10from 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
14from kivy.clock import mainthread
15
12class KeyMachine(Widget): 16class 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()