wx.lib.agw.floatspin.FloatSpin¶
FloatSpin implements a floating point SpinCtrl. It is built using a custom
wx.Control, composed by a TextCtrl and a 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.
Class Hierarchy¶
Control Appearance¶
Known Superclasses¶
Methods Summary¶
Default class constructor. |
|
Clamps var between _min and _max depending if the range has |
|
Gets the size which best suits the window: for a control, it would be the |
|
Send the event to the parent. |
|
Returns the |
|
Returns the number of digits shown. |
|
Returns the underlying |
|
Returns the string format in use. |
|
Returns the increment for every |
|
Returns the maximum value for |
|
Returns the minimum value for |
|
Returns whether the snap to ticks option is active or not. |
|
Returns the underlying |
|
Returns the |
|
Returns whether |
|
Returns whether a value is inside |
|
Returns whether the current value is the default value or not. |
|
Tries to determine if a value is finite or infinite/NaN. |
|
Handles the |
|
Handles the |
|
Handles the |
|
Handles the |
|
Handles the |
|
Handles the |
|
Handles the |
|
Handles the |
|
Handles the |
|
Handles the |
|
Replaces the (somewhat) python ugly +e000 with +e00. |
|
Sets the |
|
Sets the number of digits to show. |
|
Sets the underlying |
|
Set the string format to use. |
|
Sets the increment for every |
|
Sets the maximum value for |
|
Sets the minimum value for |
|
Sets the allowed range. |
|
Sets the allowed range. |
|
Force the value to always be divisible by the increment. Initially |
|
Sets |
|
Sets the |
|
Synchronize the underlying |
Properties Summary¶
Returns the |
|
Returns the number of digits shown. |
|
Returns the underlying |
|
Returns the string format in use. |
|
Returns the increment for every |
|
Returns the maximum value for |
|
Returns the minimum value for |
|
Returns the |
Class API¶
- class FloatSpin(wx.Control)¶
FloatSpinimplements a floating pointSpinCtrl. It is built using a customwx.Control, composed by aTextCtrland aSpinButton. In order to correctly handle floating points numbers without rounding errors or non-exact floating point representations,FloatSpinuses the greatFixedPointclass from Tim Peters.
Methods¶
- __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0, value=0.0, min_val=None, max_val=None, increment=1.0, digits=-1, agwStyle=FS_LEFT, name='FloatSpin')¶
Default class constructor.
- Parameters:
parent – the
FloatSpinparent;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
FloatSpinEventevent;digits – number of representative digits for your floating point numbers;
agwStyle – one of the following bits:
Window Styles
Hex Value
Description
FS_READONLY0x1
Sets
FloatSpinas read-only control.FS_LEFT0x2
Horizontally align the underlying
TextCtrlon the left.FS_CENTRE0x4
Horizontally align the underlying
TextCtrlon center.FS_RIGHT0x8
Horizontally align the underlying
TextCtrlon the right.name – the window name.
- ClampValue(self, var)¶
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(self)¶
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.Control.
- DoSendEvent(self)¶
Send the event to the parent.
- GetDigits(self)¶
Returns the number of digits shown.
- GetFont(self)¶
Returns the underlying
TextCtrlfont.
- GetFormat(self)¶
Returns the string format in use.
See also
SetFormatfor a list of valid string formats.
- GetIncrement(self)¶
Returns the increment for every
EVT_FLOATSPINevent.
- GetMax(self)¶
Returns the maximum value for
FloatSpin. It can be a number orNoneif no minimum is present.
- GetMin(self)¶
Returns the minimum value for
FloatSpin. It can be a number orNoneif no minimum is present.
- GetSnapToTicks(self)¶
Returns whether the snap to ticks option is active or not.
- GetTextCtrl(self)¶
Returns the underlying
TextCtrl.
- InRange(self, value)¶
Returns whether a value is inside
FloatSpinrange.- Parameters:
value – the value to test.
- IsDefaultValue(self)¶
Returns whether the current value is the default value or not.
- IsFinite(self, value)¶
Tries to determine if a value is finite or infinite/NaN.
- Parameters:
value – the value to test.
- OnChar(self, event)¶
Handles the
wx.EVT_CHARevent forFloatSpin.- Parameters:
event – a
KeyEventevent to be processed.
Note
This method works on the underlying
TextCtrl.
- OnDestroy(self, event)¶
Handles the
wx.EVT_WINDOW_DESTROYevent forFloatSpin.- Parameters:
event – a
wx.WindowDestroyEventevent to be processed.
Note
This method tries to correctly handle the control destruction under MSW.
- OnFocus(self, event)¶
Handles the
wx.EVT_SET_FOCUSevent forFloatSpin.- Parameters:
event – a
FocusEventevent to be processed.
- OnKillFocus(self, event)¶
Handles the
wx.EVT_KILL_FOCUSevent forFloatSpin.- Parameters:
event – a
FocusEventevent to be processed.
- OnMouseWheel(self, event)¶
Handles the
wx.EVT_MOUSEWHEELevent forFloatSpin.- Parameters:
event – a
MouseEventevent to be processed.
- OnSize(self, event)¶
Handles the
wx.EVT_SIZEevent forFloatSpin.- Parameters:
event – a
wx.SizeEventevent to be processed.
Note
This method resizes the text control and reposition the spin button when resized.
- OnSpinDown(self, event)¶
Handles the
wx.EVT_SPIN_DOWNevent forFloatSpin.- Parameters:
event – a
SpinEventevent to be processed.
- OnSpinMouseDown(self, event)¶
Handles the
wx.EVT_LEFT_DOWNevent forFloatSpin.- Parameters:
event – a
MouseEventevent to be processed.
Note
This method works on the underlying
SpinButton.
- OnSpinUp(self, event)¶
Handles the
wx.EVT_SPIN_UPevent forFloatSpin.- Parameters:
event – a
SpinEventevent to be processed.
- OnTextEnter(self, event)¶
Handles the
wx.EVT_TEXT_ENTERevent forFloatSpin.- Parameters:
event – a
KeyEventevent to be processed.
Note
This method works on the underlying
TextCtrl.
- ReplaceDoubleZero(self, strs)¶
Replaces the (somewhat) python ugly +e000 with +e00.
- Parameters:
strs – a string (possibly) containing a +e00 substring.
- SetDefaultValue(self, defaultvalue)¶
Sets the
FloatSpindefault value.- Parameters:
defaultvalue – a floating point value representing the new default value for
FloatSpin.
- SetDigits(self, digits=-1)¶
Sets the number of digits to show.
- Parameters:
digits – the number of digits to show. If digits < 0,
FloatSpintries to calculate the best number of digits based on input values passed in the constructor.
- SetFont(self, font=None)¶
Sets the underlying
TextCtrlfont.- Parameters:
font – a valid instance of
wx.Font.
- SetFormat(self, fmt='%f')¶
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(self, increment)¶
Sets the increment for every
EVT_FLOATSPINevent.- Parameters:
increment – a floating point number specifying the
FloatSpinincrement.
- SetMax(self, max_val)¶
Sets the maximum value for
FloatSpin.- Parameters:
max_val – the maximum value for
FloatSpin. If it isNoneit is ignored.
Note
This method doesn’t modify the current value.
- SetMin(self, min_val)¶
Sets the minimum value for
FloatSpin.- Parameters:
min_val – the minimum value for
FloatSpin. If it isNoneit is ignored.
Note
This method doesn’t modify the current value.
- SetRange(self, min_val, max_val)¶
Sets the allowed range.
- Parameters:
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(self, min_val, max_val)¶
Sets the allowed range.
- Parameters:
Note
This method doesn’t modify the current value.
- SetSnapToTicks(self, forceticks=True)¶
Force the value to always be divisible by the increment. Initially
False.- Parameters:
forceticks –
Trueto force the snap to ticks option,Falseotherwise.
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.
- SyncSpinToText(self, send_event=True, force_valid=True)¶
Synchronize the underlying
TextCtrlwithSpinButton.- Parameters:
send_event –
Trueto send aEVT_FLOATSPINevent,Falseotherwise;force_valid –
Trueto force a valid value (i.e. inside the provided range),Falseotherwise.
Properties¶
- Digits¶
Returns the number of digits shown.
- Font¶
Returns the underlying
TextCtrlfont.
- Increment¶
Returns the increment for every
EVT_FLOATSPINevent.