# -*- coding: utf-8 -*-
-import threading
from .music_file import *
from .mapping import *
-
-draw_lock = threading.RLock()
+from .lock import *
+import yaml
def parse_config(mapping):
- import yaml
stream = open("config.yml", "r")
config = yaml.load(stream)
stream.close()
aliases = config['aliases']
seen_files = {}
- file_lock = threading.RLock()
+ file_lock = Lock("file")
for mapped_key in config['keys']:
key = mapping.find_by_unicode(mapped_key)
return True
def run(self):
- print(getattr(self, self.action + "_print")(**self.arguments))
+ print(self.description())
return getattr(self, self.action)(**self.arguments)
+ def description(self):
+ return getattr(self, self.action + "_print")(**self.arguments)
+
def command(self, command = "", **kwargs):
pass
self.mapping.finished_running(self, start_time)
- def list_actions(self, surface):
- # FIXME: Todo
- print("bouh", self.key_sym)
- surface.fill((255, 0, 0))
+ def list_actions(self, screen):
+ action_descriptions = [action.description() for action in self.actions]
+ print("actions linked to key {}:".format(self.key_sym))
+ print("\t" + "\n\t".join(action_descriptions))
+ self.draw_lock.acquire()
+ surface = pygame.Surface((800, 250)).convert()
+ surface.fill((250, 250, 250))
+ if getattr(sys, 'frozen', False):
+ police = pygame.font.Font(sys._MEIPASS + "/Ubuntu-Regular.ttf", 14)
+ else:
+ police = pygame.font.Font("Ubuntu-Regular.ttf", 14)
+
+ offset = 0
+ police.set_bold(True)
+ text = police.render("actions linked to key {}:".format(self.key_sym), True, (0,0,0))
+ surface.blit(text, (0, offset))
+ offset += police.get_linesize()
+
+ police.set_bold(False)
+ for description in action_descriptions:
+ text = police.render(description, True, (0,0,0))
+ surface.blit(text, (0, offset))
+ offset += police.get_linesize()
+
+ screen.blit(surface, (10, 330))
+ pygame.display.flip()
+ self.draw_lock.release()
--- /dev/null
+import threading
+
+class Lock:
+ def __init__(self, lock_type):
+ self.type = lock_type
+ self.lock = threading.RLock()
+
+ def acquire(self, *args, **kwargs):
+ #print("acquiring lock for {}".format(self.type))
+ self.lock.acquire(*args, **kwargs)
+
+ def release(self, *args, **kwargs):
+ #print("releasing lock for {}".format(self.type))
+ self.lock.release(*args, **kwargs)
+
pygame.init()
size = width, height = 1024, 600
-
-helpers.draw_lock.acquire()
screen = pygame.display.set_mode(size)
-mapping = helpers.Mapping(screen, helpers.draw_lock)
+screen.fill((250, 250, 250))
+
+draw_lock = helpers.Lock("draw")
-action_surface = pygame.Surface((600, 250)).convert()
-action_surface.fill((0,0,0))
+mapping = helpers.Mapping(screen, draw_lock)
helpers.parse_config(mapping)
-helpers.draw_lock.release()
mapping.draw()
-helpers.draw_lock.acquire()
-screen.blit(action_surface, (10, 330))
-
+draw_lock.acquire()
pygame.display.flip()
-helpers.draw_lock.release()
+draw_lock.release()
contexts = [
'normal'
elif event.type == pygame.MOUSEBUTTONUP:
key = mapping.find_by_collidepoint(pygame.mouse.get_pos())
if key is not None:
- key.list_actions(action_surface)
+ threading.Thread(target=key.list_actions, args = [screen]).start()
+ draw_lock.acquire()
pygame.display.flip()
+ draw_lock.release()