Enum (hwx.inspire.Attributes)#
- class Enum(values, default=0, doc='', **kwds)#
Bases:
AttributeStore a string with a predefined list of allowed values and labels
Method Table# Name
Description
castForGet(self, obj, value)castForSet(self, obj, value)create(self, obj)Creates an enum attribute for the specified object.
getDisplayNames(self, obj)getGuiValue(self, obj)getValue(self, obj)getValueFromDisplayName(self, obj, displayName)getValues(self, obj)getValuesAndDisplayNames(self, obj, valuesOnly=False)loadValue(self, obj, value)populateGuiValue(self, obj, prop)raiseValueError(self, values, value)splitValues(options)Splits the specified options into values and displayNames.
Example
from hwx.inspire import * class Joint(GeneralObject): type = Enum([ # value, label ("CYLINDRICAL", "Cylindrical"), ("PLANAR", "Planar"), ("REVOLUTE", "Revolute"), ("SPHERICAL", "Spherical"), ]) joint = Joint() print("Default type", joint.type) joint.type = "REVOLUTE" print(joint.type, "'s display value is", joint.type.guiValue) try: joint.type = "INVALID VALUE" except AttributeValueError as error: print(error)
- create(obj)#
Creates an enum attribute for the specified object.
- castForSet(obj, value)#
Converts and validates the value of the attribute before setting.
Converts the value it to its internal type (and base units if applicable).
- Parameters:
obj (GeneralObject) – Object this attribute belongs to.
value (Any) – Value of the attribute to set.
- Returns:
Validated and converted value.
- Return type:
value (Any)
- castForGet(obj, value)#
Converts and returns the attribute value to its external type.
- Parameters:
obj (GeneralObject) – Object this attribute belongs to.
value (Any) – Value of the attribute to be converted.
- Returns:
Converted value.
- Return type:
value (Any)
- loadValue(obj, value)#
Called by GeneralObject.loadAttributeValues during stmod deserialization
- populateGuiValue(obj, prop)#
Override to customize, prop.value, displayValue, allowedValues.
The prop.value type determines which editor widget used: - bool -> checkbox - str -> line edit - hwtypes.Color -> color picker
Setting prop.allowedValues yields a ComboBox.
prop.displayValue is a str shown when the editor loses focus.
- getGuiValue(obj)#
Returns the formatted value, as shown in the Property Editor.