Double (hwx.inspire.Attributes)#

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

Bases: Attribute

Store float value with units.

Units can be None, length, mass, force, …

Values are get/set in base units unless under inspire.usingUnits(…).

A value’s units can be specified using a string like: “5 mm”.

Method Table#

Name

Description

castForGet (self, obj, value)

castForSet (self, obj, value)

Converts and validates the double value before setting.

create (self, obj)

Creates a double attribute for the specified object.

getGuiValue (self, obj, format=’modeling’)

getValue (self, obj)

populateGuiValue (self, obj, prop)

setValue (self, obj, value)

Example

from hwx.inspire import *

class Sphere(GeneralObject):
radius  = Double(1,         units='length')
density = Double("2 g/cm3", units='density')

# Computed not serialized
volume = Double(units='volume', fget=lambda self: (4/3) * math.pi * self.radius**3)
mass   = Double(units='mass',   fget=lambda self: self.volume * self.density)

sphere = Sphere()

# By default Doubles with units are get/set in base units (SI)
print('radius in base units (SI):', sphere.radius)

# You can use a different system with usingUnits
with usingUnits("fps"):
print("radius in ft:", sphere.radius)

# Get value as a string in configured gui units
print('radius:',  sphere.radius.guiValue)
print('density:', sphere.density.guiValue)
print('volume:',  sphere.volume.guiValue)
print('mass:',    sphere.mass.guiValue)
create(obj)#

Creates a double attribute for the specified object.

castForSet(obj, value)#

Converts and validates the double value before setting.

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

  • value (str, double) – Value of the attribute to set.

Returns:

Validated and converted value.

Return type:

Double

getValue(obj)#

Returns the attribute value of the specified object.

setValue(obj, value)#

Sets the value for the specified object attribute.

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, format='modeling')#

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

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)

class Value(value, obj, attr)#

Bases: float

Attribute Table#

Name

Type

units

property