config module
Default configurations for faceswap.
Extends out configparser.ConfigParser
functionality by checking for default
configuration updates and returning data in it’s correct format
- class lib.config.ConfigItem(default: bool | int | float | list[str] | str | None, helptext: str, datatype: type, rounding: int, min_max: tuple[int, int] | tuple[float, float] | None, choices: str | list[str], gui_radio: bool, fixed: bool, group: str | None)
Bases:
object
Dataclass for holding information about configuration items
- Parameters:
default (any) – The default value for the configuration item
helptext (str) – The helptext to be displayed for the configuration item
datatype (type) – The type of the configuration item
rounding (int) – The decimal places for floats or the step interval for ints for slider updates
min_max (tuple) – The minumum and maximum value for the GUI slider for the configuration item
gui_radio (bool) –
True
to display the configuration item in a Radio Boxfixed (bool) –
True
if the item cannot be changed for existing models (training only)group (str) – The group that this configuration item belongs to in the GUI
- choices: str | list[str]
- datatype: type
- default: bool | int | float | list[str] | str | None
- fixed: bool
- group: str | None
- gui_radio: bool
- helptext: str
- min_max: tuple[int, int] | tuple[float, float] | None
- rounding: int
- class lib.config.ConfigSection(helptext: str, items: OrderedDict[str, ConfigItem])
Bases:
object
Dataclass for holding information about configuration sections
- Parameters:
helptext (str) – The helptext to be displayed for the configuration section
items (
collections.OrderedDict
) – Dictionary of configuration items for the section
- helptext: str
- items: OrderedDict[str, ConfigItem]
- class lib.config.FaceswapConfig(section: str | None, configfile: str | None = None)
Bases:
object
Config Items
- add_item(section: str | None = None, title: str | None = None, datatype: type = <class 'str'>, default: bool | int | float | list[str] | str | None = None, info: str | None = None, rounding: int | None = None, min_max: tuple[int, int] | tuple[float, float] | None = None, choices: str | list[str] | None = None, gui_radio: bool = False, fixed: bool = True, group: str | None = None) None
Add a default item to a config section
For int or float values, rounding and min_max must be set This is for the slider in the GUI. The min/max values are not enforced: rounding: sets the decimal places for floats or the step interval for ints. min_max: tuple of min and max accepted values
For str values choices can be set to validate input and create a combo box in the GUI
For list values, choices must be provided, and a multi-option select box will be created
is_radio is to indicate to the GUI that it should display Radio Buttons rather than combo boxes for multiple choice options.
The ‘fixed’ parameter is only for training configurations. Training configurations are set when the model is created, and then reloaded from the state file. Marking an item as fixed=False indicates that this value can be changed for existing models, and will override the value saved in the state file with the updated value in config.
The ‘Group’ parameter allows you to assign the config item to a group in the GUI
- add_section(title: str, info: str) None
Add a default section to config file
- Parameters:
title (str) – The title for the section
info (str) – The helptext for the section
- property changeable_items: dict[str, bool | int | float | list[str] | str | None]
Training only. Return a dict of config items with their set values for items that can be altered after the model has been created
- property config_dict: dict[str, bool | int | float | list[str] | str | None]
Collate global options and requested section into a dictionary with the correct data types
- Type:
dict
- classmethod format_help(helptext: str, is_section: bool = False) str
Format comments for default ini file
- Parameters:
helptext (str) – The help text to be formatted
is_section (bool, optional) –
True
if the help text pertains to a section.False
if it pertains to an item. Default:True
- Returns:
The formatted help text
- Return type:
str
- get(section: str, option: str) bool | int | float | list[str] | str | None
Return a config item in it’s correct format.
- Parameters:
section (str) – The configuration section currently being processed
option (str) – The configuration option currently being processed
- Returns:
The selected configuration option in the correct data format
- Return type:
varies
- insert_config_section(section: str, helptext: str, config: ConfigParser | None = None) None
Insert a section into the config
- Parameters:
section (str) – The section title to insert
helptext (str) – The help text for the config section
config (
configparser.ConfigParser
, optional) – The config parser object to insert the section into.None
to insert it into the default config. Default:None
- save_config() None
Save a config file
- set_defaults() None
Override for plugin specific config defaults
Should be a series of self.add_section() and self.add_item() calls
e.g:
section = “sect_1” self.add_section(section,
“Section 1 Information”)
- self.add_item(section=section,
title=”option_1”, datatype=bool, default=False, info=”sect_1 option_1 information”)
- lib.config.generate_configs() None
Generate config files if they don’t exist.
This script is run prior to anything being set up, so don’t use logging Generates the default config files for plugins in the faceswap config folder