]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/commitdiff
Cleanup fonts
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 20 Jun 2016 21:38:10 +0000 (23:38 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 20 Jun 2016 21:38:10 +0000 (23:38 +0200)
fonts/Symbola.ttf [moved from Symbola.ttf with 100% similarity]
fonts/Ubuntu-Regular.ttf [moved from Ubuntu-Regular.ttf with 100% similarity]
helpers/__init__.py
helpers/font.py [new file with mode: 0644]
helpers/key.py
music_sampler.py
music_sampler.spec

similarity index 100%
rename from Symbola.ttf
rename to fonts/Symbola.ttf
similarity index 100%
rename from Ubuntu-Regular.ttf
rename to fonts/Ubuntu-Regular.ttf
index b3ab1eba61d302a2cd249fd17c39fd4754a2c323..0e29f5dbde1717b11496460f5b9fd461df526e83 100644 (file)
@@ -2,6 +2,7 @@
 from .music_file import *
 from .mapping import *
 from .lock import *
+from .font import *
 import yaml
 
 def parse_config(mapping):
diff --git a/helpers/font.py b/helpers/font.py
new file mode 100644 (file)
index 0000000..83999ef
--- /dev/null
@@ -0,0 +1,10 @@
+import os
+import pygame
+import sys
+
+def font(size, font = "Ubuntu-Regular"):
+    if getattr(sys, 'frozen', False):
+        return pygame.font.Font(sys._MEIPASS + "/fonts/" + font + ".ttf", size)
+    else:
+        path = os.path.dirname(os.path.realpath(__file__))
+        return pygame.font.Font(path + "/../fonts/" + font + ".ttf", size)
index 57fdef1d5616eb9df83ddf0bf0c18d9fb592d2dc..e643dc240f030042831000c6a890d85b6bfc961f 100644 (file)
@@ -1,5 +1,6 @@
 from .rounded_rect import *
 from .action import *
+from .font import font
 import time
 import sys
 import pygame
@@ -19,7 +20,6 @@ class Key:
     default_inner_color = (255, 255, 255)
     mapped_inner_color  = (  0, 255,   0)
     mapped_unready_inner_color  = (  0, 255,   0, 100)
-    #mapped_unready_inner_color = (255, 165, 0)
 
     def __init__(self, mapping, draw_lock, key_name, key_sym, top, left, width = 48, height = 48, disabled = False):
         self.draw_lock = draw_lock
@@ -89,12 +89,8 @@ class Key:
 
         self.surface = self.square(all_actions_ready).surface()
 
-        if getattr(sys, 'frozen', False):
-            police = pygame.font.Font(sys._MEIPASS + "/Ubuntu-Regular.ttf", 14)
-            text_police = pygame.font.Font(sys._MEIPASS + "/Ubuntu-Regular.ttf", 10)
-        else:
-            police = pygame.font.Font("Ubuntu-Regular.ttf", 14)
-            text_police = pygame.font.Font("Ubuntu-Regular.ttf", 10)
+        police = font(14)
+        text_police = font(10)
 
         police.set_bold(True)
         text = police.render(self.key_sym, True, (0,0,0))
@@ -151,10 +147,7 @@ class Key:
         self.draw_lock.acquire()
         surface = pygame.Surface((690, 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)
+        police = font(14)
 
         offset = 0
         police.set_bold(True)
index ff04fd1e42d2d1d62c559cbbd5a9929b353d381b..8ebfaa3e664f9c57eb951e57682dffd4e565eb74 100644 (file)
@@ -56,12 +56,8 @@ while 1:
                 threading.Thread(name = "MSClic", target=key.list_actions, args = [screen]).start()
 
     draw_lock.acquire()
-    if getattr(sys, 'frozen', False):
-        icon_police = pygame.font.Font(sys._MEIPASS + "/Symbola.ttf", 19)
-        police = pygame.font.Font(sys._MEIPASS + "/Ubuntu-Regular.ttf", 14)
-    else:
-        icon_police = pygame.font.Font("Symbola.ttf", 19)
-        police = pygame.font.Font("Ubuntu-Regular.ttf", 14)
+    police = helpers.font(14)
+    icon_police = helpers.font(14, font = "Symbola")
 
     surface = pygame.Surface((208, 250)).convert()
     surface.fill((250, 250, 250))
index a60c546c2dd7cfc5c9987e5adbeabddf1b358ff3..912edb788ae0b7f1b0d55de1c24ba05d6ae7f85f 100644 (file)
@@ -6,8 +6,7 @@ a = Analysis(['music_sampler.py'],
              binaries=None,
              datas=[
               ('config.yml', '.'),
-              ('Ubuntu-Regular.ttf', '.'),
-              ('Symbola.ttf', '.')
+              ('fonts/*', 'fonts')
              ],
              hiddenimports=[
                'six',