Enum (hwx.inspire.Attributes)#

class Enum(values, default=0, doc='', **kwds)#

Bases: Attribute

Store a string with a predefined list of allowed values and labels

Method Table#

Name

Description

castForGet (self, obj, value)

castForSet (self, obj, value)

Converts and validates the enum values before setting.

create (self, obj)

Creates an enum attribute for the specified object.

getDisplayNames (self, obj)

Returns the display name.

getGuiValue (self, obj)

Returns the formatted value, as shown in the Property Editor.

getValue (self, obj)

getValueFromDisplayName (self, obj, displayName)

Returns the value from the specified display name and object.

getValues (self, obj)

Returns the enum values.

getValuesAndDisplayNames (self, obj, valuesOnly=False)

Returns all the enum value and the display names for it.

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 enum values before setting.

Parameters:
  • obj (GeneralObject) – Object this attribute belongs to.

  • value (list[str]) – Value of the attribute to set.

Returns:

Validated and converted value.

Return type:

Enum

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)#

Loads and sets the value, when a model is loaded.

getValue(obj)#

Returns the attribute value of the specified object.

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.

getValuesAndDisplayNames(obj, valuesOnly=False)#

Returns all the enum value and the display names for it.

getValues(obj)#

Returns the enum values.

getDisplayNames(obj)#

Returns the display name.

getValueFromDisplayName(obj, displayName)#

Returns the value from the specified display name and object.

class Value(value, obj, attr)#

Bases: str

Attribute Table#

Name

Type

displayNames

property

values

property