Skip to content

Commit

Permalink
removed references to "roboto" font face in all text markup
Browse files Browse the repository at this point in the history
This commit eliminates specifiably referencing the "roboto" font everywhere in the kivy text markup and where we update label's .text properties.

Currently we only have two font types that are explicitly defined:

 1. bkmono
 2. mdicons

The "bkmono" can be changed as-needed, but currently it's set on startup either to "RobotoMono" if the user hasn't set anything or whatever the user set their font-to. Note this means if the user sets their own font, then there will be no mono fonts displayed (unless they happened to set this to a mono font). This is also the case for bold and italic (in this commit I also replaced references to RobotoMedium with the more-robust "bold" attribute).

In the future we could consider writing some logic that tries to figure-out the Bold and Italic and BoldItalic font faces for the user's selected font, but I don't think that's so critical right now.

Currently there's also an issue where the user has to restart twice to get the font face to apply.

TODO: when the user changes their font face in Settings, update the kivy 'default_font' and then update all labels in the app to use the updated font (without requiring restarts)
  • Loading branch information
maltfield committed Mar 24, 2024
1 parent d8a34f1 commit e9d9ce1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 69 deletions.
25 changes: 11 additions & 14 deletions src/buskill.kv
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
with_previous: False
app_icon: 'images/menu.png'
markup: True
title: '[font=BKFMe][size=20sp] BusKill[/size][/font]'
title: '[b][size=20sp] BusKill[/size][/b]'
on_release: root.toggle_menu()

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

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

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

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

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

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

<-BusKillSettingsWithNoMenu>:
Expand Down Expand Up @@ -466,7 +464,7 @@
with_previous: False
app_icon: 'images/arrow_back_white.png'
markup: True
title: '[font=BKFMe][size=18sp] {0}[/size][/font]'.format( root.actionbar_title or '' )
title: '[b][size=18sp] {0}[/size][/b]'.format( root.actionbar_title or '' )
on_release:
root.manager.transition.direction = 'right'
root.manager.current = 'settings'
Expand Down Expand Up @@ -537,7 +535,7 @@
with_previous: False
app_icon: 'images/arrow_back_white.png'
markup: True
title: '[font=BKFMe][size=18sp] Settings[/size][/font]'
title: '[b][size=18sp] Settings[/size][/b]'
on_release:
root.manager.transition.direction = 'right'
root.manager.current = 'main'
Expand Down Expand Up @@ -579,7 +577,7 @@
with_previous: False
app_icon: 'images/arrow_back_white.png'
markup: True
title: '[font=BKFMe][size=18sp] Debug Log[/size][/font]'
title: '[b][size=18sp] Debug Log[/size][/b]'
on_release:
root.manager.transition.direction = 'right'
root.manager.current = 'main'
Expand All @@ -605,7 +603,6 @@
text_size: self.size
halign: 'center'
valign: 'middle'
font_name: "BKF"
font_size: '16sp'

RecycleView:
Expand Down
71 changes: 16 additions & 55 deletions src/buskill_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,20 +1040,13 @@ def reset_defaults2(self):
self.dialog.dismiss()

# delete all the options saved to the config file
print( "Config['buskill']:|" +str(Config['buskill'].__dict__.items())+ "|" )
for key in Config['buskill']:
print( "key:|" +str(key)+ "|" )

for key in Config['buskill']:
print( "attempt to delete key:|" +str(key)+ "|" )

# # is this a "title" entry?
# if key == "title":
# # this is just a title entry (without a value that can be set); skip
# pass
# else:
# this is not a "title" entry; proceed
Config.remove_option( 'buskill', key )
sections = ['kivy','buskill']
for section in sections:
for key in Config[section]:
print( "attempt to delete key:|" +str(key)+ "|" )
Config.remove_option( section, key )

# save the changes to the .ini config file
Config.write()

# setup the defaults again to avoid configparser.NoOptionError
Expand Down Expand Up @@ -1336,31 +1329,22 @@ def __init__(self, bk, **kwargs):
or 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 )
# bkmono = "BusKill Mono"; we just overwrite it with the user's font
LabelBase.register( "bkmono", gui_font_face_path )

Config.set('kivy', 'default_font', [gui_font_face_filename, gui_font_face_path])
# TODO; add logic to try to actually find an "italic", "bold", and
# "bolditalic" version of the user-selected font
Config.set('kivy', 'default_font', [gui_font_face_filename, gui_font_face_path, gui_font_face_path, gui_font_face_path, gui_font_face_path])
Config.write()

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",
"bkmono",
os.path.join( 'fonts', 'RobotoMono-Regular.ttf' ),
)

LabelBase.register(
"mdicons",
os.path.join( 'fonts', 'MaterialIcons-Regular.ttf' ),
Expand All @@ -1382,49 +1366,26 @@ def __init__(self, bk, **kwargs):
if file.lower().endswith(".ttf"):
font_paths.append(str(os.path.join(root, file)))

font_roboto_regular_path = [f for f in font_paths if f.lower().endswith("roboto-regular.ttf")]
font_roboto_medium_path = [f for f in font_paths if f.lower().endswith("roboto-medium.ttf")]
font_roboto_mono_path = [f for f in font_paths if f.lower().endswith("robotomono-regular.ttf")]
font_mdicons_path = [f for f in font_paths if f.lower().endswith("materialicons-regular.ttf")]

msg = "DEBUG: Found Roboto Regular " + str(font_roboto_regular_path)
print( msg ); logger.debug( msg )
msg = "DEBUG: Found Roboto Medium " + str(font_roboto_medium_path)
print( msg ); logger.debug( msg )
msg = "DEBUG: Found Roboto Mono " + str(font_roboto_mono_path)
print( msg ); logger.debug( msg )
msg = "DEBUG: Found Material Icons " + str(font_mdicons_path)
print( msg ); logger.debug( msg )

# just get the first file we found in all cases
font_roboto_regular_path = font_roboto_regular_path[0]
font_roboto_medium_path = font_roboto_medium_path[0]
font_roboto_mono_path = font_roboto_mono_path[0]
font_mdicons_path = font_mdicons_path[0]

LabelBase.register(
"BKF",
font_roboto_regular_path
)
LabelBase.register(
"BKFMe",
font_roboto_medium_path
)
LabelBase.register(
"BKFMo",
font_roboto_mono_path
)
LabelBase.register(
"mdicons",
font_mdicons_path
)
LabelBase.register( "bkmono", font_roboto_mono_path )
LabelBase.register( "mdicons", font_mdicons_path )

except Exception as e:

msg = "WARNING: Failed to find fonts (" +str(e) + ")"
print( msg ); logger.warning( msg )


# does rapid-fire UI-agnostic cleanup stuff when the GUI window is closed
def close( self, *args ):
self.bk.close()
Expand Down

0 comments on commit e9d9ce1

Please sign in to comment.