X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/339983ff62d8d8e2cd4137dd61c46553d459cedc..db679b8c836e69c111cdc31e62cf92cebe4f938f:/wxPython/wx/lib/masked/numctrl.py diff --git a/wxPython/wx/lib/masked/numctrl.py b/wxPython/wx/lib/masked/numctrl.py index cfb64b22a2..e48eacd7b7 100644 --- a/wxPython/wx/lib/masked/numctrl.py +++ b/wxPython/wx/lib/masked/numctrl.py @@ -44,61 +44,61 @@ # o wxMaskedNumCtrl -> masked.NumCtrl # -""" -

-masked.NumCtrl: -

-

-Being derived from MaskedTextCtrl, the control only allows -fixed-point notation. That is, it has a fixed (though reconfigurable) -maximum width for the integer portion and optional fixed width -fractional portion. -

-Here's the API: -

-    masked.NumCtrl(
-         parent, id = -1,
-         value = 0,
-         pos = wx.DefaultPosition,
-         size = wx.DefaultSize,
-         style = 0,
-         validator = wx.DefaultValidator,
-         name = "masked.number",
-         integerWidth = 10,
-         fractionWidth = 0,
-         allowNone = False,
-         allowNegative = True,
-         useParensForNegatives = False,
-         groupDigits = False,
-         groupChar = ',',
-         decimalChar = '.',
-         min = None,
-         max = None,
-         limited = False,
-         selectOnEntry = True,
-         foregroundColour = "Black",
-         signedForegroundColour = "Red",
-         emptyBackgroundColour = "White",
-         validBackgroundColour = "White",
-         invalidBackgroundColour = "Yellow",
-         autoSize = True
-         )
-
- -
-
-
masked.EVT_NUM(win, id, func) -
Respond to a EVT_COMMAND_MASKED_NUMBER_UPDATED event, generated when -the value changes. Notice that this event will always be sent when the -control's contents changes - whether this is due to user input or -comes from the program itself (for example, if SetValue() is called.) -
-
-
SetValue(int|long|float|string) -
Sets the value of the control to the value specified, if -possible. The resulting actual value of the control may be -altered to conform to the format of the control, changed -to conform with the bounds set on the control if limited, -or colored if not limited but the value is out-of-bounds. -A ValueError exception will be raised if an invalid value -is specified. -
-
GetValue() -
Retrieves the numeric value from the control. The value -retrieved will be either be returned as a long if the -fractionWidth is 0, or a float otherwise. -
-
-
SetParameters(**kwargs) -
Allows simultaneous setting of various attributes -of the control after construction. Keyword arguments -allowed are the same parameters as supported in the constructor. -
-
-
SetIntegerWidth(value) -
Resets the width of the integer portion of the control. The -value must be >= 1, or an AttributeError exception will result. -This value should account for any grouping characters that might -be inserted (if grouping is enabled), but does not need to account -for the sign, as that is handled separately by the control. -
GetIntegerWidth() -
Returns the current width of the integer portion of the control, -not including any reserved sign position. -
-
-
SetFractionWidth(value) -
Resets the width of the fractional portion of the control. The -value must be >= 0, or an AttributeError exception will result. If -0, the current value of the control will be truncated to an integer -value. -
GetFractionWidth() -
Returns the current width of the fractional portion of the control. -
-
-
SetMin(min=None) -
Resets the minimum value of the control. If a value of None -is provided, then the control will have no explicit minimum value. -If the value specified is greater than the current maximum value, -then the function returns False and the minimum will not change from -its current setting. On success, the function returns True. -
-If successful and the current value is lower than the new lower -bound, if the control is limited, the value will be automatically -adjusted to the new minimum value; if not limited, the value in the -control will be colored as invalid. -
-If min > the max value allowed by the width of the control, -the function will return False, and the min will not be set. -
-
GetMin() -
Gets the current lower bound value for the control. -It will return None if no lower bound is currently specified. -
-
-
SetMax(max=None) -
Resets the maximum value of the control. If a value of None -is provided, then the control will have no explicit maximum value. -If the value specified is less than the current minimum value, then -the function returns False and the maximum will not change from its -current setting. On success, the function returns True. -
-If successful and the current value is greater than the new upper -bound, if the control is limited the value will be automatically -adjusted to this maximum value; if not limited, the value in the -control will be colored as invalid. -
-If max > the max value allowed by the width of the control, -the function will return False, and the max will not be set. -
-
GetMax() -
Gets the current upper bound value for the control. -It will return None if no upper bound is currently specified. -
-
-
SetBounds(min=None,max=None) -
This function is a convenience function for setting the min and max -values at the same time. The function only applies the maximum bound -if setting the minimum bound is successful, and returns True -only if both operations succeed. Note: leaving out an argument -will remove the corresponding bound. -
GetBounds() -
This function returns a two-tuple (min,max), indicating the -current bounds of the control. Each value can be None if -that bound is not set. -
-
-
IsInBounds(value=None) -
Returns True if no value is specified and the current value -of the control falls within the current bounds. This function can also -be called with a value to see if that value would fall within the current -bounds of the given control. -
-
-
SetLimited(bool) -
If called with a value of True, this function will cause the control -to limit the value to fall within the bounds currently specified. -If the control's value currently exceeds the bounds, it will then -be limited accordingly. -If called with a value of False, this function will disable value -limiting, but coloring of out-of-bounds values will still take -place if bounds have been set for the control. -
GetLimited() -
IsLimited() -
Returns True if the control is currently limiting the -value to fall within the current bounds. -
-
-
SetAllowNone(bool) -
If called with a value of True, this function will cause the control -to allow the value to be empty, representing a value of None. -If called with a value of False, this function will prevent the value -from being None. If the value of the control is currently None, -ie. the control is empty, then the value will be changed to that -of the lower bound of the control, or 0 if no lower bound is set. -
GetAllowNone() -
IsNoneAllowed() -
Returns True if the control currently allows its -value to be None. -
-
-
SetAllowNegative(bool) -
If called with a value of True, this function will cause the -control to allow the value to be negative (and reserve space for -displaying the sign. If called with a value of False, and the -value of the control is currently negative, the value of the -control will be converted to the absolute value, and then -limited appropriately based on the existing bounds of the control -(if any). -
GetAllowNegative() -
IsNegativeAllowed() -
Returns True if the control currently permits values -to be negative. -
-
-
SetGroupDigits(bool) -
If called with a value of True, this will make the control -automatically add and manage grouping characters to the presented -value in integer portion of the control. -
GetGroupDigits() -
IsGroupingAllowed() -
Returns True if the control is currently set to group digits. -
-
-
SetGroupChar() -
Sets the grouping character for the integer portion of the -control. (The default grouping character this is ','. -
GetGroupChar() -
Returns the current grouping character for the control. -
-
-
SetSelectOnEntry() -
If called with a value of True, this will make the control -automatically select the contents of each field as it is entered -within the control. (The default is True.) -
GetSelectOnEntry() -
Returns True if the control currently auto selects -the field values on entry. -
-
-
SetAutoSize(bool) -
Resets the autoSize attribute of the control. -
GetAutoSize() -
Returns the current state of the autoSize attribute for the control. -
-
-
- + +-------------------------- + +masked.EVT_NUM(win, id, func) + Respond to a EVT_COMMAND_MASKED_NUMBER_UPDATED event, generated when + the value changes. Notice that this event will always be sent when the + control's contents changes - whether this is due to user input or + comes from the program itself (for example, if SetValue() is called.) + + +SetValue(int|long|float|string) + Sets the value of the control to the value specified, if + possible. The resulting actual value of the control may be + altered to conform to the format of the control, changed + to conform with the bounds set on the control if limited, + or colored if not limited but the value is out-of-bounds. + A ValueError exception will be raised if an invalid value + is specified. + +GetValue() + Retrieves the numeric value from the control. The value + retrieved will be either be returned as a long if the + fractionWidth is 0, or a float otherwise. + + +SetParameters(\*\*kwargs) + Allows simultaneous setting of various attributes + of the control after construction. Keyword arguments + allowed are the same parameters as supported in the constructor. + + +SetIntegerWidth(value) + Resets the width of the integer portion of the control. The + value must be >= 1, or an AttributeError exception will result. + This value should account for any grouping characters that might + be inserted (if grouping is enabled), but does not need to account + for the sign, as that is handled separately by the control. +GetIntegerWidth() + Returns the current width of the integer portion of the control, + not including any reserved sign position. + + +SetFractionWidth(value) + Resets the width of the fractional portion of the control. The + value must be >= 0, or an AttributeError exception will result. If + 0, the current value of the control will be truncated to an integer + value. +GetFractionWidth() + Returns the current width of the fractional portion of the control. + + +SetMin(min=None) + Resets the minimum value of the control. If a value of None + is provided, then the control will have no explicit minimum value. + If the value specified is greater than the current maximum value, + then the function returns False and the minimum will not change from + its current setting. On success, the function returns True. + + If successful and the current value is lower than the new lower + bound, if the control is limited, the value will be automatically + adjusted to the new minimum value; if not limited, the value in the + control will be colored as invalid. + + If min > the max value allowed by the width of the control, + the function will return False, and the min will not be set. + +GetMin() + Gets the current lower bound value for the control. + It will return None if no lower bound is currently specified. + + +SetMax(max=None) + Resets the maximum value of the control. If a value of None + is provided, then the control will have no explicit maximum value. + If the value specified is less than the current minimum value, then + the function returns False and the maximum will not change from its + current setting. On success, the function returns True. + + If successful and the current value is greater than the new upper + bound, if the control is limited the value will be automatically + adjusted to this maximum value; if not limited, the value in the + control will be colored as invalid. + + If max > the max value allowed by the width of the control, + the function will return False, and the max will not be set. + +GetMax() + Gets the current upper bound value for the control. + It will return None if no upper bound is currently specified. + + +SetBounds(min=None,max=None) + This function is a convenience function for setting the min and max + values at the same time. The function only applies the maximum bound + if setting the minimum bound is successful, and returns True + only if both operations succeed. Note: leaving out an argument + will remove the corresponding bound. +GetBounds() + This function returns a two-tuple (min,max), indicating the + current bounds of the control. Each value can be None if + that bound is not set. + + +IsInBounds(value=None) + Returns True if no value is specified and the current value + of the control falls within the current bounds. This function can also + be called with a value to see if that value would fall within the current + bounds of the given control. + + +SetLimited(bool) + If called with a value of True, this function will cause the control + to limit the value to fall within the bounds currently specified. + If the control's value currently exceeds the bounds, it will then + be limited accordingly. + If called with a value of False, this function will disable value + limiting, but coloring of out-of-bounds values will still take + place if bounds have been set for the control. + +GetLimited() + +IsLimited() + Returns True if the control is currently limiting the + value to fall within the current bounds. + + +SetAllowNone(bool) + If called with a value of True, this function will cause the control + to allow the value to be empty, representing a value of None. + If called with a value of False, this function will prevent the value + from being None. If the value of the control is currently None, + ie. the control is empty, then the value will be changed to that + of the lower bound of the control, or 0 if no lower bound is set. + +GetAllowNone() + +IsNoneAllowed() + Returns True if the control currently allows its + value to be None. + + +SetAllowNegative(bool) + If called with a value of True, this function will cause the + control to allow the value to be negative (and reserve space for + displaying the sign. If called with a value of False, and the + value of the control is currently negative, the value of the + control will be converted to the absolute value, and then + limited appropriately based on the existing bounds of the control + (if any). + +GetAllowNegative() + +IsNegativeAllowed() + Returns True if the control currently permits values + to be negative. + + +SetGroupDigits(bool) + If called with a value of True, this will make the control + automatically add and manage grouping characters to the presented + value in integer portion of the control. + +GetGroupDigits() + +IsGroupingAllowed() + Returns True if the control is currently set to group digits. + + +SetGroupChar() + Sets the grouping character for the integer portion of the + control. (The default grouping character this is ','. +GetGroupChar() + Returns the current grouping character for the control. + + +SetSelectOnEntry() + If called with a value of True, this will make the control + automatically select the contents of each field as it is entered + within the control. (The default is True.) + GetSelectOnEntry() + Returns True if the control currently auto selects + the field values on entry. + + +SetAutoSize(bool) + Resets the autoSize attribute of the control. +GetAutoSize() + Returns the current state of the autoSize attribute for the control. + """ import copy @@ -396,6 +401,10 @@ EVT_NUM = wx.PyEventBinder(wxEVT_COMMAND_MASKED_NUMBER_UPDATED, 1) #---------------------------------------------------------------------------- class NumberUpdatedEvent(wx.PyCommandEvent): + """ + Used to fire an EVT_NUM event whenever the value in a NumCtrl changes. + """ + def __init__(self, id, value = 0, object=None): wx.PyCommandEvent.__init__(self, wxEVT_COMMAND_MASKED_NUMBER_UPDATED, id) @@ -410,9 +419,11 @@ class NumberUpdatedEvent(wx.PyCommandEvent): #---------------------------------------------------------------------------- class NumCtrlAccessorsMixin: - # Define masked.NumCtrl's list of attributes having their own - # Get/Set functions, ignoring those that make no sense for - # an numeric control. + """ + Defines masked.NumCtrl's list of attributes having their own + Get/Set functions, ignoring those that make no sense for + a numeric control. + """ exposed_basectrl_params = ( 'decimalChar', 'shiftDecimalChar', @@ -449,6 +460,11 @@ class NumCtrlAccessorsMixin: #---------------------------------------------------------------------------- class NumCtrl(BaseMaskedTextCtrl, NumCtrlAccessorsMixin): + """ + Masked edit control supporting "native" numeric values, ie. .SetValue(3), for + example, and supporting a variety of formatting options, including automatic + rounding specifiable precision, grouping and decimal place characters, etc. + """ valid_ctrl_params = { @@ -591,7 +607,8 @@ class NumCtrl(BaseMaskedTextCtrl, NumCtrlAccessorsMixin): def SetParameters(self, **kwargs): """ - This routine is used to initialize and reconfigure the control: + This function is used to initialize and reconfigure the control. + See TimeCtrl module overview for available parameters. """ ## dbg('NumCtrl::SetParameters', indent=1) maskededit_kwargs = {} @@ -1731,7 +1748,7 @@ if __name__ == '__main__': except: traceback.print_exc() -i=0 +__i=0 ## To-Do's: ## =============================## ## 1. Add support for printf-style format specification.