aboutsummaryrefslogtreecommitdiff
path: root/helpers
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2016-06-19 01:13:41 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2016-06-19 01:13:41 +0200
commitba9ea93a0f52178d24a606fddc2acc5dc85b7ff2 (patch)
tree0a2b43561b84eefed07ecb83de1ecf4fad428532 /helpers
parente5e6409426e3eb1918318973372568081e6d9dd6 (diff)
downloadMusicSampler-ba9ea93a0f52178d24a606fddc2acc5dc85b7ff2.tar.gz
MusicSampler-ba9ea93a0f52178d24a606fddc2acc5dc85b7ff2.tar.zst
MusicSampler-ba9ea93a0f52178d24a606fddc2acc5dc85b7ff2.zip
enhancing locks
Diffstat (limited to 'helpers')
-rw-r--r--helpers/__init__.py8
-rw-r--r--helpers/action.py5
-rw-r--r--helpers/key.py31
-rw-r--r--helpers/lock.py15
4 files changed, 49 insertions, 10 deletions
diff --git a/helpers/__init__.py b/helpers/__init__.py
index 6935342..b1723ee 100644
--- a/helpers/__init__.py
+++ b/helpers/__init__.py
@@ -1,12 +1,10 @@
1# -*- coding: utf-8 -*- 1# -*- coding: utf-8 -*-
2import threading
3from .music_file import * 2from .music_file import *
4from .mapping import * 3from .mapping import *
5 4from .lock import *
6draw_lock = threading.RLock() 5import yaml
7 6
8def parse_config(mapping): 7def parse_config(mapping):
9 import yaml
10 stream = open("config.yml", "r") 8 stream = open("config.yml", "r")
11 config = yaml.load(stream) 9 config = yaml.load(stream)
12 stream.close() 10 stream.close()
@@ -14,7 +12,7 @@ def parse_config(mapping):
14 aliases = config['aliases'] 12 aliases = config['aliases']
15 seen_files = {} 13 seen_files = {}
16 14
17 file_lock = threading.RLock() 15 file_lock = Lock("file")
18 16
19 for mapped_key in config['keys']: 17 for mapped_key in config['keys']:
20 key = mapping.find_by_unicode(mapped_key) 18 key = mapping.find_by_unicode(mapped_key)
diff --git a/helpers/action.py b/helpers/action.py
index 8a69fae..97873a0 100644
--- a/helpers/action.py
+++ b/helpers/action.py
@@ -28,9 +28,12 @@ class Action:
28 return True 28 return True
29 29
30 def run(self): 30 def run(self):
31 print(getattr(self, self.action + "_print")(**self.arguments)) 31 print(self.description())
32 return getattr(self, self.action)(**self.arguments) 32 return getattr(self, self.action)(**self.arguments)
33 33
34 def description(self):
35 return getattr(self, self.action + "_print")(**self.arguments)
36
34 def command(self, command = "", **kwargs): 37 def command(self, command = "", **kwargs):
35 pass 38 pass
36 39
diff --git a/helpers/key.py b/helpers/key.py
index 2e4a313..6997e70 100644
--- a/helpers/key.py
+++ b/helpers/key.py
@@ -112,9 +112,32 @@ class Key:
112 112
113 self.mapping.finished_running(self, start_time) 113 self.mapping.finished_running(self, start_time)
114 114
115 def list_actions(self, surface): 115 def list_actions(self, screen):
116 # FIXME: Todo 116 action_descriptions = [action.description() for action in self.actions]
117 print("bouh", self.key_sym) 117 print("actions linked to key {}:".format(self.key_sym))
118 surface.fill((255, 0, 0)) 118 print("\t" + "\n\t".join(action_descriptions))
119 self.draw_lock.acquire()
120 surface = pygame.Surface((800, 250)).convert()
121 surface.fill((250, 250, 250))
122 if getattr(sys, 'frozen', False):
123 police = pygame.font.Font(sys._MEIPASS + "/Ubuntu-Regular.ttf", 14)
124 else:
125 police = pygame.font.Font("Ubuntu-Regular.ttf", 14)
126
127 offset = 0
128 police.set_bold(True)
129 text = police.render("actions linked to key {}:".format(self.key_sym), True, (0,0,0))
130 surface.blit(text, (0, offset))
131 offset += police.get_linesize()
132
133 police.set_bold(False)
134 for description in action_descriptions:
135 text = police.render(description, True, (0,0,0))
136 surface.blit(text, (0, offset))
137 offset += police.get_linesize()
138
139 screen.blit(surface, (10, 330))
140 pygame.display.flip()
141 self.draw_lock.release()
119 142
120 143
diff --git a/helpers/lock.py b/helpers/lock.py
new file mode 100644
index 0000000..dff8b1f
--- /dev/null
+++ b/helpers/lock.py
@@ -0,0 +1,15 @@
1import threading
2
3class Lock:
4 def __init__(self, lock_type):
5 self.type = lock_type
6 self.lock = threading.RLock()
7
8 def acquire(self, *args, **kwargs):
9 #print("acquiring lock for {}".format(self.type))
10 self.lock.acquire(*args, **kwargs)
11
12 def release(self, *args, **kwargs):
13 #print("releasing lock for {}".format(self.type))
14 self.lock.release(*args, **kwargs)
15