Config

Configuration module for Nicotine+ plugins

This module provides an advanced way to define the configuration of a plugin. It allows for the definition of the settings once in a object oriented way and automatically generates the settings and metasettings for the plugin.

Example

from npc import BasePlugin, String, Int, Float, Bool, ListString, Dropdown, Radio

class Plugin(BasePlugin):

    class Config(BasePlugin.Config):
         setting_1 = String("This is setting 1", "default")
         setting_2 = Int("This is setting 2", 0)
         setting_3 = Float("This is setting 3", 0.0, maximum=10.0, minimum=0.0, stepsize=0.1)
         setting_4 = Bool("This is setting 4", False)
         setting_5 = ListString("This is setting 5", ["item1", "item2", "item3"])
         setting_6 = Dropdown("This is setting 6", ["option1", "option2", "option3"], "option1")
         setting_7 = Radio("This is setting 7", ["option1", "option2", "option3"], "option1")
         setting_8 = File("This is setting 8", "", chooser=FileChooser.DIRECTORY)

...

Note

It’s recommended to inherit from npc.BasePlugin.Config to get the default config including the config for checking for updates.

In your plugins code it’s recommended to use the npc.BasePlugin.config attribute to access the configuration, instead of Nicotine+’s default npc.BasePlugin.settings. This is because changes to npc.BasePlugin.settings will not persist across sessions. As well as the npc.BasePlugin.config attribute is type hinted, thus providing better code completion and safety.

Warning

When changing settings programmatically be e.g.:

plugin.config.setting_5.sort()
plugin.config.setting_1 = "new value"

the changes will not persist across sessions. You must call npc.BaseConfig.apply() to persist the changes. This is because Nicotine+ stores the settings during runtime in a all in one dict and persists this, without taking changes on the plugins instance into account. npc.BaseConfig.apply() will update the global configuration.

self.config.apply()