Skip to content

Commit

Permalink
Merge pull request #888 from Ultimaker/CURA-10720_handle_enum_extensions
Browse files Browse the repository at this point in the history
Add utility to extend enums
  • Loading branch information
jellespijker authored Jul 26, 2023
2 parents d77f1ef + bcf8a24 commit 6a8c6c0
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions UM/Settings/SettingDefinition.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def __init__(self, key: str, container: Optional[DefinitionContainerInterface] =

self._i18n_catalog = i18n_catalog # type: Optional[i18nCatalog]

self._children = [] # type: List[SettingDefinition]
self._relations = [] # type: List[SettingRelation]
self._children: List[SettingDefinition] = []
self._relations: List[SettingRelation] = []

# Cached set of keys of ancestors. Used for fast lookups of ancestors.
self.__ancestors = set() # type: Set[str]
Expand All @@ -116,6 +116,21 @@ def __init__(self, key: str, container: Optional[DefinitionContainerInterface] =

self.__property_values = {} # type: Dict[str, Any]

def extend_category(self, value_id: str, value_display: str, plugin_id: Optional[str] = None,
plugin_version: Optional[str] = None) -> None:
"""Append a category to the setting.
:param value_id: :type{str} The id of the category.
:param value_display: :type{str} The display name of the category. If the display string needs to be translated, provide the translated string.
:param plugin_id: :type{Optional[str]} The id of the plugin that owns the category. Defaults to None.
:param plugin_version: :type{Optional[str]} The version of the plugin that owns the category. Defaults to None.
"""
if plugin_id is not None and plugin_version is not None:
value_id = f"PLUGIN::{plugin_id}@{plugin_version}::{value_id}"
elif plugin_id is not None or plugin_version is not None:
raise ValueError("Both plugin_id and plugin_version must be provided if one of them is provided.")
self.options[value_id] = value_display

def __getattr__(self, name: str) -> Any:
"""Override __getattr__ to provide access to definition properties."""

Expand Down

0 comments on commit 6a8c6c0

Please sign in to comment.