From 956ce6fd3e47b2536f57f3359ebff26850f30aea Mon Sep 17 00:00:00 2001 From: =?utf8?q?Isma=C3=ABl=20Bouya?= Date: Mon, 20 Jun 2016 23:38:10 +0200 Subject: [PATCH] Cleanup fonts --- Symbola.ttf => fonts/Symbola.ttf | Bin Ubuntu-Regular.ttf => fonts/Ubuntu-Regular.ttf | Bin helpers/__init__.py | 1 + helpers/font.py | 10 ++++++++++ helpers/key.py | 15 ++++----------- music_sampler.py | 8 ++------ music_sampler.spec | 3 +-- 7 files changed, 18 insertions(+), 19 deletions(-) rename Symbola.ttf => fonts/Symbola.ttf (100%) rename Ubuntu-Regular.ttf => fonts/Ubuntu-Regular.ttf (100%) create mode 100644 helpers/font.py diff --git a/Symbola.ttf b/fonts/Symbola.ttf similarity index 100% rename from Symbola.ttf rename to fonts/Symbola.ttf diff --git a/Ubuntu-Regular.ttf b/fonts/Ubuntu-Regular.ttf similarity index 100% rename from Ubuntu-Regular.ttf rename to fonts/Ubuntu-Regular.ttf diff --git a/helpers/__init__.py b/helpers/__init__.py index b3ab1eb..0e29f5d 100644 --- a/helpers/__init__.py +++ b/helpers/__init__.py @@ -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 index 0000000..83999ef --- /dev/null +++ b/helpers/font.py @@ -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) diff --git a/helpers/key.py b/helpers/key.py index 57fdef1..e643dc2 100644 --- a/helpers/key.py +++ b/helpers/key.py @@ -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) diff --git a/music_sampler.py b/music_sampler.py index ff04fd1..8ebfaa3 100644 --- a/music_sampler.py +++ b/music_sampler.py @@ -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)) diff --git a/music_sampler.spec b/music_sampler.spec index a60c546..912edb7 100644 --- a/music_sampler.spec +++ b/music_sampler.spec @@ -6,8 +6,7 @@ a = Analysis(['music_sampler.py'], binaries=None, datas=[ ('config.yml', '.'), - ('Ubuntu-Regular.ttf', '.'), - ('Symbola.ttf', '.') + ('fonts/*', 'fonts') ], hiddenimports=[ 'six', -- 2.41.0