From bb69f62e140efde8e93f7b62bf8723113bf30b06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Sun, 26 Jun 2016 00:18:52 +0200 Subject: Make kivy compatible with pyinstaller --- helpers/__init__.py | 10 ++++++++++ music_sampler.py | 7 ++++++- music_sampler.spec | 3 ++- musicsampler.kv | 17 +++++++++-------- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/helpers/__init__.py b/helpers/__init__.py index 40a96af..70667fd 100644 --- a/helpers/__init__.py +++ b/helpers/__init__.py @@ -1 +1,11 @@ # -*- coding: utf-8 -*- +import sys +import os + +def path(): + if getattr(sys, 'frozen', False): + return sys._MEIPASS + "/" + else: + path = os.path.dirname(os.path.realpath(__file__)) + return path + "/../" + diff --git a/music_sampler.py b/music_sampler.py index 0d9a7a9..7c0fc32 100644 --- a/music_sampler.py +++ b/music_sampler.py @@ -4,10 +4,15 @@ from kivy.uix.relativelayout import RelativeLayout from kivy.properties import ListProperty, StringProperty from kivy.clock import Clock from kivy.core.window import Window - +from kivy.lang import Builder from helpers.key import Key from helpers.mapping import Mapping +import sys + +if getattr(sys, 'frozen', False): + Builder.load_file(sys._MEIPASS + '/musicsampler.kv') + class PlayList(RelativeLayout): playlist = ListProperty([]) diff --git a/music_sampler.spec b/music_sampler.spec index 912edb7..fca4005 100644 --- a/music_sampler.spec +++ b/music_sampler.spec @@ -6,7 +6,8 @@ a = Analysis(['music_sampler.py'], binaries=None, datas=[ ('config.yml', '.'), - ('fonts/*', 'fonts') + ('fonts/*', 'fonts'), + ('musicsampler.kv', '.') ], hiddenimports=[ 'six', diff --git a/musicsampler.kv b/musicsampler.kv index 17be1f5..3bf344e 100644 --- a/musicsampler.kv +++ b/musicsampler.kv @@ -1,4 +1,5 @@ #:import math math +#:import h helpers : pad_col_sep: 0 if not self.pad_cols else self.parent.pad_x @@ -32,7 +33,7 @@ width: self.line_width Label: id: key_label - font_name: "fonts/Ubuntu-B.ttf" + font_name: h.path() + "fonts/Ubuntu-B.ttf" font_size: math.ceil(2 * math.sqrt(self.parent.parent.key_size)) color: 0, 0, 0, 1 text: self.parent.key_sym @@ -44,7 +45,7 @@ center_y: self.parent.y + self.parent.height - self.texture_size[1] /2 - 5 Label: id: key_description_title - font_name: "fonts/Ubuntu-Regular.ttf" + font_name: h.path() + "fonts/Ubuntu-Regular.ttf" font_size: math.ceil(2 * math.sqrt(self.parent.parent.key_size / 2)) color: 0, 0, 0, 1 text: self.parent.description_title @@ -55,7 +56,7 @@ center_y: self.parent.y + self.parent.height - self.texture_size[1] /2 - 5 Label: id: key_description - font_name: "fonts/Ubuntu-Regular.ttf" + font_name: h.path() + "fonts/Ubuntu-Regular.ttf" font_size: math.ceil(2 * math.sqrt(self.parent.parent.key_size / 2)) color: 0, 0, 0, 1 text: "\n".join(self.parent.description) @@ -121,7 +122,7 @@ size: self.width, self.height Label: id: action_list_title - font_name: "fonts/Ubuntu-B.ttf" + font_name: h.path() + "fonts/Ubuntu-B.ttf" font_size: math.ceil(2 * math.sqrt(self.parent.parent.key_size or 10)) color: 0, 0, 0, 1 text: self.parent.action_title @@ -132,7 +133,7 @@ size: self.texture_size[0], self.parent.height Label: id: action_list_icons - font_name: "fonts/Symbola.ttf" + font_name: h.path() + "fonts/Symbola.ttf" font_size: math.ceil(2 * math.sqrt(self.parent.parent.key_size or 10)) line_height: 1.2 # FIXME: Donner la bonne taille de label color: 0, 0, 0, 1 @@ -144,7 +145,7 @@ size: self.texture_size[0], self.parent.height - 3 * self.line_height * self.font_size Label: id: action_list_names - font_name: "fonts/Ubuntu-Regular.ttf" + font_name: h.path() + "fonts/Ubuntu-Regular.ttf" font_size: math.ceil(2 * math.sqrt(self.parent.parent.key_size or 10)) color: 0, 0, 0, 1 text: "\n".join(map(lambda x: x[1], self.parent.action_list)) @@ -165,7 +166,7 @@ size: self.width, self.height Label: id: playlist_icons - font_name: "fonts/Symbola.ttf" + font_name: h.path() + "fonts/Symbola.ttf" font_size: math.ceil(2 * math.sqrt(self.parent.parent.key_size or 10)) line_height: 1.2 # FIXME: Donner la bonne taille de label color: 0, 0, 0, 1 @@ -177,7 +178,7 @@ size: self.texture_size[0], self.parent.height Label: id: playlist_names - font_name: "fonts/Ubuntu-Regular.ttf" # FIXME: Mettre en gras quand c'est en cours + font_name: h.path() + "fonts/Ubuntu-Regular.ttf" # FIXME: Mettre en gras quand c'est en cours font_size: math.ceil(2 * math.sqrt(self.parent.parent.key_size or 10)) color: 0, 0, 0, 1 text: "\n".join(map(lambda x: x[1], self.parent.playlist)) -- cgit v1.2.3