From 956ce6fd3e47b2536f57f3359ebff26850f30aea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Mon, 20 Jun 2016 23:38:10 +0200 Subject: Cleanup fonts --- helpers/__init__.py | 1 + helpers/font.py | 10 ++++++++++ helpers/key.py | 15 ++++----------- 3 files changed, 15 insertions(+), 11 deletions(-) create mode 100644 helpers/font.py (limited to 'helpers') 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) -- cgit v1.2.3