AGW Logo

agw_title FloatSpin

FloatSpin implements a floating point wx.SpinCtrl. It is built using a custom wx.PyControl, composed by a wx.TextCtrl and a wx.SpinButton. In order to correctly handle floating points numbers without rounding errors or non-exact floating point representations, FloatSpin uses the great FixedPoint class from Tim Peters.

hierarchy Inheritance Diagram

Inheritance diagram for: FloatSpin

Inheritance diagram of FloatSpin


appearance Control Appearance


FloatSpin

FloatSpin


method_summary Methods Summary

__init__Default class constructor.
ClampValueClamps var between _min and _max depending if the range has been specified.
DoGetBestSizeGets the size which best suits the window: for a control, it would be the
DoSendEventSend the event to the parent.
GetDefaultValueReturns the FloatSpin default value.
GetDigitsReturns the number of digits shown.
GetFontReturns the underlying wx.TextCtrl font.
GetFormatReturns the string format in use.
GetIncrementReturns the increment for every EVT_FLOATSPIN event.
GetMaxReturns the maximum value for FloatSpin. It can be a
GetMinReturns the minimum value for FloatSpin. It can be a
GetSnapToTicksReturns whether the snap to ticks option is active or not.
GetTextCtrlReturns the underlying wx.TextCtrl.
GetValueReturns the FloatSpin value.
HasRangeReturns whether FloatSpin range has been set or not.
InRangeReturns whether a value is inside FloatSpin range.
IsDefaultValueReturns whether the current value is the default value or not.
IsFiniteTries to determine if a value is finite or infinite/NaN.
OnCharHandles the wx.EVT_CHAR event for FloatSpin.
OnDestroyHandles the wx.EVT_WINDOW_DESTROY event for FloatSpin.
OnFocusHandles the wx.EVT_SET_FOCUS event for FloatSpin.
OnKillFocusHandles the wx.EVT_KILL_FOCUS event for FloatSpin.
OnMouseWheelHandles the wx.EVT_MOUSEWHEEL event for FloatSpin.
OnSizeHandles the wx.EVT_SIZE event for FloatSpin.
OnSpinDownHandles the wx.EVT_SPIN_DOWN event for FloatSpin.
OnSpinMouseDownHandles the wx.EVT_LEFT_DOWN event for FloatSpin.
OnSpinUpHandles the wx.EVT_SPIN_UP event for FloatSpin.
OnTextEnterHandles the wx.EVT_TEXT_ENTER event for FloatSpin.
ReplaceDoubleZeroReplaces the (somewhat) python ugly +e000 with +e00.
SetDefaultValueSets the FloatSpin default value.
SetDigitsSets the number of digits to show.
SetFontSets the underlying wx.TextCtrl font.
SetFormatSet the string format to use.
SetIncrementSets the increment for every EVT_FLOATSPIN event.
SetRangeSets the allowed range.
SetRangeDontClampValueSets the allowed range.
SetSnapToTicksForce the value to always be divisible by the increment.
SetToDefaultValueSets FloatSpin value to its default value.
SetValueSets the FloatSpin value.
SyncSpinToTextSynchronize the underlying wx.TextCtrl with wx.SpinButton.

API Class API

class FloatSpin(wx.PyControl)[source]

FloatSpin implements a floating point wx.SpinCtrl. It is built using a custom wx.PyControl, composed by a wx.TextCtrl and a wx.SpinButton. In order to correctly handle floating points numbers without rounding errors or non-exact floating point representations, FloatSpin uses the great FixedPoint class from Tim Peters.



__init__(parent, id=wx.ID_ANY, pos=wx.DefaultPosition, size=(95, -1), style=0, value=0.0, min_val=None, max_val=None, increment=1.0, digits=-1, agwStyle=FS_LEFT, name="FloatSpin")[source]

Default class constructor.

Parameters:
  • parent – the FloatSpin parent;
  • id – an identifier for the control: a value of -1 is taken to mean a default;
  • pos – the control position. A value of (-1, -1) indicates a default position, chosen by either the windowing system or wxPython, depending on platform;
  • size – the control size. A value of (-1, -1) indicates a default size, chosen by either the windowing system or wxPython, depending on platform;
  • style – the window style;
  • value – is the current value for FloatSpin;
  • min_val – the minimum value, ignored if None;
  • max_val – the maximum value, ignored if None;
  • increment – the increment for every FloatSpinEvent event;
  • digits – number of representative digits for your floating point numbers;
  • agwStyle – one of the following bits:


    Window Styles Hex Value Description
    FS_READONLY 0x1 Sets FloatSpin as read-only control.
    FS_LEFT 0x2 Horizontally align the underlying wx.TextCtrl on the left.
    FS_CENTRE 0x4 Horizontally align the underlying wx.TextCtrl on center.
    FS_RIGHT 0x8 Horizontally align the underlying wx.TextCtrl on the right.
  • name – the window name.


ClampValue(var)[source]

Clamps var between _min and _max depending if the range has been specified.

Parameters:var – the value to be clamped.
Returns:A clamped copy of var.


DoGetBestSize()[source]

Gets the size which best suits the window: for a control, it would be the minimal size which doesn’t truncate the control, for a panel - the same size as it would have after a call to Fit().

Note

Overridden from wx.PyControl.



DoSendEvent()[source]

Send the event to the parent.



GetDefaultValue()[source]

Returns the FloatSpin default value.



GetDigits()[source]

Returns the number of digits shown.



GetFont()[source]

Returns the underlying wx.TextCtrl font.



GetFormat()[source]

Returns the string format in use.

See also

SetFormat for a list of valid string formats.



GetIncrement()[source]

Returns the increment for every EVT_FLOATSPIN event.



GetMax()[source]

