diff --git a/examples/widgets/codeinput.py b/examples/widgets/codeinput.py index 0ad568d53..4bb814dbc 100644 --- a/examples/widgets/codeinput.py +++ b/examples/widgets/codeinput.py @@ -6,9 +6,11 @@ from kivy.uix.codeinput import CodeInput from kivy.uix.popup import Popup from kivy.properties import ListProperty from kivy.core.window import Window +from kivy.core.text import LabelBase from pygments import lexers -from pygame import font as fonts + import codecs +import glob import os example_text = ''' @@ -106,10 +108,13 @@ class CodeInputTest(App): text='12', values=list(map(str, list(range(5, 40))))) fnt_size.bind(text=self._update_size) + + fonts = [file for file in LabelBase._font_dirs_files if file.endswith('.ttf')] + fnt_name = Spinner( - text='RobotoMono', + text='RiobotoMono', option_cls=Fnt_SpinnerOption, - values=sorted(map(str, fonts.get_fonts()))) + values=fonts) fnt_name.bind(text=self._update_font) mnu_file = Spinner( text='File', @@ -123,6 +128,7 @@ class CodeInputTest(App): b.add_widget(menu) self.codeinput = CodeInput( + lexer=KivyLexer(), font_size=12, text=example_text) @@ -135,9 +141,7 @@ class CodeInputTest(App): self.codeinput.font_size = float(size) def _update_font(self, instance, fnt_name): - font_name = fonts.match_font(fnt_name) - if os.path.exists(font_name): - instance.font_name = self.codeinput.font_name = font_name + instance.font_name = self.codeinput.font_name = fnt_name def _file_menu_selected(self, instance, value): if value == 'File': diff --git a/examples/widgets/codeinputtest.kv b/examples/widgets/codeinputtest.kv index c513ad4ff..381937537 100644 --- a/examples/widgets/codeinputtest.kv +++ b/examples/widgets/codeinputtest.kv @@ -1,9 +1,6 @@ -#:import fonts pygame.font #:import os os : - fnt_name: fonts.match_font(self.text) - resolved_name: self.fnt_name if os.path.exists(self.fnt_name) else self.font_name - font_name: self.resolved_name if self.resolved_name else self.font_name + font_name: self.text : title: filechooser.path diff --git a/kivy/core/text/__init__.py b/kivy/core/text/__init__.py index b3ffaf2ad..423bea653 100644 --- a/kivy/core/text/__init__.py +++ b/kivy/core/text/__init__.py @@ -148,6 +148,8 @@ class LabelBase(object): _fonts_dirs = [] + _font_dirs_files = [] + _texture_1px = None def __init__( @@ -287,11 +289,16 @@ class LabelBase(object): fdirs.append(kivy_data_dir + os.sep + 'fonts') # let's register the font dirs rdirs = [] - for _dir in fdirs: - if os.path.exists(_dir): - resource_add_path(_dir) - rdirs.append(_dir) + _font_dir_files = [] + for fdir in fdirs: + for _dir, dirs, files in os.walk(fdir): + _font_dir_files.extend(files) + if os.path.exists(_dir): + resource_add_path(_dir) + rdirs.append(_dir) LabelBase._fonts_dirs = rdirs + LabelBase._font_dirs_files = _font_dir_files + return rdirs raise Exception("Unknown Platform {}".format(platform))