X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2461468b51c022278cc52ba7fd274f3bfedef7e8..7bdfb981a826d29e292738a27700543fa10d2bfb:/wxPython/wx/lib/timectrl.py
diff --git a/wxPython/wx/lib/timectrl.py b/wxPython/wx/lib/timectrl.py
index c7d08a8ba7..af42f0836b 100644
--- a/wxPython/wx/lib/timectrl.py
+++ b/wxPython/wx/lib/timectrl.py
@@ -60,12 +60,14 @@ Here's the API for TimeCtrl:
TimeCtrl(
parent, id = -1,
value = '12:00:00 AM',
- pos = wxDefaultPosition,
- size = wxDefaultSize,
+ pos = wx.DefaultPosition,
+ size = wx.DefaultSize,
style = wxTE_PROCESS_TAB,
- validator = wxDefaultValidator,
+ validator = wx.DefaultValidator,
name = "time",
+ format = 'HHMMSS',
fmt24hr = False,
+ displaySeconds = True,
spinButton = None,
min = None,
max = None,
@@ -80,7 +82,7 @@ Here's the API for TimeCtrl:
with SetValue() after instantiation of the control.)
size
- The size of the control will be automatically adjusted for 12/24 hour format
- if wxDefaultSize is specified.
+ if wx.DefaultSize is specified.
- style
- By default, TimeCtrl will process TAB events, by allowing tab to the
different cells within the control.
@@ -89,11 +91,23 @@ Here's the API for TimeCtrl:
of its validation for entry control is handled internally. However, a validator
can be supplied to provide data transfer capability to the control.
+ - format
+
- This parameter can be used instead of the fmt24hr and displaySeconds
+ parameters, respectively; it provides a shorthand way to specify the time
+ format you want. Accepted values are 'HHMMSS', 'HHMM', '24HHMMSS', and
+ '24HHMM'. If the format is specified, the other two arguments will be ignored.
+
- fmt24hr
- If True, control will display time in 24 hour time format; if False, it will
use 12 hour AM/PM format. SetValue() will adjust values accordingly for the
- control, based on the format specified.
+ control, based on the format specified. (This value is ignored if the format
+ parameter is specified.)
+ - displaySeconds
+
- If True, control will include a seconds field; if False, it will
+ just show hours and minutes. (This value is ignored if the format
+ parameter is specified.)
+
- spinButton
- If specified, this button's events will be bound to the behavior of the
TimeCtrl, working like up/down cursor key events. (See BindSpinButton.)
@@ -151,7 +165,7 @@ set to Jan 1, 1970.) (Same as GetValue(as_wxDateTime=True); provided for backwar
compatibility with previous release.)
- - BindSpinButton(wxSpinBtton)
+
- BindSpinButton(SpinBtton)
- Binds an externally created spin button to the control, so that up/down spin
events change the active cell or selection in the control (in addition to the
up/down cursor keys.) (This is primarily to allow you to create a "standard"
@@ -258,7 +272,7 @@ import types
import wx
from wx.tools.dbg import Logger
-from wx.lib.maskededit import MaskedTextCtrl, Field
+from wx.lib.maskededit import BaseMaskedTextCtrl, Field
dbg = Logger()
dbg(enable=0)
@@ -281,11 +295,40 @@ class TimeUpdatedEvent(wx.PyCommandEvent):
"""Retrieve the value of the time control at the time this event was generated"""
return self.value
-
-class TimeCtrl(MaskedTextCtrl):
+class TimeCtrlAccessorsMixin:
+ # Define TimeCtrl's list of attributes having their own
+ # Get/Set functions, ignoring those that make no sense for
+ # an numeric control.
+ exposed_basectrl_params = (
+ 'defaultValue',
+ 'description',
+
+ 'useFixedWidthFont',
+ 'emptyBackgroundColour',
+ 'validBackgroundColour',
+ 'invalidBackgroundColour',
+
+ 'validFunc',
+ 'validRequired',
+ )
+ for param in exposed_basectrl_params:
+ propname = param[0].upper() + param[1:]
+ exec('def Set%s(self, value): self.SetCtrlParameters(%s=value)' % (propname, param))
+ exec('def Get%s(self): return self.GetCtrlParameter("%s")''' % (propname, param))
+
+ if param.find('Colour') != -1:
+ # add non-british spellings, for backward-compatibility
+ propname.replace('Colour', 'Color')
+
+ exec('def Set%s(self, value): self.SetCtrlParameters(%s=value)' % (propname, param))
+ exec('def Get%s(self): return self.GetCtrlParameter("%s")''' % (propname, param))
+
+
+class TimeCtrl(BaseMaskedTextCtrl):
valid_ctrl_params = {
- 'display_seconds' : True, # by default, shows seconds
+ 'format' : 'HHMMSS', # default format code
+ 'displaySeconds' : True, # by default, shows seconds
'min': None, # by default, no bounds set
'max': None,
'limited': False, # by default, no limiting even if bounds set
@@ -316,61 +359,39 @@ class TimeCtrl(MaskedTextCtrl):
max = self.__max
limited = self.__limited
self.__posCurrent = 0
+ # handle deprecated keword argument name:
+ if kwargs.has_key('display_seconds'):
+ kwargs['displaySeconds'] = kwargs['display_seconds']
+ del kwargs['display_seconds']
+ if not kwargs.has_key('displaySeconds'):
+ kwargs['displaySeconds'] = True
+
+ # (handle positional arg (from original release) differently from rest of kwargs:)
+ self.__fmt24hr = False
+ if not kwargs.has_key('format'):
+ if fmt24hr:
+ if kwargs.has_key('displaySeconds') and kwargs['displaySeconds']:
+ kwargs['format'] = '24HHMMSS'
+ del kwargs['displaySeconds']
+ else:
+ kwargs['format'] = '24HHMM'
+ else:
+ if kwargs.has_key('displaySeconds') and kwargs['displaySeconds']:
+ kwargs['format'] = 'HHMMSS'
+ del kwargs['displaySeconds']
+ else:
+ kwargs['format'] = 'HHMM'
+ if not kwargs.has_key('useFixedWidthFont'):
+ # allow control over font selection:
+ kwargs['useFixedWidthFont'] = self.__useFixedWidthFont
- # (handle positional args (from original release) differently from rest of kwargs:)
- self.__fmt24hr = fmt24hr
-
- maskededit_kwargs = {}
-
- # assign keyword args as appropriate:
- for key, param_value in kwargs.items():
- if key not in TimeCtrl.valid_ctrl_params.keys():
- raise AttributeError('invalid keyword argument "%s"' % key)
-
- if key == "display_seconds":
- self.__display_seconds = param_value
-
- elif key == "min": min = param_value
- elif key == "max": max = param_value
- elif key == "limited": limited = param_value
-
- elif key == "useFixedWidthFont":
- maskededit_kwargs[key] = param_value
- elif key == "oob_color":
- maskededit_kwargs['invalidBackgroundColor'] = param_value
-
- if self.__fmt24hr:
- if self.__display_seconds: maskededit_kwargs['autoformat'] = 'MILTIMEHHMMSS'
- else: maskededit_kwargs['autoformat'] = 'MILTIMEHHMM'
-
- # Set hour field to zero-pad, right-insert, require explicit field change,
- # select entire field on entry, and require a resultant valid entry
- # to allow character entry:
- hourfield = Field(formatcodes='0r