ControlPanelOption

class lib.gui.control_helper.ControlPanelOption(title: str, dtype: type, group: str | None = None, subgroup: str | None = None, default: str | bool | float | int | None = None, initial_value: str | bool | float | int | None = None, choices: list[str] | tuple[str, ...] | Literal['colorchooser'] | None = None, is_radio: bool = False, is_multi_option: bool = False, rounding: int | float | None = None, min_max: tuple[int, int] | tuple[float, float] | None = None, sysbrowser: dict[Literal['filetypes', 'browser', 'command', 'destination', 'action_option'], str | list[str]] | None = None, helptext: str | None = None, track_modified: bool = False, command: str | None = None)

Bases: object

A class to hold a control panel option. A list of these is expected to be passed to the ControlPanel object.

Parameters:
  • title (str) – Title of the control. Will be used for label text and control naming

  • dtype (type) – Datatype of the control.

  • group (str | None, optional) – The group that this control should sit with. If provided, all controls in the same group will be placed together. Default: None

  • subgroup (str | None, optional) – The subgroup that this option belongs to. If provided, will group options in the same subgroups together for the same layout as option/check boxes. Default: None

  • default (str | bool | float | int | list[str] | None, optional) – Default value for the control. If None is provided, then action will be dictated by whether “blank_nones” is set in ControlPanel. Default: None

  • initial_value (str | bool | float | int | list[str] | None, optional) – Initial value for the control. If None, default will be used. Default: None

  • choices (list[str] | tuple[str, ...] | Literal["colorchooser"] | None, optional) – Used for combo boxes and radio control option setting. Set to “colorchooser” for a color selection dialog. Default: None

  • is_radio (bool, optional) – Specifies to use a Radio control instead of combobox if choices are passed. Default: False

  • is_multi_option (bool, optional) – Specifies to use a Multi Check Button option group for the specified control. Default: False

  • rounding (int | float | None, optional) – For slider controls. Sets the stepping. Default: None

  • min_max (tuple[int, int] | tuple[float, float] | None, optional) – For slider controls. Sets the min and max values. Default: None

  • sysbrowser (dict[Literal["filetypes", "browser", "command", "destination", "action_option"], str | list[str]] | None, optional) – Adds Filesystem browser buttons to ttk.Entry options. Default: None

  • helptext (str | None, optional) – Sets the tooltip text. Default: None

  • track_modified (bool, optional) – Set whether to set a callback trace indicating that the parameter has been modified. Default: False

  • command (str | None, optional) – Required if tracking modified. The command that this option belongs to. Default: None

Attributes Summary

choices

The option choices

default

Either the currently selected value or the default

group

Option group or "_master" if no group set

helptext

The formatted option help text for tooltips

is_multi_option

True if the control should be contained in a multi check button group, otherwise False.

is_radio

If the option should be a radio control

min_max

minimum and maximum values for numeric controls

name

Lowered title for naming

rounding

Rounding for numeric controls

subgroup

Option subgroup, or None if none provided.

title

Title case title for naming with underscores removed

value

Either the initial value or default

Methods Summary

from_config_object(title, option)

Create a GUI control panel option from a Faceswap ConfigItem

get()

Return the option value from the tk_var

get_control()

Set the correct control type based on the datatype or for this option

get_tk_var(initial_value)

Correct variable type for control

set(value)

Set the variable for the config option with the given value

set_initial_value(value)

Set the initial_value to the given value

Attributes Documentation

choices

The option choices

Type:

list[str] | tuple[str, …] | Literal[“colorchooser”]

default

Either the currently selected value or the default

Type:

str | bool | float | int | list[str]

group

Option group or “_master” if no group set

Type:

str

helptext

The formatted option help text for tooltips

Type:

str | None

is_multi_option

True if the control should be contained in a multi check button group, otherwise False.

Type:

bool

is_radio

If the option should be a radio control

Type:

bool

min_max

minimum and maximum values for numeric controls

Type:

tuple[int, int] | tuple[float, float] | None

name

Lowered title for naming

Type:

str

rounding

Rounding for numeric controls

Type:

int | float | None

subgroup

Option subgroup, or None if none provided.

Type:

str | None

title

Title case title for naming with underscores removed

Type:

str

value

Either the initial value or default

Type:

str | bool | float | int | list[str]

Methods Documentation

classmethod from_config_object(title: str, option: ConfigItem) Self

Create a GUI control panel option from a Faceswap ConfigItem

Parameters:
  • title (str) – The option title (that displays as a label in the GUI)

  • option (ConfigItem) – The faceswap object to create the Control Panel option from

