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.

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)
property groups: list[OptionsGroup]#
  • read-only

A list of all options groups.

property data: dict[str, Any]#
  • read-only

The dictionary containing all options and their values from all groups.

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, default: False) -- 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(name: str, data: dict[str, Any] | None = None)#

An options group.

Warning

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

changed()#
  • Signal

Emitted when options in this group is changed.

removed()#
  • Signal

Emitted when this options group is removed.

property name: str#
  • read-only

The name of the group.

property 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, default: False) -- 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.

Return type:

None

class ignis.services.options.Option(name: str, value: Any = None)#

An option object.

removed()#
  • Signal

Emitted when the option is removed.

property name: str#
  • read-only

The name of the option.

property value: Any#
  • read-write

The current value of the option.

remove() None#

Remove this option.

Return type:

None