Skip to content

Commit

Permalink
Implemented User-specified font
Browse files Browse the repository at this point in the history
This successfully applies the user's chosen font from the GUI's settings screen (and Config option 'gui_font_face'), but it does not apply everywhere (yet)

TODO:
 1. See if you can update `default_font` to get it to apply to all Labels (by default)
 1. See if you can get the font settings to apply to all labels after the Setting is changed (during runtime; without requiring a restart of the app)
  • Loading branch information
maltfield committed Mar 24, 2024
1 parent 525821e commit b7fc6e2
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 38 deletions.
36 changes: 18 additions & 18 deletions src/buskill.kv
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# For more info, see: https://buskill.in/
# Authors: Michael Altfield <michael@buskill.in>
# Created: 2020-06-23
# Updated: 2023-06-14
# Version: 0.3
# Updated: 2024-03-24
# Version: 0.4
################################################################################

#:set DEBUG False
Expand Down Expand Up @@ -62,7 +62,7 @@
with_previous: False
app_icon: 'images/menu.png'
markup: True
title: '[font=RobotoMedium][size=20sp] BusKill[/size][/font]'
title: '[font=BKFMe][size=20sp] BusKill[/size][/font]'
on_release: root.toggle_menu()

NavigationDrawer:
Expand All @@ -83,7 +83,7 @@
orientation: 'lr-tb'

Button:
text: '[font=Roboto][size=24sp] [/size][/font][font=mdicons][size=24sp]\ue923[/size][/font] [font=RobotoMedium][size=16sp]Update[/size][/font]'
text: '[font=BKF][size=24sp] [/size][/font][font=mdicons][size=24sp]\ue923[/size][/font] [font=BKFMe][size=16sp]Update[/size][/font]'
markup: True
halign: 'left'
valign: 'center'
Expand All @@ -95,7 +95,7 @@
on_release: root.upgrade1()

Button:
text: '[font=Roboto][size=24sp] [/size][/font][font=mdicons][size=24sp]\ue8b8[/size][/font] [font=RobotoMedium][size=16sp]Settings[/size][/font]'
text: '[font=BKF][size=24sp] [/size][/font][font=mdicons][size=24sp]\ue8b8[/size][/font] [font=BKFMe][size=16sp]Settings[/size][/font]'
markup: True
halign: 'left'
valign: 'center'
Expand All @@ -109,7 +109,7 @@
root.manager.current = 'settings'

Button:
text: '[font=Roboto][size=24sp] [/size][/font][font=mdicons][size=24sp]\ue868[/size][/font] [font=RobotoMedium][size=16sp]Debug Log[/size][/font]'
text: '[font=BKF][size=24sp] [/size][/font][font=mdicons][size=24sp]\ue868[/size][/font] [font=BKFMe][size=16sp]Debug Log[/size][/font]'
markup: True
halign: 'left'
valign: 'center'
Expand All @@ -123,7 +123,7 @@
root.manager.current = 'debug_log'

Button:
text: '[font=Roboto][size=24sp] [/size][/font][font=mdicons][size=24sp]\ue88f[/size][/font] [font=RobotoMedium][size=16sp]About[/size][/font]'
text: '[font=BKF][size=24sp] [/size][/font][font=mdicons][size=24sp]\ue88f[/size][/font] [font=BKFMe][size=16sp]About[/size][/font]'
markup: True
halign: 'left'
valign: 'center'
Expand Down Expand Up @@ -165,13 +165,13 @@
text_size: self.size
halign: 'center'
valign: 'middle'
font_name: "Roboto"
font_name: "BKF"
font_size: '20sp'

Button:
id: toggle_btn
text: "Arm"
font_name: "RobotoMedium"
font_name: "BKFMe"
font_size: '40sp'
background_normal: ''
background_color: 0.129, 0.588, 0.953, 1
Expand Down Expand Up @@ -203,7 +203,7 @@
Label:
id: l_title
text: root.title
font_name: "RobotoMedium"
font_name: "BKFMe"
font_size: '20sp'
markup: True
pos_hint: {'center_x': 0.5}
Expand All @@ -214,7 +214,7 @@
id: l_body
text: root.body
text_size: self.size[0], None
font_name: "Roboto"
font_name: "BKF"
font_size: '16sp'
markup: True
size_hint: 1, None
Expand Down Expand Up @@ -251,7 +251,7 @@
text: "Loading Log. Please wait."
size_hint_x: None
width: self.texture_size[0]
font_name: "RobotoMono"
font_name: "BKFMo"
font_size: '12sp'

<-BusKillSettingsWithNoMenu>:
Expand All @@ -273,7 +273,6 @@
height: self.minimum_height