Returns:

A GUI ControlPanelOption instance

Return type:

ControlPanelOption

get() str | bool | int | float

Return the option value from the tk_var

Returns:

The value selected for this option

Return type:

str | bool | float | int

Notes

tk variables don’t like empty values if it’s not a stringVar. This seems to be pretty much the only reason that a get() call would fail, so replace any numerical variable with it’s numerical zero equivalent on a TCL Error. Only impacts variables linked to Entry widgets.

get_control() Literal['radio', 'multi', 'colorchooser', 'scale'] | type[Combobox] | type[Checkbutton] | type[Entry]

Set the correct control type based on the datatype or for this option

Return type:

Literal[‘radio’, ‘multi’, ‘colorchooser’, ‘scale’] | type[~tkinter.ttk.Combobox] | type[~tkinter.ttk.Checkbutton] | type[~tkinter.Entry]

get_tk_var(initial_value: str | bool | int | float) Variable

Correct variable type for control

Parameters:
  • value (initial) – The initial value to set the tk.Variable to

  • initial_value (str | bool | int | float)

Returns:

The correct tk.Variable for the given initial value

Return type:

tk.BooleanVar | tk.IntVar | tk.DoubleVar | tk.StringVar

set(value: str | bool | int | float | None) None

Set the variable for the config option with the given value

Parameters:

value (str | bool | float | int | None) – The value to set the config option variable to

Return type:

None

set_initial_value(value: str | bool | int | float)

Set the initial_value to the given value

Parameters:

value (str | bool | int | float) – The value to set the initial value attribute to

property choices: list[str] | tuple[str, ...] | Literal['colorchooser'] | None

The option choices

Type:

list[str] | tuple[str, …] | Literal[“colorchooser”]

property default: str | bool | float | int | None

Either the currently selected value or the default

Type:

str | bool | float | int | list[str]

classmethod from_config_object(title: str, option: ConfigItem) Self

Create a GUI control panel option from a Faceswap ConfigItem

Parameters:
  • title (str) – The option title (that displays as a label in the GUI)

  • option (ConfigItem) – The faceswap object to create the Control Panel option from

Returns:

A GUI ControlPanelOption instance

Return type:

ControlPanelOption

get() str | bool | int | float

Return the option value from the tk_var

Returns:

The value selected for this option

Return type:

str | bool | float | int

Notes

tk variables don’t like empty values if it’s not a stringVar. This seems to be pretty much the only reason that a get() call would fail, so replace any numerical variable with it’s numerical zero equivalent on a TCL Error. Only impacts variables linked to Entry widgets.

get_control() Literal['radio', 'multi', 'colorchooser', 'scale'] | type[Combobox] | type[Checkbutton] | type[Entry]

Set the correct control type based on the datatype or for this option

Return type:

Literal[‘radio’, ‘multi’, ‘colorchooser’, ‘scale’] | type[~tkinter.ttk.Combobox] | type[~tkinter.ttk.Checkbutton] | type[~tkinter.Entry]

get_tk_var(initial_value: str | bool | int | float) Variable

Correct variable type for control

Parameters:
  • value (initial) – The initial value to set the tk.Variable to

  • initial_value (str | bool | int | float)

Returns:

The correct tk.Variable for the given initial value

Return type:

tk.BooleanVar | tk.IntVar | tk.DoubleVar | tk.StringVar

property group: str

Option group or “_master” if no group set

Type:

str

property helptext: str | None

The formatted option help text for tooltips

Type:

str | None

property is_multi_option: bool

True if the control should be contained in a multi check button group, otherwise False.

Type:

bool

property is_radio: bool

If the option should be a radio control

Type:

bool

property min_max: tuple[int, int] | tuple[float, float] | None

minimum and maximum values for numeric controls

Type:

tuple[int, int] | tuple[float, float] | None

property name: str

Lowered title for naming

Type:

str

property rounding: int | float | None

Rounding for numeric controls

Type:

int | float | None

set(value: str | bool | int | float | None) None

Set the variable for the config option with the given value

Parameters:

value (str | bool | float | int | None) – The value to set the config option variable to

Return type:

None

set_initial_value(value: str | bool | int | float)

Set the initial_value to the given value

Parameters:

value (str | bool | int | float) – The value to set the initial value attribute to

property subgroup: str | None

Option subgroup, or None if none provided.

Type:

str | None

property title

Title case title for naming with underscores removed

Type:

str

property value: str | bool | float | int | None

Either the initial value or default

Type:

str | bool | float | int | list[str]