.. wxPython Phoenix documentation This file was generated by Phoenix's sphinx generator and associated tools, do not edit by hand. Copyright: (c) 2011-2020 by Total Control Software License: wxWindows License .. include:: headings.inc .. currentmodule:: wx.lib.agw.floatspin .. highlight:: python .. _wx.lib.agw.floatspin.FloatSpin: ========================================================================================================================================== |phoenix_title| **wx.lib.agw.floatspin.FloatSpin** ========================================================================================================================================== :class:`FloatSpin` implements a floating point :class:`SpinCtrl`. It is built using a custom :class:`wx.Control`, composed by a :class:`TextCtrl` and a :class:`SpinButton`. In order to correctly handle floating points numbers without rounding errors or non-exact floating point representations, :class:`FloatSpin` uses the great :class:`FixedPoint` class from Tim Peters. | |class_hierarchy| Class Hierarchy ================================= .. raw:: html
Inheritance diagram for class FloatSpin:
| |appearance| Control Appearance =============================== | .. figure:: _static/images/widgets/fullsize/wxmsw/wx.lib.agw.floatspin.floatspin.png :alt: wxMSW :figclass: floatleft **wxMSW** .. figure:: _static/images/widgets/fullsize/wxmac/../no_appearance.png :alt: wxMAC :figclass: floatright **wxMAC** .. figure:: _static/images/widgets/fullsize/wxgtk/../no_appearance.png :alt: wxGTK :figclass: floatcenter **wxGTK** | |super_classes| Known Superclasses ================================== :class:`wx.Control` | |method_summary| Methods Summary ================================ ================================================================================ ================================================================================ :meth:`~wx.lib.agw.floatspin.FloatSpin.__init__` Default class constructor. :meth:`~wx.lib.agw.floatspin.FloatSpin.ClampValue` Clamps `var` between `_min` and `_max` depending if the range has :meth:`~wx.lib.agw.floatspin.FloatSpin.DoGetBestSize` Gets the size which best suits the window: for a control, it would be the :meth:`~wx.lib.agw.floatspin.FloatSpin.DoSendEvent` Send the event to the parent. :meth:`~wx.lib.agw.floatspin.FloatSpin.GetDefaultValue` Returns the :class:`FloatSpin` default value. :meth:`~wx.lib.agw.floatspin.FloatSpin.GetDigits` Returns the number of digits shown. :meth:`~wx.lib.agw.floatspin.FloatSpin.GetFont` Returns the underlying :class:`TextCtrl` font. :meth:`~wx.lib.agw.floatspin.FloatSpin.GetFormat` Returns the string format in use. :meth:`~wx.lib.agw.floatspin.FloatSpin.GetIncrement` Returns the increment for every ``EVT_FLOATSPIN`` event. :meth:`~wx.lib.agw.floatspin.FloatSpin.GetMax` Returns the maximum value for :class:`FloatSpin`. It can be a :meth:`~wx.lib.agw.floatspin.FloatSpin.GetMin` Returns the minimum value for :class:`FloatSpin`. It can be a :meth:`~wx.lib.agw.floatspin.FloatSpin.GetSnapToTicks` Returns whether the snap to ticks option is active or not. :meth:`~wx.lib.agw.floatspin.FloatSpin.GetTextCtrl` Returns the underlying :class:`TextCtrl`. :meth:`~wx.lib.agw.floatspin.FloatSpin.GetValue` Returns the :class:`FloatSpin` value. :meth:`~wx.lib.agw.floatspin.FloatSpin.HasRange` Returns whether :class:`FloatSpin` range has been set or not. :meth:`~wx.lib.agw.floatspin.FloatSpin.InRange` Returns whether a value is inside :class:`FloatSpin` range. :meth:`~wx.lib.agw.floatspin.FloatSpin.IsDefaultValue` Returns whether the current value is the default value or not. :meth:`~wx.lib.agw.floatspin.FloatSpin.IsFinite` Tries to determine if a value is finite or infinite/NaN. :meth:`~wx.lib.agw.floatspin.FloatSpin.OnChar` Handles the ``wx.EVT_CHAR`` event for :class:`FloatSpin`. :meth:`~wx.lib.agw.floatspin.FloatSpin.OnDestroy` Handles the ``wx.EVT_WINDOW_DESTROY`` event for :class:`FloatSpin`. :meth:`~wx.lib.agw.floatspin.FloatSpin.OnFocus` Handles the ``wx.EVT_SET_FOCUS`` event for :class:`FloatSpin`. :meth:`~wx.lib.agw.floatspin.FloatSpin.OnKillFocus` Handles the ``wx.EVT_KILL_FOCUS`` event for :class:`FloatSpin`. :meth:`~wx.lib.agw.floatspin.FloatSpin.OnMouseWheel` Handles the ``wx.EVT_MOUSEWHEEL`` event for :class:`FloatSpin`. :meth:`~wx.lib.agw.floatspin.FloatSpin.OnSize` Handles the ``wx.EVT_SIZE`` event for :class:`FloatSpin`. :meth:`~wx.lib.agw.floatspin.FloatSpin.OnSpinDown` Handles the ``wx.EVT_SPIN_DOWN`` event for :class:`FloatSpin`. :meth:`~wx.lib.agw.floatspin.FloatSpin.OnSpinMouseDown` Handles the ``wx.EVT_LEFT_DOWN`` event for :class:`FloatSpin`. :meth:`~wx.lib.agw.floatspin.FloatSpin.OnSpinUp` Handles the ``wx.EVT_SPIN_UP`` event for :class:`FloatSpin`. :meth:`~wx.lib.agw.floatspin.FloatSpin.OnTextEnter` Handles the ``wx.EVT_TEXT_ENTER`` event for :class:`FloatSpin`. :meth:`~wx.lib.agw.floatspin.FloatSpin.ReplaceDoubleZero` Replaces the (somewhat) python ugly `+e000` with `+e00`. :meth:`~wx.lib.agw.floatspin.FloatSpin.SetDefaultValue` Sets the :class:`FloatSpin` default value. :meth:`~wx.lib.agw.floatspin.FloatSpin.SetDigits` Sets the number of digits to show. :meth:`~wx.lib.agw.floatspin.FloatSpin.SetFont` Sets the underlying :class:`TextCtrl` font. :meth:`~wx.lib.agw.floatspin.FloatSpin.SetFormat` Set the string format to use. :meth:`~wx.lib.agw.floatspin.FloatSpin.SetIncrement` Sets the increment for every ``EVT_FLOATSPIN`` event. :meth:`~wx.lib.agw.floatspin.FloatSpin.SetMax` Sets the maximum value for :class:`FloatSpin`. :meth:`~wx.lib.agw.floatspin.FloatSpin.SetMin` Sets the minimum value for :class:`FloatSpin`. :meth:`~wx.lib.agw.floatspin.FloatSpin.SetRange` Sets the allowed range. :meth:`~wx.lib.agw.floatspin.FloatSpin.SetRangeDontClampValue` Sets the allowed range. :meth:`~wx.lib.agw.floatspin.FloatSpin.SetSnapToTicks` Force the value to always be divisible by the increment. Initially ``False``. :meth:`~wx.lib.agw.floatspin.FloatSpin.SetToDefaultValue` Sets :class:`FloatSpin` value to its default value. :meth:`~wx.lib.agw.floatspin.FloatSpin.SetValue` Sets the :class:`FloatSpin` value. :meth:`~wx.lib.agw.floatspin.FloatSpin.SyncSpinToText` Synchronize the underlying :class:`TextCtrl` with :class:`SpinButton`. ================================================================================ ================================================================================ | |property_summary| Properties Summary ===================================== ================================================================================ ================================================================================ :attr:`~wx.lib.agw.floatspin.FloatSpin.DefaultValue` Returns the :class:`FloatSpin` default value. :attr:`~wx.lib.agw.floatspin.FloatSpin.Digits` Returns the number of digits shown. :attr:`~wx.lib.agw.floatspin.FloatSpin.Font` Returns the underlying :class:`TextCtrl` font. :attr:`~wx.lib.agw.floatspin.FloatSpin.Format` Returns the string format in use. :attr:`~wx.lib.agw.floatspin.FloatSpin.Increment` Returns the increment for every ``EVT_FLOATSPIN`` event. :attr:`~wx.lib.agw.floatspin.FloatSpin.Max` Returns the maximum value for :class:`FloatSpin`. It can be a :attr:`~wx.lib.agw.floatspin.FloatSpin.Min` Returns the minimum value for :class:`FloatSpin`. It can be a :attr:`~wx.lib.agw.floatspin.FloatSpin.Value` Returns the :class:`FloatSpin` value. ================================================================================ ================================================================================ | |api| Class API =============== .. class:: FloatSpin(wx.Control) :class:`FloatSpin` implements a floating point :class:`SpinCtrl`. It is built using a custom :class:`wx.Control`, composed by a :class:`TextCtrl` and a :class:`SpinButton`. In order to correctly handle floating points numbers without rounding errors or non-exact floating point representations, :class:`FloatSpin` uses the great :class:`FixedPoint` class from Tim Peters. .. method:: __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. :param `parent`: the :class:`FloatSpin` parent; :param `id`: an identifier for the control: a value of -1 is taken to mean a default; :param `pos`: the control position. A value of (-1, -1) indicates a default position, chosen by either the windowing system or wxPython, depending on platform; :param `size`: the control size. A value of (-1, -1) indicates a default size, chosen by either the windowing system or wxPython, depending on platform; :param `style`: the window style; :param `value`: is the current value for :class:`FloatSpin`; :param `min_val`: the minimum value, ignored if ``None``; :param `max_val`: the maximum value, ignored if ``None``; :param `increment`: the increment for every :class:`FloatSpinEvent` event; :param `digits`: number of representative digits for your floating point numbers; :param `agwStyle`: one of the following bits: =============== =========== ================================================== Window Styles Hex Value Description =============== =========== ================================================== ``FS_READONLY`` 0x1 Sets :class:`FloatSpin` as read-only control. ``FS_LEFT`` 0x2 Horizontally align the underlying :class:`TextCtrl` on the left. ``FS_CENTRE`` 0x4 Horizontally align the underlying :class:`TextCtrl` on center. ``FS_RIGHT`` 0x8 Horizontally align the underlying :class:`TextCtrl` on the right. =============== =========== ================================================== :param `name`: the window name. .. method:: ClampValue(self, var) Clamps `var` between `_min` and `_max` depending if the range has been specified. :param `var`: the value to be clamped. :return: A clamped copy of `var`. .. method:: 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 :class:`wx.Control`. .. method:: DoSendEvent(self) Send the event to the parent. .. method:: GetDefaultValue(self) Returns the :class:`FloatSpin` default value. .. method:: GetDigits(self) Returns the number of digits shown. .. method:: GetFont(self) Returns the underlying :class:`TextCtrl` font. .. method:: GetFormat(self) Returns the string format in use. .. seealso:: :meth:`~FloatSpin.SetFormat` for a list of valid string formats. .. method:: GetIncrement(self) Returns the increment for every ``EVT_FLOATSPIN`` event. .. method:: GetMax(self) Returns the maximum value for :class:`FloatSpin`. It can be a number or ``None`` if no minimum is present. .. method:: GetMin(self) Returns the minimum value for :class:`FloatSpin`. It can be a number or ``None`` if no minimum is present. .. method:: GetSnapToTicks(self) Returns whether the snap to ticks option is active or not. .. method:: GetTextCtrl(self) Returns the underlying :class:`TextCtrl`. .. method:: GetValue(self) Returns the :class:`FloatSpin` value. .. method:: HasRange(self) Returns whether :class:`FloatSpin` range has been set or not. .. method:: InRange(self, value) Returns whether a value is inside :class:`FloatSpin` range. :param `value`: the value to test. .. method:: IsDefaultValue(self) Returns whether the current value is the default value or not. .. method:: IsFinite(self, value) Tries to determine if a value is finite or infinite/NaN. :param `value`: the value to test. .. method:: OnChar(self, event) Handles the ``wx.EVT_CHAR`` event for :class:`FloatSpin`. :param `event`: a :class:`KeyEvent` event to be processed. .. note:: This method works on the underlying :class:`TextCtrl`. .. method:: OnDestroy(self, event) Handles the ``wx.EVT_WINDOW_DESTROY`` event for :class:`FloatSpin`. :param `event`: a :class:`wx.WindowDestroyEvent` event to be processed. .. note:: This method tries to correctly handle the control destruction under MSW. .. method:: OnFocus(self, event) Handles the ``wx.EVT_SET_FOCUS`` event for :class:`FloatSpin`. :param `event`: a :class:`FocusEvent` event to be processed. .. method:: OnKillFocus(self, event) Handles the ``wx.EVT_KILL_FOCUS`` event for :class:`FloatSpin`. :param `event`: a :class:`FocusEvent` event to be processed. .. method:: OnMouseWheel(self, event) Handles the ``wx.EVT_MOUSEWHEEL`` event for :class:`FloatSpin`. :param `event`: a :class:`MouseEvent` event to be processed. .. method:: OnSize(self, event) Handles the ``wx.EVT_SIZE`` event for :class:`FloatSpin`. :param `event`: a :class:`wx.SizeEvent` event to be processed. .. note:: This method resizes the text control and reposition the spin button when resized. .. method:: OnSpinDown(self, event) Handles the ``wx.EVT_SPIN_DOWN`` event for :class:`FloatSpin`. :param `event`: a :class:`SpinEvent` event to be processed. .. method:: OnSpinMouseDown(self, event) Handles the ``wx.EVT_LEFT_DOWN`` event for :class:`FloatSpin`. :param `event`: a :class:`MouseEvent` event to be processed. .. note:: This method works on the underlying :class:`SpinButton`. .. method:: OnSpinUp(self, event) Handles the ``wx.EVT_SPIN_UP`` event for :class:`FloatSpin`. :param `event`: a :class:`SpinEvent` event to be processed. .. method:: OnTextEnter(self, event) Handles the ``wx.EVT_TEXT_ENTER`` event for :class:`FloatSpin`. :param `event`: a :class:`KeyEvent` event to be processed. .. note:: This method works on the underlying :class:`TextCtrl`. .. method:: ReplaceDoubleZero(self, strs) Replaces the (somewhat) python ugly `+e000` with `+e00`. :param `strs`: a string (possibly) containing a `+e00` substring. .. method:: SetDefaultValue(self, defaultvalue) Sets the :class:`FloatSpin` default value. :param `defaultvalue`: a floating point value representing the new default value for :class:`FloatSpin`. .. method:: SetDigits(self, digits=-1) Sets the number of digits to show. :param `digits`: the number of digits to show. If `digits` < 0, :class:`FloatSpin` tries to calculate the best number of digits based on input values passed in the constructor. .. method:: SetFont(self, font=None) Sets the underlying :class:`TextCtrl` font. :param `font`: a valid instance of :class:`wx.Font`. .. method:: SetFormat(self, fmt="%f") Set the string format to use. :param `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 ====== ================================= .. method:: SetIncrement(self, increment) Sets the increment for every ``EVT_FLOATSPIN`` event. :param `increment`: a floating point number specifying the :class:`FloatSpin` increment. .. method:: SetMax(self, max_val) Sets the maximum value for :class:`FloatSpin`. :param `max_val`: the maximum value for :class:`FloatSpin`. If it is ``None`` it is ignored. .. note:: This method doesn't modify the current value. .. method:: SetMin(self, min_val) Sets the minimum value for :class:`FloatSpin`. :param `min_val`: the minimum value for :class:`FloatSpin`. If it is ``None`` it is ignored. .. note:: This method doesn't modify the current value. .. method:: SetRange(self, min_val, max_val) Sets the allowed range. :param `min_val`: the minimum value for :class:`FloatSpin`. If it is ``None`` it is ignored; :param `max_val`: the maximum value for :class:`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) .. method:: SetRangeDontClampValue(self, min_val, max_val) Sets the allowed range. :param `min_val`: the minimum value for :class:`FloatSpin`. If it is ``None`` it is ignored; :param `max_val`: the maximum value for :class:`FloatSpin`. If it is ``None`` it is ignored. .. note:: This method doesn't modify the current value. .. method:: SetSnapToTicks(self, forceticks=True) Force the value to always be divisible by the increment. Initially ``False``. :param `forceticks`: ``True`` 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. .. method:: SetToDefaultValue(self) Sets :class:`FloatSpin` value to its default value. .. method:: SetValue(self, value) Sets the :class:`FloatSpin` value. :param `value`: the new value. .. method:: SyncSpinToText(self, send_event=True, force_valid=True) Synchronize the underlying :class:`TextCtrl` with :class:`SpinButton`. :param `send_event`: ``True`` to send a ``EVT_FLOATSPIN`` event, ``False`` otherwise; :param `force_valid`: ``True`` to force a valid value (i.e. inside the provided range), ``False`` otherwise. .. attribute:: DefaultValue Returns the :class:`FloatSpin` default value. .. attribute:: Digits Returns the number of digits shown. .. attribute:: Font Returns the underlying :class:`TextCtrl` font. .. attribute:: Format Returns the string format in use. .. seealso:: :meth:`~FloatSpin.SetFormat` for a list of valid string formats. .. attribute:: Increment Returns the increment for every ``EVT_FLOATSPIN`` event. .. attribute:: Max Returns the maximum value for :class:`FloatSpin`. It can be a number or ``None`` if no minimum is present. .. attribute:: Min Returns the minimum value for :class:`FloatSpin`. It can be a number or ``None`` if no minimum is present. .. attribute:: Value Returns the :class:`FloatSpin` value.