mirror of https://github.com/kivy/kivy.git
Core:LabelBase: recurse all dirs. closes #3270
This commit is contained in:
parent
7de66e6543
commit
1360355990
|
@ -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':
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
#:import fonts pygame.font
|
||||
#:import os os
|
||||
<Fnt_SpinnerOption>:
|
||||
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
|
||||
|
||||
<LoadDialog>:
|
||||
title: filechooser.path
|
||||
|
|
|
@ -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))
|
||||
|
||||
|
|
Loading…
Reference in New Issue