Options#

class ignis.services.options.OptionsService(*args: Any, **kwargs: Any)#

Service to manage options and options groups. This service stores options and their values in the ~/.cache/ignis/options.json file.

Warning

You should not manually edit the ~/.cache/ignis/options.json file. Use this service instead.

Properties:
  • groups (list[OptionsGroup]): The list of all options groups.

  • data (dict[str, Any]): The dictionary containing all options and their values from all groups.

Example usage:

from ignis.services.options import OptionsService

options = OptionsService.get_default()

some_opt_group = options.create_group(name="some_group", exists_ok=True)

some_option = some_opt_group.create_option(name="some_option", default="hi", exists_ok=True)
some_option.set_value("bye")

print(some_option.value)

print(some_opt_group.data)

print(options.data)
create_group(name: str, exists_ok: bool = False) OptionsGroup#

Create options group.

Parameters:
  • name (str) -- The name of the options group to create.

  • exists_ok (bool, optional) -- If True, do not raise OptionsGroupExistsError if the group already exists. Default: False.

Returns:

The newly created options group or already existing one.

Return type:

OptionsGroup

Raises:

OptionsGroupExistsError -- If the options group already exists and exists_ok is set to False.

get_group(name: str) OptionsGroup#

Get OptionsGroup object by its name.

Parameters:

name (str) -- The name of the options group.

Returns:

The options group instance.

Return type:

OptionsGroup

Raises:

OptionsGroupNotFoundError -- If the options group does not exist.

class ignis.services.options.OptionsGroup(*args: Any, **kwargs: Any)#

An options group.

Warning

You shouldn't initialize this class manually. Use the create_group() method instead.

Signals:
  • "changed" (): Emitted when options in this group is changed.

  • "changed" (): Emitted when this options group is removed.

Properties:
  • name (str, read-only): The name of the group.

  • data (dict[str, Any], read-only): The dictionary containing all options and their values.

create_option(name: str, default: Any, exists_ok: bool = False) Option#

Create an option.

Parameters:
  • name (str) -- The name of the option.

  • default (Any) -- The default value for the option.

  • exists_ok (bool, optional) -- If True, do not raise OptionExistsError if the option already exists. Default: False.

Returns:

The newly created option or already existing option.

Return type:

Option

Raises:

OptionExistsError -- If the option already exists and exists_ok is set to False.

get_option(name: str) Option#

Get Option object by its name.

Parameters:

name (str) -- The name of the option.

Returns:

The option instance.

Return type:

Option

Raises:

OptionNotFoundError -- If the option does not exist.

remove() None#

Remove this options group.

class ignis.services.options.Option(*args: Any, **kwargs: Any)#

An option object.

Signals:
  • "removed" (): Emitted when the option is removed.

Properties:
  • name (str, read-only): The name of the option.

  • value (Any, read-write): The current value of the option.

remove() None#

Remove this option.