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”.
# Name
Description
castForSet
(self, obj, value)create
(self, obj)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)#
bool(x) -> bool
Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.
- 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)
- 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.