From 23b7e0e5daf024e87d967ede3dfe6777a07e7469 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Isma=C3=ABl=20Bouya?= Date: Sun, 19 Jun 2016 22:44:54 +0200 Subject: [PATCH] Fix threading problems with ipython --- config.yml | 146 +++++++++++++++++++++++------------------- helpers/key.py | 8 +-- helpers/mapping.py | 2 +- helpers/music_file.py | 2 +- music_sampler.py | 12 +++- 5 files changed, 96 insertions(+), 74 deletions(-) diff --git a/config.yml b/config.yml index ca6c399..bd67496 100644 --- a/config.yml +++ b/config.yml @@ -35,124 +35,140 @@ aliases: key_properties: 'a': description: - - Chloé + - # Chloé - Jonglacro - color: [255, 0, 0] + color: [73, 221, 226] 'z': description: - - Chloé - - Jonglacro 2 - color: [255, 0, 0] + - #Chloé + - Jonglacro + - 2 + color: [73, 221, 226] 'e': description: - - Chloé - - Stop jonglacro 2 - color: [255, 0, 0] + - #Chloé + - Fin + - jonglacro + color: [73, 221, 226] 'r': description: - - Chloé - - Lancer prisonnière - color: [255, 0, 0] + - #Chloé + - Lancer + - prisonnière + color: [73, 221, 226] 't': description: - - Chloé - - Stop lancer prisonnière - color: [255, 0, 0] + - #Chloé + - Fin + - lancer + color: [73, 221, 226] 'y': description: - - Chloé + - #Chloé - Quête - color: [255, 0, 0] + color: [73, 221, 226] 'u': description: - - Chloé - - Grrr - color: [255, 0, 0] + - #Chloé + - Monstre + color: [73, 221, 226] 'i': description: - - Chloé - - Transition -> entrée ondine - color: [255, 0, 0] + - #Chloé + - Fin quête + - Entrée ondine + color: [73, 221, 226] 'o': description: - - Denise + - #Denise + - Fin ondine - Cour ondine - color: [0, 255, 0] + color: [190, 110, 236] 'p': description: - - Denise - - Stop cour ondine - color: [0, 255, 0] + - #Denise + - Fin + - cour ondine + color: [190, 110, 236] 'q': description: - - Chloé - - Fouille jonglage - color: [255, 0, 0] + - #Chloé + - Fouille + - Jonglage + color: [73, 221, 226] 's': description: - - Denise - - Stop fouille jonglage - color: [0, 255, 0] + - #Denise + - Fin + - Jonglage + color: [190, 110, 236] 'd': description: - - Denise - - Libération prisonnière - color: [0, 255, 0] + - #Denise + - Libération + - Prisonnière + color: [190, 110, 236] 'f': description: - - Denise - - Paf + baisser musique - color: [0, 255, 0] + - #Denise + - Paf + - Baisser musique + color: [190, 110, 236] 'g': description: - - Denise - - Stop musique - color: [0, 255, 0] + - #Denise + - Stop + - libération + color: [190, 110, 236] 'h': description: - - Denise - - Duos - color: [0, 255, 0] + - #Denise + - Duo + color: [190, 110, 236] 'j': description: - - Jérôme - - Transition trios - color: [0, 0, 255] + - #Jérôme + - Fin duo + - Trio + color: [240, 158, 0] 'k': description: - - Jérôme - - Stop trios - color: [0, 0, 255] + - #Jérôme + - Fin trio + color: [240, 158, 0] 'l': description: - - Jérôme - - Jeu à 2-4 - color: [0, 0, 255] + - #Jérôme + - Jeu à + - 2 4 + color: [240, 158, 0] 'm': description: - - Chloé + - #Chloé + - Fin jeu - Début baston - color: [255, 0, 0] + color: [73, 221, 226] 'w': description: - - Christophe - - Transition ralenti + - #Christophe + - Fin baston + - Ralenti color: [255, 255, 0] 'x': description: - - Christophe - - Stop ralenti + - #Christophe + - Fin ralenti color: [255, 255, 0] 'c': description: - - Christophe - - Début baston 2 + - #Christophe + - Baston 2 color: [255, 255, 0] 'v': description: - - Auréliane - - Stop baston 2 - color: [0, 255, 255] + - #Auréliane + - Fin baston 2 + color: [0, 190, 27] keys: diff --git a/helpers/key.py b/helpers/key.py index 9a6cb3b..e9e485d 100644 --- a/helpers/key.py +++ b/helpers/key.py @@ -72,7 +72,7 @@ class Key: ) def set_description(self, description): - self.description = description + self.description = [str(desc) for desc in description] def set_color(self, color): self.custom_color = tuple(color) @@ -97,7 +97,7 @@ class Key: self.surface.blit(text, (5,5)) is_first_line = True - offset = 11 + text_police.get_linesize() + offset = 11 + text_police.get_linesize() - 4 first_line_offset = 18 for description in self.description: text = text_police.render(description, True, (0,0,0)) @@ -105,8 +105,8 @@ class Key: self.surface.blit(text, (first_line_offset, 9)) is_first_line = False else: - self.surface.blit(text, (5, offset)) - offset += text_police.get_linesize() + self.surface.blit(text, (3, offset)) + offset += text_police.get_linesize() - 4 background_surface.blit(self.surface, self.position) self.draw_lock.release() diff --git a/helpers/mapping.py b/helpers/mapping.py index ee5623a..84e9941 100644 --- a/helpers/mapping.py +++ b/helpers/mapping.py @@ -130,7 +130,7 @@ class Mapping: should_redraw_key = key.draw(self.background) if should_redraw_key: - threading.Thread(target = key.poll_redraw, args = [self.background]).start() + threading.Thread(name = "MSPollRedraw", target = key.poll_redraw, args = [self.background]).start() self.blit() def blit(self): diff --git a/helpers/music_file.py b/helpers/music_file.py index b834104..5101f7f 100644 --- a/helpers/music_file.py +++ b/helpers/music_file.py @@ -10,7 +10,7 @@ class MusicFile: self.sound = None self.loaded = False - threading.Thread(target = self.load_sound, args = [lock]).start() + threading.Thread(name = "MSMusicLoad", target = self.load_sound, args = [lock]).start() def load_sound(self, lock): lock.acquire() diff --git a/music_sampler.py b/music_sampler.py index fd03009..d4fc2a7 100644 --- a/music_sampler.py +++ b/music_sampler.py @@ -27,6 +27,7 @@ contexts = [ context = 'normal' +#### Normal workflow #### while 1: event = pygame.event.wait() @@ -35,7 +36,7 @@ while 1: event.mod == 4160 and event.key == pygame.K_c): for thread in threading.enumerate(): - if thread is threading.current_thread(): + if thread.getName()[0:2] != "MS": continue thread.join() @@ -46,13 +47,18 @@ while 1: if event.type == pygame.KEYDOWN: key = mapping.find_by_key_num(event.key) if key is not None: - threading.Thread(target=key.do_actions).start() + threading.Thread(name = "MSKeyAction", target=key.do_actions).start() elif event.type == pygame.MOUSEBUTTONUP: key = mapping.find_by_collidepoint(pygame.mouse.get_pos()) if key is not None: - threading.Thread(target=key.list_actions, args = [screen]).start() + threading.Thread(name = "MSClic", target=key.list_actions, args = [screen]).start() draw_lock.acquire() pygame.display.flip() draw_lock.release() +#### In Ipython #### +# for thread in threading.enumerate(): +# if thread.getName()[0:2] != "MS": +# continue +# thread.join() -- 2.41.0