Skip to content

Commit

Permalink
POC: dynamically adding all fonts to ComplexOption items
Browse files Browse the repository at this point in the history
Good news: I did succed in being able to populate the ComplexOption with a list of OptionItems for every font found on the system.

Bad news: It crashed my system.

Most of these fonts are probably useless anyway. For example, I randomly picked-one and it was a font for the Tamil language. We need a way to par-down the list to be shorter.

TODO:
 1. remove symlinks (duplicates) from the list of fonts
 2. remove fonts that don't have glyphs for latin characters

For #2, I found some code on SE that uses the python module fonttools, but I actually liked this one better -- as it just uses the built-in module unicodedata

 * https://superuser.com/questions/876572/how-do-i-find-out-which-font-contains-a-certain-special-character

For more info, see:

 * #55 (comment)
  • Loading branch information
maltfield committed Mar 17, 2024
1 parent dc92d21 commit 2529ff3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
18 changes: 15 additions & 3 deletions src/buskill_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,9 +686,21 @@ def _choose_settings_screen(self, instance):
option_item = BusKillOptionItem( self.key, value, desc, confirmation, icon, self, manager )
setting_screen.content.add_widget( option_item )

# TODO: change this to actually add fonts that are available
option_item = BusKillOptionItem( 'key', 'some_font', 'desc', '', '', self, manager )
setting_screen.content.add_widget( option_item )
# handle the "font" option
if self.key == 'font':
# first we must determine what fonts are available on this system

font_paths = []
for fonts_dir_path in LabelBase.get_system_fonts_dir():

for root, dirs, files in os.walk(fonts_dir_path):
for file in files:
if file.lower().endswith(".ttf"):
font_path = str(os.path.join(root, file))
font_paths.append( font_path )
option_item = BusKillOptionItem( self.key, font_path, 'desc', '', '', self, manager )

setting_screen.content.add_widget( option_item )

# add the new ComplexOption sub-screen to the Screen Manager
manager.add_widget( setting_screen )
Expand Down
8 changes: 0 additions & 8 deletions src/packages/buskill/settings_buskill.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,5 @@
"options": ["roboto"],
"options_long": ["Roboto Font"],
"options_icons": ["\ue1bf","\ue62a"]
},
{
"type": "options",
"title": "Font",
"desc": "Choose the font in the app",
"section": "buskill",
"key": "font",
"options": ["font1", "font2"]
}
]

0 comments on commit 2529ff3

Please sign in to comment.