Skip to content

Commit

Permalink
Add utility to extend enums
Browse files Browse the repository at this point in the history
CURA-10720
  • Loading branch information
casperlamboo committed Jul 24, 2023
1 parent 49ba701 commit 7ee6457
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 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 = [] # type: List[SettingDefinition]
self._relations = [] # type: 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,17 @@ 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) -> 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.
"""

value_id = f"{value_id}::{plugin_id}" if plugin_id else value_id
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 7ee6457

Please sign in to comment.