<-BusKillSettingItem>:
#:set DEBUG False
size_hint: .25, None
height: labellayout.height + dp(10)
padding: 6
Expand Down Expand Up @@ -357,7 +356,8 @@
canvas:
Color:
#rgba: 47 / 255., 167 / 255., 212 / 255., self.selected_alpha
rgba: 0, 1, 0, 1
#rgba: 0, 1, 0, 1
rgba: (0, 1, 0, 1 if DEBUG == True else 0, 0, 0, 0)
Rectangle:
pos: self.x, self.y + 1
size: self.size
Expand Down Expand Up @@ -466,7 +466,7 @@
with_previous: False
app_icon: 'images/arrow_back_white.png'
markup: True
title: '[font=RobotoMedium][size=18sp] {0}[/size][/font]'.format( root.actionbar_title or '' )
title: '[font=BKFMe][size=18sp] {0}[/size][/font]'.format( root.actionbar_title or '' )
on_release:
root.manager.transition.direction = 'right'
root.manager.current = 'settings'
Expand Down Expand Up @@ -537,7 +537,7 @@
with_previous: False
app_icon: 'images/arrow_back_white.png'
markup: True
title: '[font=RobotoMedium][size=18sp] Settings[/size][/font]'
title: '[font=BKFMe][size=18sp] Settings[/size][/font]'
on_release:
root.manager.transition.direction = 'right'
root.manager.current = 'main'
Expand Down Expand Up @@ -579,7 +579,7 @@
with_previous: False
app_icon: 'images/arrow_back_white.png'
markup: True
title: '[font=RobotoMedium][size=18sp] Debug Log[/size][/font]'
title: '[font=BKFMe][size=18sp] Debug Log[/size][/font]'
on_release:
root.manager.transition.direction = 'right'
root.manager.current = 'main'
Expand All @@ -605,7 +605,7 @@
text_size: self.size
halign: 'center'
valign: 'middle'
font_name: "Roboto"
font_name: "BKF"
font_size: '16sp'

RecycleView:
Expand Down
57 changes: 37 additions & 20 deletions src/buskill_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1307,25 +1307,42 @@ def __init__(self, bk, **kwargs):
# register font aiases so we don't have to specify their full file path
# when setting font names in our kivy language .kv files
try:


# did the user set a custom font?
default_font = Config.get('kivy', 'default_font')
gui_font_face_path = Config.get('buskill', 'gui_font_face')

if gui_font_face_path not in default_font:
# the user set a custom font; use it

# Set the "BusKill Font" that's used in kivy label's .text markup
LabelBase.register( "BKF", gui_font_face_path )
# BKFMe = "Medium/Bold", but we just overwrite it with the user's font
LabelBase.register( "BKFMe", gui_font_face_path )
# BKFMo = "Mono", but we just overwrite it with the user's font
LabelBase.register( "BKFMo", gui_font_face_path )
else:
# the user did *not* set a custom font; use Roboto

LabelBase.register(
"BKF",
os.path.join( 'fonts', 'Roboto-Regular.ttf' ),
)
LabelBase.register(
"BKFMe",
os.path.join( 'fonts', 'Roboto-Medium.ttf' ),
)
LabelBase.register(
"BKFMo",
os.path.join( 'fonts', 'RobotoMono-Regular.ttf' ),
)

LabelBase.register(
"Roboto",
#os.path.join( bk.EXE_DIR, 'fonts', 'Roboto-Regular.ttf' ),
os.path.join( 'fonts', 'Roboto-Regular.ttf' ),
)
LabelBase.register(
"RobotoMedium",
#os.path.join( bk.EXE_DIR, 'fonts', 'Roboto-Medium.ttf' ),
os.path.join( 'fonts', 'Roboto-Medium.ttf' ),
)
LabelBase.register(
"RobotoMono",
os.path.join( 'fonts', 'RobotoMono-Regular.ttf' ),
)
LabelBase.register(
"mdicons",
#os.path.join( bk.EXE_DIR, 'fonts', 'MaterialIcons-Regular.ttf' ),
os.path.join( 'fonts', 'MaterialIcons-Regular.ttf' ),
"mdicons",
os.path.join( 'fonts', 'MaterialIcons-Regular.ttf' ),
)

except Exception as e:

msg = "INFO: Failed to load fonts (" +str(e) + ")"
Expand Down Expand Up @@ -1363,15 +1380,15 @@ def __init__(self, bk, **kwargs):
font_mdicons_path = font_mdicons_path[0]

LabelBase.register(
"Roboto",
"BKF",
font_roboto_regular_path
)
LabelBase.register(
"RobotoMedium",
"BKFMe",
font_roboto_medium_path
)
LabelBase.register(
"RobotoMono",
"BKFMo",
font_roboto_mono_path
)
LabelBase.register(
Expand Down

0 comments on commit b7fc6e2

Please sign in to comment.