DoubleEdit (hwx.gui)#
- class DoubleEdit(value=0.0, units=None, alignment='right', format=None, **kwds)#
Bases:
LineEditA widget that can display/edit a double.
Method Table# Name
Description
get(self)Gets the value converted to base units.
set(self, value)Sets the value converted to user units with the units label.
validate(self, widget)Validates whether the value entered is a double and convert to base units.
Example
# Start with a simple DoubleEdit, Try entering different values. # Notice only numbers are allowed. Enter something that is not a number # and hit return, the value is not accepted and reset. # # Now lets add a validator. This is a method that get called when the # <Return> key is entered or the DoubleEdit loses focus. # The default validator is what ensures the value is numeric. # Uncomment the validator argument in the DoubleEntry constructor and # rerun the Demo. Now try entering a value outside 0-100. # # Now let's specify that the value has a unit type of 'length' # Uncomment the units argument in the DoubleEntry constructor. # Change type of units in the ComboBox, notice the displayed/entered # value is in user units, but the get/set value is in SI units. # Set the units to FPS, the value is displayed in feet # Enter '2cm', again displayed in feet, but notice the output value shows # .02 because it is in meters from hwx import gui # - callbacks -------------------------------------------------------------- def onInputChanged(): # user entered a new value in the input filed output.text = input.value def onUnitsChanged(): # the units combo box changed input.unitManager.system = units.value output.text = input.value # Demonstrate the input value is really SI def validator(widget): # method called when to validate the contents try: return 0 <= widget.value <= 100 except: return False # - widgets ---------------------------------------------------------------- input = gui.DoubleEdit(2, # format = str, # can be a callable or format string like "%f" # units = 'length', # validator = validator, command=onInputChanged, ) units = gui.ComboBox(values=input.unitManager.getSystemNames(), value=input.unitManager.system, visible=input.units, # only shown when playing with units command=onUnitsChanged, ) output = gui.Label(input.value) frame = gui.VFrame((input, 5, output), 10, units) show(frame)
- validate(widget)#
Validates whether the value entered is a double and convert to base units.
- Parameters:
widget (Widget) – Widget where the value is entered.
- Returns:
True if the widget value entered is an int, otherwise False.
- Return type:
bool
- set(value)#
Sets the value converted to user units with the units label.
- Parameters:
value (str, float) – A float value or a string with the units.
- get()#
Gets the value converted to base units.