How can I tell Kivy to update a given Config with its default values at runtime?
I have a "reset settings to defaults" button in my app that deletes all of the entries in my Kivy Config, including in the [kivy] section.
# delete all the options saved to the config file
sections = ['kivy','myapp','etc']
for section in sections:
for key in Config[section]:
Config.remove_option( section, key )
# write-out the changes to the .ini file
Config.write()
After the above commands execute, I'm left with an empty [kivy] section in my .ini file, as desired.
The problem is that I'm having a NoOptionError later in my code that's expecting the default_font option in the Kivy Config
configparser.NoOptionError: No option 'default_font' in section: 'kivy
After the above code wipes away any config options in the [kivy] section of my .ini file, how can I tell Kivy to repopulate it with the defaults?
When I restart the app, Kivy does repopulate the [kivy] section of my .ini file as desired. And I can see that the code that does that is located here:
elif version == 16:
Config.setdefault('kivy', 'default_font', [
'Roboto',
'data/fonts/Roboto-Regular.ttf',
'data/fonts/Roboto-Italic.ttf',
'data/fonts/Roboto-Bold.ttf',
'data/fonts/Roboto-BoldItalic.ttf'])
But how can I execute the above kivy code at runtime so that it updates my Config with the defaults without having to restart the app?
Note I'm aware that I can manually make my own
build_config()function and callConfig.setdefaults('kivy', {...})where I type the default values myself in the dictionary. That's not what I'm asking for. I'm asking how to call the above code that's part of kivy, so the code is not redundant and is future-proof.
I don't think that changing your
Configdefaults will have any effect on your currently runningAppif you change them as you describe. You can force reset by just having yourButtonremove the defaultconfig.ini. The path to the defaultconfig.iniis inConfig.filename. The next time anykivyapp is started, the default will be restored.Another option is to not use
Config.write()at all (that just saves the current settings to theinifile and is not necessary when just changing the settings for the currentApp). Then just do aConfig.read(Config.filename)to restore the settings that are still in theinifile.