Python: captionbob.render
captionbob.render.settings_values
The settings of an effect or a plugin as JSON values.
A settings class of captionbob is a frozen dataclass whose every setting has a default. The command line lists each setting with its JSON type and its default, and it builds a settings object from the JSON values that a user changed. A tuple is a JSON list, and a named tuple, such as a keyword look, is a JSON object. A JSON value must have the type of the default. A whole number is taken for a setting whose default is a float. The settings class checks its own values when it is built.
Source file: captionbob/render/settings_values.py
json_type
def json_type(value: Any) -> str
Give the JSON type of a settings value.
Args:
value: A default of a settings class.
Returns:
BOOLEAN, INTEGER, NUMBER, STRING, LIST or OBJECT.
Raises:
TypeError: When the value has no JSON form.
json_value
def json_value(value: Any) -> Any
Give a settings value as a JSON value.
Args:
value: A value of a settings object.
Returns:
The same value for a bool, a number or a text, a list for a tuple and an object for a named tuple, with the same change inside.
Raises:
TypeError: When the value has no JSON form.
settings_fields
def settings_fields(settings_class: type) -> list[dict[str, Any]]
Give each setting of a settings class with its type and default.
Args:
settings_class: The frozen settings dataclass of an effect or a plugin.
Returns:
One JSON object for each setting, in the order of the class, with the keys NAME_KEY, TYPE_KEY and DEFAULT_KEY.
Raises:
TypeError: When the class is not a dataclass, or when a default has no JSON form.ValueError: When a setting has no default.
settings_from_json
def settings_from_json(settings_class: type, values: Any) -> Any
Build a settings object from the JSON values that a user changed.
Args:
settings_class: The frozen settings dataclass of an effect or a plugin.values: A JSON object with the changed settings by name. A setting that is not in it keeps its default.
Returns:
The settings object.
Raises:
TypeError: When the values are not an object, or when a value does not have the type of its default.ValueError: When a setting is not known, or when the settings class refuses a value.