Returns the maximum value for FloatSpin. It can be a number or None if no minimum is present.



GetMin()[source]

Returns the minimum value for FloatSpin. It can be a number or None if no minimum is present.



GetSnapToTicks()[source]

Returns whether the snap to ticks option is active or not.



GetTextCtrl()[source]

Returns the underlying wx.TextCtrl.



GetValue()[source]

Returns the FloatSpin value.



HasRange()[source]

Returns whether FloatSpin range has been set or not.



InRange(value)[source]

Returns whether a value is inside FloatSpin range.

Parameters:value – the value to test.


IsDefaultValue()[source]

Returns whether the current value is the default value or not.



IsFinite(value)[source]

Tries to determine if a value is finite or infinite/NaN.

Parameters:value – the value to test.


OnChar(event)[source]

Handles the wx.EVT_CHAR event for FloatSpin.

Parameters:event – a wx.KeyEvent event to be processed.

Note

This method works on the underlying wx.TextCtrl.



OnDestroy(event)[source]

Handles the wx.EVT_WINDOW_DESTROY event for FloatSpin.

Parameters:event – a wx.WindowDestroyEvent event to be processed.

Note

This method tries to correctly handle the control destruction under MSW.



OnFocus(event)[source]

Handles the wx.EVT_SET_FOCUS event for FloatSpin.

Parameters:event – a wx.FocusEvent event to be processed.


OnKillFocus(event)[source]

Handles the wx.EVT_KILL_FOCUS event for FloatSpin.

Parameters:event – a wx.FocusEvent event to be processed.



OnMouseWheel(event)[source]

Handles the wx.EVT_MOUSEWHEEL event for FloatSpin.

Parameters:event – a wx.MouseEvent event to be processed.


OnSize(event)[source]

Handles the wx.EVT_SIZE event for FloatSpin.

Parameters:event – a wx.SizeEvent event to be processed.

Note

This method resizes the text control and reposition the spin button when resized.



OnSpinDown(event)[source]

Handles the wx.EVT_SPIN_DOWN event for FloatSpin.

Parameters:event – a wx.SpinEvent event to be processed.


OnSpinMouseDown(event)[source]

Handles the wx.EVT_LEFT_DOWN event for FloatSpin.

Parameters:event – a wx.MouseEvent event to be processed.

Note

This method works on the underlying wx.SpinButton.



OnSpinUp(event)[source]

Handles the wx.EVT_SPIN_UP event for FloatSpin.

Parameters:event – a wx.SpinEvent event to be processed.



OnTextEnter(event)[source]

Handles the wx.EVT_TEXT_ENTER event for FloatSpin.

Parameters:event – a wx.KeyEvent event to be processed.

Note

This method works on the underlying wx.TextCtrl.



ReplaceDoubleZero(strs)[source]

Replaces the (somewhat) python ugly +e000 with +e00.

Parameters:strs – a string (possibly) containing a +e00 substring.


SetDefaultValue(defaultvalue)[source]

Sets the FloatSpin default value.

Parameters:defaultvalue – a floating point value representing the new default value for FloatSpin.


SetDigits(digits=-1)[source]

Sets the number of digits to show.

Parameters:digits – the number of digits to show. If digits < 0, FloatSpin tries to calculate the best number of digits based on input values passed in the constructor.


SetFont(font=None)[source]

Sets the underlying wx.TextCtrl font.

Parameters:font – a valid instance of wx.Font.


SetFormat(fmt='%f')[source]

Set the string format to use.

Parameters:fmt – the new string format to use. One of the following strings:


Format Description
‘e’ Floating point exponential format (lowercase)
‘E’ Floating point exponential format (uppercase)
‘f’ Floating point decimal format
‘F’ Floating point decimal format
‘g’ Floating point format. Uses lowercase exponential format if exponent is less than -4 or not less than precision, decimal format otherwise
‘G’ Floating point format. Uses uppercase exponential format if exponent is less than -4 or not less than precision, decimal format otherwise


SetIncrement(increment)[source]

Sets the increment for every EVT_FLOATSPIN event.

Parameters:increment – a floating point number specifying the FloatSpin increment.


SetRange(min_val, max_val)[source]

Sets the allowed range.

Parameters:
  • min_val – the minimum value for FloatSpin. If it is None it is ignored;
  • max_val – the maximum value for FloatSpin. If it is None it is ignored.

Note

This method doesn’t modify the current value.

Note

You specify open ranges like this (you can equally do this in the constructor):

SetRange(min_val=1, max_val=None)
SetRange(min_val=None, max_val=0)

or no range:

SetRange(min_val=None, max_val=None)


SetRangeDontClampValue(min_val, max_val)[source]

Sets the allowed range.

Parameters:
  • min_val – the minimum value for FloatSpin. If it is None it is ignored;
  • max_val – the maximum value for FloatSpin. If it is None it is ignored.

Note

This method doesn’t modify the current value.



SetSnapToTicks(forceticks=True)[source]

Force the value to always be divisible by the increment. Initially False.

Parameters:forceticksTrue to force the snap to ticks option, False otherwise.

Note

This uses the default value as the basis, you will get strange results for very large differences between the current value and default value when the increment is very small.



SetToDefaultValue()[source]

Sets FloatSpin value to its default value.



SetValue(value)[source]

Sets the FloatSpin value.

Parameters:value – the new value.


SyncSpinToText(send_event=True, force_valid=True)[source]

Synchronize the underlying wx.TextCtrl with wx.SpinButton.

Parameters:
  • send_eventTrue to send a EVT_FLOATSPIN event, False otherwise;
  • force_validTrue to force a valid value (i.e. inside the provided range), False otherwise.
Tree

Table Of Contents

Previous topic

FixedPoint

Next topic

FloatSpinEvent