libretro.drivers.options.dict¶
OptionDriver implementation backed by a Mapping of values.
See also
OptionDriverThe protocol this implementation satisfies.
Classes
An |
- class DictOptionDriver[source]¶
Bases:
OptionDriverAn
OptionDriverbacked by an in-memorydictof option values.Supports all three core-options interface versions (v0, v1, v2) so the same harness can drive cores written against any of them.
See also
OptionDriverThe protocol this class implements.
- __init__(version=2, categories_supported=None, variables=None)[source]¶
Initialize the driver with a chosen interface version and seed values.
- Parameters:
version (
int) – The core-options interface version to advertise (0,1, or2).categories_supported (
bool|None) – Whether to advertise category support. Defaults toTruefor v2 andFalseotherwise.variables (
Mapping[str,str] |Mapping[bytes,bytes] |None) – Initial option values, keyed by option key. String keys and values are encoded as UTF-8.
- Raises:
ValueError – If
versionis not0,1, or2.
- get_variable(key)[source]¶
Return the current value of a single core option.
Corresponds to
RETRO_ENVIRONMENT_GET_VARIABLE.
- set_variables(variables)[source]¶
Register the v0 core option variables advertised by the core.
Corresponds to
RETRO_ENVIRONMENT_SET_VARIABLES.- Parameters:
variables (
Collection[retro_variable] |None) – The variables registered by the core, orNoneto clear the registration.
- property variable_updated¶
Whether any core option has been changed since the core last queried it.
Corresponds to
RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE. Reading this property is expected to clear the flag.
- property version¶
The core options interface version this driver implements.
Corresponds to
RETRO_ENVIRONMENT_GET_CORE_OPTIONS_VERSION.
- set_options(options)[source]¶
Register the v1 core option definitions advertised by the core.
Corresponds to
RETRO_ENVIRONMENT_SET_CORE_OPTIONS.- Parameters:
options (
Collection[retro_core_option_definition] |None) – The options registered by the core, orNoneto clear the registration.
- set_options_intl(options)[source]¶
Register the v1 core option definitions, with translations, advertised by the core.
Corresponds to
RETRO_ENVIRONMENT_SET_CORE_OPTIONS_INTL.- Parameters:
options (
retro_core_options_intl|None) – The options registered by the core, orNoneto clear the registration.
- set_display(key, visible)[source]¶
Show or hide a single core option in the frontend’s UI.
Corresponds to
RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY.
- set_options_v2(options)[source]¶
Register the v2 core option definitions advertised by the core.
Corresponds to
RETRO_ENVIRONMENT_SET_CORE_OPTIONS_V2.- Parameters:
options (
retro_core_options_v2|None) – The options registered by the core, orNoneto clear the registration.
- set_options_v2_intl(options)[source]¶
Register the v2 core option definitions, with translations, advertised by the core.
Corresponds to
RETRO_ENVIRONMENT_SET_CORE_OPTIONS_V2_INTL.- Parameters:
options (
retro_core_options_v2_intl|None) – The options registered by the core, orNoneto clear the registration.
- property update_display_callback¶
The display-update callback registered by the core, if any.
Set via
RETRO_ENVIRONMENT_SET_CORE_OPTIONS_UPDATE_DISPLAY_CALLBACK.Noneif the core has not registered one.- Parameters:
callback – The callback to register, or
Noneto clear it.- Raises:
UnsupportedEnvCall – If this driver does not support the display-update callback.
- set_variable(var, value)[source]¶
Set a single core option’s value.
Corresponds to
RETRO_ENVIRONMENT_SET_VARIABLE.
- property supports_categories¶
Whether this driver groups core options into categories (v2 feature).
- class VariableMapping[source]¶
Bases:
MutableMapping[bytes,bytes]Doesn’t fully implement MutableMapping since the semantics aren’t exactly the same as a normal dict (e.g. setting an invalid value doesn’t actually set it), but core options can be mutated with __setitem__ and __delitem__.
- __init__(options)[source]¶
Initialize the mapping with a back-reference to its owning driver.
- Parameters:
options (
DictOptionDriver) – TheDictOptionDriverthis mapping reads from and writes to.
- self[key][source]¶
Get the value of an option variable by key, or its default value if it hasn’t been set yet.
- self[key] = value[source]¶
Set the value of an option variable by key.
- Parameters:
Values that haven’t been registered can be set, but will only be exposed to the core if it registers an option with that key and value later on.
- del self[key][source]¶
Delete an option variable by key; future attempts to get this variable will return its default value until it’s set again. If the option isn’t set, this does nothing.
- key in self¶
- classmethod __new__(*args, **kwargs)¶
- clear() None. Remove all items from D.¶
- get(k[, d]) D[k] if k in D, else d. d defaults to None.¶
- items() a set-like object providing a view on D's items¶
- keys() a set-like object providing a view on D's keys¶
- pop(k[, d]) v, remove specified key and return the corresponding value.¶
If key is not found, d is returned if given, otherwise KeyError is raised.
- popitem() (k, v), remove and return some (key, value) pair¶
as a 2-tuple; but raise KeyError if D is empty.
- setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D¶
- update([E, ]**F) None. Update D from mapping/iterable E and F.¶
If E present and has a .keys() method, does: for k in E.keys(): D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
- values() an object providing a view on D's values¶
- property variables¶
A live, mutable mapping of option keys to current values.
Mutating the returned mapping changes the driver’s stored option values and is the primary way to drive option changes from a Python test harness.
- class VisibilityMapping[source]¶
-
A read-only
Mappingof option key to visibility flag.Used by
DictOptionDriver.visibilityto expose per-option visibility decisions to test code.- key in self¶
- classmethod __new__(*args, **kwargs)¶
- get(k[, d]) D[k] if k in D, else d. d defaults to None.¶
- items() a set-like object providing a view on D's items¶
- keys() a set-like object providing a view on D's keys¶
- values() an object providing a view on D's values¶
- __init__(options)[source]¶
Initialize the mapping with a back-reference to its owning driver.
- Parameters:
options (
DictOptionDriver) – TheDictOptionDriverthis mapping reads from.
- classmethod __new__(*args, **kwargs)¶
- property visibility¶
A mapping of option keys to whether the frontend would show that option.