From c495b06c1a81373ed099d7d9753cb47a57eb301b Mon Sep 17 00:00:00 2001 From: Michael Altfield Date: Mon, 18 Mar 2024 00:22:13 -0500 Subject: [PATCH] I changed the font list from a list to a set; now the number of fonts is down to ~200. I'm also sorting the fonts alphabetically now. I'm still fighting several issues: 1. For some reason there's a ton of items that have the radio box "checked", even as you scroll down (I think I should investigate the code that updates the OptionItem when the setting changes, and make sure it iterates through the RecycleView's `data` instance field to update `icons` for every dict (and then probably add an `on_icon()` function that updates the widget's root.icon text to reflect this) 2. Currently I'm displaying the basename() of the font file (the filename not the path) in the GUI, but that means that I have to set this to the 'value' which is also the setting in the config file. In fact, the human readable version should be distinct from what's saved to the file (the full absolute path). I should look at adding a "human readable value" or something to my BusKillOptionItem() class 3. For some reason when you scroll-up it when you're at the top of the RecycleView, it interprets that as a click. This applies to both the "Font Face" and the Trigger" section :( --- src/buskill_gui.py | 60 ++++++++++------------ src/packages/buskill/settings_buskill.json | 8 ++- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/buskill_gui.py b/src/buskill_gui.py index 0a066081..ee407c5a 100755 --- a/src/buskill_gui.py +++ b/src/buskill_gui.py @@ -22,7 +22,7 @@ from packages.garden.progressspinner import ProgressSpinner from buskill_version import BUSKILL_VERSION -import os, sys, re, webbrowser, json +import os, sys, re, webbrowser, json, operator import multiprocessing, threading from multiprocessing import util @@ -512,34 +512,15 @@ class BusKillOptionItem(FloatLayout): parent_option = ObjectProperty() manager = ObjectProperty() - #def __init__(self, title, value, desc, confirmation, icon, parent_option, manager, **kwargs): def __init__(self, **kwargs): - print( "self:|" +str(self)+ "|" ) - print( "\t" +str(dir(self))+ "|" ) - print( "kwargs:|" +str(kwargs)+ "|" ) - -# #self.title = kwargs['title'] -# self.title = StringProperty('') -# print( "title:|" +str(self.title)+ "|" ) -# #self.desc = kwargs['desc'] -# self.desc = StringProperty('') -# #self.confirmation = kwargs['confirmation'] -# self.confirmation = StringProperty('') -# #self.icon = kwargs['icon'] -# self.icon = StringProperty('') -# print( "icon:|" +str(self.icon)+ "|" ) -# #self.icon = StringProperty('') -# #self.value = kwargs['value'] -# self.value = StringProperty('') -# #self.parent_option = kwargs['parent_option'] -# parent_option = StringProperty('') -# #self.manager = kwargs['manager'] -# manager = ObjectProperty() - super(BusKillOptionItem, self).__init__(**kwargs) + # this is called when the 'manager' Kivy Property changes, which will happen + # some short time after __init__() when RecycleView creates instances of + # this object def on_manager(self, instance, value): + self.manager = value # the "main" screen @@ -549,6 +530,15 @@ def on_manager(self, instance, value): # the "main" screen self.dialog = self.main_screen.dialog + def on_parent_option(self, instance, value): + print( "WE GOT A PARENT OPTION!!!" ) + self.radio_button_label.text = 'F' + + if self.parent_option.value == self.value : + self.radio_button_label.text = '[font=mdicons][size=18sp]\ue837[/size][/font] ' + else: + self.radio_button_label.text = '[font=mdicons][size=18sp]\ue836[/size][/font] ' + # this is called when the user clicks on this OptionItem (eg choosing the # 'soft-shutdown' trigger) def on_touch_up( self, touch ): @@ -716,27 +706,33 @@ def _choose_settings_screen(self, instance): setting_screen.rv.data.extend(option_item) # handle the "font" option - if self.key == 'font': + if self.key == 'gui_font_face': # first we must determine what fonts are available on this system option_items = [] - font_paths = [] + font_paths = set() for fonts_dir_path in LabelBase.get_system_fonts_dir(): for root, dirs, files in os.walk(fonts_dir_path): for file in files[0:10]: if file.lower().endswith(".ttf"): font_path = str(os.path.join(root, file)) - print(font_path) - font_paths.append( font_path ) - font_filename = os.path.basename( font_path ) + #print(font_path) + font_paths.add( font_path ) #option_item = BusKillOptionItem( self.key, font_path, 'desc', '', '', self, manager ) #option_item = BusKillOptionItem( title = self.key, value = font_path, desc = 'test desc', confirmation = '', icon = '', parent_option = self, manager = manager ) #setting_screen.content.add_widget( option_item ) #setting_screen.rv.data = [{'text': str(x)} for x in range(4)] - option_items.append( {'title': 'title', 'value': font_filename, 'icon':'\ue167', 'desc':'', 'parent_option': self, 'manager': manager } ) - option_items = option_items + + print( "Found " +str(len(font_paths))+ " font files." ) + + for font_path in font_paths: + font_filename = os.path.basename( font_path ) + + option_items.append( {'title': 'title', 'value': font_filename, 'icon':'\ue167', 'desc':'', 'parent_option': self, 'manager': manager } ) + + option_items.sort(key=operator.itemgetter('value')) print( "len(option_items):|" + str(len(option_items))+ "|" ) print( "DEBUG: adding data:|" +str(option_items)+ "|" ) setting_screen.rv.data.extend(option_items) @@ -1320,7 +1316,7 @@ def build_config(self, config): Config.read( self.bk.CONF_FILE ) Config.setdefaults('buskill', { 'trigger': 'lock-screen', - 'font': None, + 'gui_font_face': None, }) Config.set('kivy', 'exit_on_escape', '0') Config.set('input', 'mouse', 'mouse,multitouch_on_demand') diff --git a/src/packages/buskill/settings_buskill.json b/src/packages/buskill/settings_buskill.json index b5958340..ba3aba9b 100644 --- a/src/packages/buskill/settings_buskill.json +++ b/src/packages/buskill/settings_buskill.json @@ -11,13 +11,17 @@ "confirmation": ["", "This selection may cause data loss! Are you sure you want to continue?\n\nThe 'soft-shutdown' trigger will immediately cause your computer to shutdown. This could cause you to lose work if, for example, you're writing an email or typing a text document.\n\nAre you sure you want to select the 'soft-shutdown' trigger, despite the risk of data loss?" ], "options_icons": ["\ue1bf","\ue62a"] }, + { + "type": "title", + "title": "Look & Feel" + }, { "icon": "\ue167", "type": "complex-options", - "title": "Font", + "title": "Font Face", "desc": "Choose the font in the app", "section": "buskill", - "key": "font", + "key": "gui_font_face", "options": ["roboto"], "options_long": ["Roboto Font"], "options_icons": ["\ue1bf","\ue62a"]