X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d14a1e28567de23c586bc80017073d0c39f8d18f..b887061dd1d7b3a49a111513309b1bb5c308537c:/wxPython/wx/lib/timectrl.py
diff --git a/wxPython/wx/lib/timectrl.py b/wxPython/wx/lib/timectrl.py
index e0d52116b2..af42f0836b 100644
--- a/wxPython/wx/lib/timectrl.py
+++ b/wxPython/wx/lib/timectrl.py
@@ -1,5 +1,5 @@
#----------------------------------------------------------------------------
-# Name: wxTimeCtrl.py
+# Name: timectrl.py
# Author: Will Sadkin
# Created: 09/19/2002
# Copyright: (c) 2002 by Will Sadkin, 2002
@@ -13,12 +13,12 @@
# component of that control is inaccessible through the interface exposed in
# wxPython.
#
-# wxTimeCtrl does not use validators, because it does careful manipulation
+# TimeCtrl does not use validators, because it does careful manipulation
# of the cursor in the text window on each keystroke, and validation is
# cursor-position specific, so the control intercepts the key codes before the
# validator would fire.
#
-# wxTimeCtrl now also supports .SetValue() with either strings or wxDateTime
+# TimeCtrl now also supports .SetValue() with either strings or wxDateTime
# values, as well as range limits, with the option of either enforcing them
# or simply coloring the text of the control if the limits are exceeded.
#
@@ -29,31 +29,45 @@
# or be counted twice (1 day each per year, for DST adjustments), the date
# portion of all wxDateTimes used/returned have their date portion set to
# Jan 1, 1970 (the "epoch.")
+#----------------------------------------------------------------------------
+# 12/13/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for V2.5 compatability
+# o wx.SpinCtl has some issues that cause the control to
+# lock up. Noted in other places using it too, it's not this module
+# that's at fault.
+#
+# 12/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o wxMaskedTextCtrl -> MaskedTextCtrl
+# o wxTimeCtrl -> TimeCtrl
#
"""
-wxTimeCtrl provides a multi-cell control that allows manipulation of a time
+TimeCtrl provides a multi-cell control that allows manipulation of a time
value. It supports 12 or 24 hour format, and you can use wxDateTime or mxDateTime
to get/set values from the control.
-Left/right/tab keys to switch cells within a wxTimeCtrl, and the up/down arrows act
-like a spin control. wxTimeCtrl also allows for an actual spin button to be attached
+Left/right/tab keys to switch cells within a TimeCtrl, and the up/down arrows act
+like a spin control. TimeCtrl also allows for an actual spin button to be attached
to the control, so that it acts like the up/down arrow keys.
The ! or c key sets the value of the control to the current time.
-Here's the API for wxTimeCtrl:
+Here's the API for TimeCtrl:
- wxTimeCtrl(
+ 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,
@@ -68,27 +82,39 @@ Here's the API for wxTimeCtrl:
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, wxTimeCtrl will process TAB events, by allowing tab to the
+
- By default, TimeCtrl will process TAB events, by allowing tab to the
different cells within the control.
- validator
-
- By default, wxTimeCtrl just uses the default (empty) validator, as all
+
- By default, TimeCtrl just uses the default (empty) validator, as all
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
- wxTimeCtrl, working like up/down cursor key events. (See BindSpinButton.)
+ TimeCtrl, working like up/down cursor key events. (See BindSpinButton.)
- min
- Defines the lower bound for "valid" selections in the control.
- By default, wxTimeCtrl doesn't have bounds. You must set both upper and lower
+ By default, TimeCtrl doesn't have bounds. You must set both upper and lower
bounds to make the control pay attention to them, (as only one bound makes no sense
with times.) "Valid" times will fall between the min and max "pie wedge" of the
clock.
@@ -139,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"
@@ -239,10 +265,14 @@ value to fall within the current bounds.
"""
-import string, copy
-from wxPython.wx import *
-from wxPython.tools.dbg import Logger
-from wxPython.lib.maskededit import wxMaskedTextCtrl, Field
+import copy
+import string
+import types
+
+import wx
+
+from wx.tools.dbg import Logger
+from wx.lib.maskededit import BaseMaskedTextCtrl, Field
dbg = Logger()
dbg(enable=0)
@@ -254,47 +284,74 @@ except ImportError:
accept_mx = False
# This class of event fires whenever the value of the time changes in the control:
-wxEVT_TIMEVAL_UPDATED = wxNewId()
-def EVT_TIMEUPDATE(win, id, func):
- """Used to trap events indicating that the current time has been changed."""
- win.Connect(id, -1, wxEVT_TIMEVAL_UPDATED, func)
+wxEVT_TIMEVAL_UPDATED = wx.NewEventType()
+EVT_TIMEUPDATE = wx.PyEventBinder(wxEVT_TIMEVAL_UPDATED, 1)
-class TimeUpdatedEvent(wxPyCommandEvent):
+class TimeUpdatedEvent(wx.PyCommandEvent):
def __init__(self, id, value ='12:00:00 AM'):
- wxPyCommandEvent.__init__(self, wxEVT_TIMEVAL_UPDATED, id)
+ wx.PyCommandEvent.__init__(self, wxEVT_TIMEVAL_UPDATED, id)
self.value = value
def GetValue(self):
"""Retrieve the value of the time control at the time this event was generated"""
return self.value
-
-class wxTimeCtrl(wxMaskedTextCtrl):
+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
'useFixedWidthFont': True, # by default, use a fixed-width font
- 'oob_color': "Yellow" # by default, the default wxMaskedTextCtrl "invalid" color
+ 'oob_color': "Yellow" # by default, the default MaskedTextCtrl "invalid" color
}
def __init__ (
self, parent, id=-1, value = '12:00:00 AM',
- pos = wxDefaultPosition, size = wxDefaultSize,
+ pos = wx.DefaultPosition, size = wx.DefaultSize,
fmt24hr=False,
spinButton = None,
- style = wxTE_PROCESS_TAB,
- validator = wxDefaultValidator,
+ style = wx.TE_PROCESS_TAB,
+ validator = wx.DefaultValidator,
name = "time",
**kwargs ):
# set defaults for control:
dbg('setting defaults:')
- for key, param_value in wxTimeCtrl.valid_ctrl_params.items():
+ for key, param_value in TimeCtrl.valid_ctrl_params.items():
# This is done this way to make setattr behave consistently with
# "private attribute" name mangling
- setattr(self, "_wxTimeCtrl__" + key, copy.copy(param_value))
+ setattr(self, "_TimeCtrl__" + key, copy.copy(param_value))
# create locals from current defaults, so we can override if
# specified in kwargs, and handle uniformly:
@@ -302,61 +359,39 @@ class wxTimeCtrl(wxMaskedTextCtrl):
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 wxTimeCtrl.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" % self.GetValue()
+ return "" % self.GetValue()
def SetValue(self, value):
@@ -453,7 +584,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
and convert wxDateTime, mxDateTime, or 12/24 format time string
into the appropriate format string for the control.
"""
- dbg('wxTimeCtrl::SetValue(%s)' % repr(value), indent=1)
+ dbg('TimeCtrl::SetValue(%s)' % repr(value), indent=1)
try:
strtime = self._toGUI(self.__validateValue(value))
except:
@@ -478,11 +609,11 @@ class wxTimeCtrl(wxMaskedTextCtrl):
elif as_mxDateTime:
value = DateTime.DateTime(1970, 1, 1, value.GetHour(), value.GetMinute(), value.GetSecond())
elif as_wxTimeSpan:
- value = wxTimeSpan(value.GetHour(), value.GetMinute(), value.GetSecond())
+ value = wx.TimeSpan(value.GetHour(), value.GetMinute(), value.GetSecond())
elif as_mxDateTimeDelta:
value = DateTime.DateTimeDelta(0, value.GetHour(), value.GetMinute(), value.GetSecond())
else:
- value = wxMaskedTextCtrl.GetValue(self)
+ value = BaseMaskedTextCtrl.GetValue(self)
return value
@@ -495,7 +626,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
def GetWxDateTime(self, value=None):
"""
- This function is the conversion engine for wxTimeCtrl; it takes
+ This function is the conversion engine for TimeCtrl; it takes
one of the following types:
time string
wxDateTime
@@ -511,7 +642,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
"""
global accept_mx
dbg(suspend=1)
- dbg('wxTimeCtrl::GetWxDateTime(%s)' % repr(value), indent=1)
+ dbg('TimeCtrl::GetWxDateTime(%s)' % repr(value), indent=1)
if value is None:
dbg('getting control value')
value = self.GetValue()
@@ -524,7 +655,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
if type(value) == types.StringType:
# Construct constant wxDateTime, then try to parse the string:
- wxdt = wxDateTimeFromDMY(1, 0, 1970)
+ wxdt = wx.DateTimeFromDMY(1, 0, 1970)
dbg('attempting conversion')
value = value.strip() # (parser doesn't like leading spaces)
checkTime = wxdt.ParseTime(value)
@@ -536,9 +667,9 @@ class wxTimeCtrl(wxMaskedTextCtrl):
raise ValueError('cannot convert string "%s" to valid time' % value)
else:
- if isinstance(value, wxDateTime):
+ if isinstance(value, wx.DateTime):
hour, minute, second = value.GetHour(), value.GetMinute(), value.GetSecond()
- elif isinstance(value, wxTimeSpan):
+ elif isinstance(value, wx.TimeSpan):
totalseconds = value.GetSeconds()
hour = totalseconds / 3600
minute = totalseconds / 60 - (hour * 60)
@@ -557,7 +688,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
dbg(indent=0, suspend=0)
raise ValueError(error)
- wxdt = wxDateTimeFromDMY(1, 0, 1970)
+ wxdt = wx.DateTimeFromDMY(1, 0, 1970)
wxdt.SetHour(hour)
wxdt.SetMinute(minute)
wxdt.SetSecond(second)
@@ -599,7 +730,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
adjusted to the new minimum value; if not limited, the value in the
control will be colored as invalid.
"""
- dbg('wxTimeCtrl::SetMin(%s)'% repr(min), indent=1)
+ dbg('TimeCtrl::SetMin(%s)'% repr(min), indent=1)
if min is not None:
try:
min = self.GetWxDateTime(min)
@@ -627,7 +758,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
by default, or as a string if as_string argument is True.
"""
dbg(suspend=1)
- dbg('wxTimeCtrl::GetMin, as_string?', as_string, indent=1)
+ dbg('TimeCtrl::GetMin, as_string?', as_string, indent=1)
if self.__min is None:
dbg('(min == None)')
ret = self.__min
@@ -658,7 +789,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
adjusted to this maximum value; if not limited, the value in the
control will be colored as invalid.
"""
- dbg('wxTimeCtrl::SetMax(%s)' % repr(max), indent=1)
+ dbg('TimeCtrl::SetMax(%s)' % repr(max), indent=1)
if max is not None:
try:
max = self.GetWxDateTime(max)
@@ -686,7 +817,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
by default, or as a string if as_string argument is True.
"""
dbg(suspend=1)
- dbg('wxTimeCtrl::GetMin, as_string?', as_string, indent=1)
+ dbg('TimeCtrl::GetMin, as_string?', as_string, indent=1)
if self.__max is None:
dbg('(max == None)')
ret = self.__max
@@ -737,7 +868,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
limiting, but coloring of out-of-bounds values will still take
place if bounds have been set for the control.
"""
- dbg('wxTimeCtrl::SetLimited(%d)' % limited, indent=1)
+ dbg('TimeCtrl::SetLimited(%d)' % limited, indent=1)
self.__limited = limited
if not limited:
@@ -772,9 +903,9 @@ class wxTimeCtrl(wxMaskedTextCtrl):
# Note: relies on min and max and value date portions
# always being the same.
- interval = (min + wxTimeSpan(24, 0, 0, 0)) - max
+ interval = (min + wx.TimeSpan(24, 0, 0, 0)) - max
- half_interval = wxTimeSpan(
+ half_interval = wx.TimeSpan(
0, # hours
0, # minutes
interval.GetSeconds() / 2, # seconds
@@ -782,7 +913,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
if value < min: # min is on next day, so use value on
# "next day" for "nearest" interval calculation:
- cmp_value = value + wxTimeSpan(24, 0, 0, 0)
+ cmp_value = value + wx.TimeSpan(24, 0, 0, 0)
else: # "before midnight; ok
cmp_value = value
@@ -833,7 +964,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
dbg('ValueError getting wxDateTime for %s' % repr(value), indent=0)
raise
- dbg('wxTimeCtrl::IsInBounds(%s)' % repr(value), indent=1)
+ dbg('TimeCtrl::IsInBounds(%s)' % repr(value), indent=1)
if self.__min is None or self.__max is None:
dbg(indent=0)
return True
@@ -850,7 +981,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
min = self.GetMin()
max = self.GetMax()
- midnight = wxDateTimeFromDMY(1, 0, 1970)
+ midnight = wx.DateTimeFromDMY(1, 0, 1970)
if min <= max: # they don't span midnight
ret = min <= value <= max
@@ -874,15 +1005,25 @@ class wxTimeCtrl(wxMaskedTextCtrl):
except ValueError:
return False
+ def SetFormat(self, format):
+ self.SetParameters(format=format)
+
+ def GetFormat(self):
+ if self.__displaySeconds:
+ if self.__fmt24hr: return '24HHMMSS'
+ else: return 'HHMMSS'
+ else:
+ if self.__fmt24hr: return '24HHMM'
+ else: return 'HHMM'
#-------------------------------------------------------------------------------------------------------------
# these are private functions and overrides:
def __OnTextChange(self, event=None):
- dbg('wxTimeCtrl::OnTextChange', indent=1)
+ dbg('TimeCtrl::OnTextChange', indent=1)
- # Allow wxMaskedtext base control to color as appropriate,
+ # Allow Maskedtext base control to color as appropriate,
# and Skip the EVT_TEXT event (if appropriate.)
##! WS: For some inexplicable reason, every wxTextCtrl.SetValue()
## call is generating two (2) EVT_TEXT events. (!)
@@ -891,7 +1032,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
## event iff the value has actually changed. The masked edit
## OnTextChange routine does this, and returns True on a valid event,
## False otherwise.
- if not wxMaskedTextCtrl._OnTextChange(self, event):
+ if not BaseMaskedTextCtrl._OnTextChange(self, event):
return
dbg('firing TimeUpdatedEvent...')
@@ -907,14 +1048,14 @@ class wxTimeCtrl(wxMaskedTextCtrl):
This is necessary to handle the optional spin button, because the insertion
point is lost when the focus shifts to the spin button.
"""
- dbg('wxTimeCtrl::SetInsertionPoint', pos, indent=1)
- wxMaskedTextCtrl.SetInsertionPoint(self, pos) # (causes EVT_TEXT event to fire)
+ dbg('TimeCtrl::SetInsertionPoint', pos, indent=1)
+ BaseMaskedTextCtrl.SetInsertionPoint(self, pos) # (causes EVT_TEXT event to fire)
self.__posCurrent = self.GetInsertionPoint()
dbg(indent=0)
def SetSelection(self, sel_start, sel_to):
- dbg('wxTimeCtrl::SetSelection', sel_start, sel_to, indent=1)
+ dbg('TimeCtrl::SetSelection', sel_start, sel_to, indent=1)
# Adjust selection range to legal extent if not already
if sel_start < 0:
@@ -927,7 +1068,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
sel_to = cell_end
self.__bSelection = sel_start != sel_to
- wxMaskedTextCtrl.SetSelection(self, sel_start, sel_to)
+ BaseMaskedTextCtrl.SetSelection(self, sel_start, sel_to)
dbg(indent=0)
@@ -952,8 +1093,8 @@ class wxTimeCtrl(wxMaskedTextCtrl):
Event handler for any bound spin button on EVT_SPIN_UP;
causes control to behave as if up arrow was pressed.
"""
- dbg('wxTimeCtrl::OnSpinUp', indent=1)
- self.__OnSpin(WXK_UP)
+ dbg('TimeCtrl::OnSpinUp', indent=1)
+ self.__OnSpin(wx.WXK_UP)
keep_processing = False
dbg(indent=0)
return keep_processing
@@ -964,8 +1105,8 @@ class wxTimeCtrl(wxMaskedTextCtrl):
Event handler for any bound spin button on EVT_SPIN_DOWN;
causes control to behave as if down arrow was pressed.
"""
- dbg('wxTimeCtrl::OnSpinDown', indent=1)
- self.__OnSpin(WXK_DOWN)
+ dbg('TimeCtrl::OnSpinDown', indent=1)
+ self.__OnSpin(wx.WXK_DOWN)
keep_processing = False
dbg(indent=0)
return keep_processing
@@ -978,13 +1119,13 @@ class wxTimeCtrl(wxMaskedTextCtrl):
It then calls the base control's _OnChar routine with the modified
event instance.
"""
- dbg('wxTimeCtrl::OnChar', indent=1)
+ dbg('TimeCtrl::OnChar', indent=1)
keycode = event.GetKeyCode()
dbg('keycode:', keycode)
if keycode == ord(':'):
dbg('colon seen! removing shift attribute')
event.m_shiftDown = False
- wxMaskedTextCtrl._OnChar(self, event ) ## handle each keypress
+ BaseMaskedTextCtrl._OnChar(self, event ) ## handle each keypress
dbg(indent=0)
@@ -993,7 +1134,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
This is the key handler for '!' and 'c'; this allows the user to
quickly set the value of the control to the current time.
"""
- self.SetValue(wxDateTime_Now().FormatTime())
+ self.SetValue(wx.DateTime_Now().FormatTime())
keep_processing = False
return keep_processing
@@ -1003,7 +1144,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
Event handler for motion events; this handler
changes limits the selection to the new cell boundaries.
"""
- dbg('wxTimeCtrl::LimitSelection', indent=1)
+ dbg('TimeCtrl::LimitSelection', indent=1)
pos = self.GetInsertionPoint()
self.__posCurrent = pos
sel_start, sel_to = self.GetSelection()
@@ -1022,13 +1163,13 @@ class wxTimeCtrl(wxMaskedTextCtrl):
def __IncrementValue(self, key, pos):
- dbg('wxTimeCtrl::IncrementValue', key, pos, indent=1)
+ dbg('TimeCtrl::IncrementValue', key, pos, indent=1)
text = self.GetValue()
field = self._FindField(pos)
dbg('field: ', field._index)
start, end = field._extent
slice = text[start:end]
- if key == WXK_UP: increment = 1
+ if key == wx.WXK_UP: increment = 1
else: increment = -1
if slice in ('A', 'P'):
@@ -1040,7 +1181,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
# adjusting this field is trickier, as its value can affect the
# am/pm setting. So, we use wxDateTime to generate a new value for us:
# (Use a fixed date not subject to DST variations:)
- converter = wxDateTimeFromDMY(1, 0, 1970)
+ converter = wx.DateTimeFromDMY(1, 0, 1970)
dbg('text: "%s"' % text)
converter.ParseTime(text.strip())
currenthour = converter.GetHour()
@@ -1059,8 +1200,8 @@ class wxTimeCtrl(wxMaskedTextCtrl):
self.SetValue(newvalue)
except ValueError: # must not be in bounds:
- if not wxValidator_IsSilent():
- wxBell()
+ if not wx.Validator_IsSilent():
+ wx.Bell()
dbg(indent=0)
@@ -1070,11 +1211,11 @@ class wxTimeCtrl(wxMaskedTextCtrl):
converts it to a string appropriate for the format of the control.
"""
if self.__fmt24hr:
- if self.__display_seconds: strval = wxdt.Format('%H:%M:%S')
- else: strval = wxdt.Format('%H:%M')
+ if self.__displaySeconds: strval = wxdt.Format('%H:%M:%S')
+ else: strval = wxdt.Format('%H:%M')
else:
- if self.__display_seconds: strval = wxdt.Format('%I:%M:%S %p')
- else: strval = wxdt.Format('%I:%M %p')
+ if self.__displaySeconds: strval = wxdt.Format('%I:%M:%S %p')
+ else: strval = wxdt.Format('%I:%M %p')
return strval
@@ -1086,7 +1227,7 @@ class wxTimeCtrl(wxMaskedTextCtrl):
not a valid value for the control as currently specified.
It is used by both the SetValue() and the IsValid() methods.
"""
- dbg('wxTimeCtrl::__validateValue(%s)' % repr(value), indent=1)
+ dbg('TimeCtrl::__validateValue(%s)' % repr(value), indent=1)
if not value:
dbg(indent=0)
raise ValueError('%s not a valid time value' % repr(value))
@@ -1106,35 +1247,35 @@ class wxTimeCtrl(wxMaskedTextCtrl):
return value
#----------------------------------------------------------------------------
-# Test jig for wxTimeCtrl:
+# Test jig for TimeCtrl:
if __name__ == '__main__':
import traceback
- class TestPanel(wxPanel):
+ class TestPanel(wx.Panel):
def __init__(self, parent, id,
- pos = wxPyDefaultPosition, size = wxPyDefaultSize,
+ pos = wx.DefaultPosition, size = wx.DefaultSize,
fmt24hr = 0, test_mx = 0,
- style = wxTAB_TRAVERSAL ):
+ style = wx.TAB_TRAVERSAL ):
- wxPanel.__init__(self, parent, id, pos, size, style)
+ wx.Panel.__init__(self, parent, id, pos, size, style)
self.test_mx = test_mx
- self.tc = wxTimeCtrl(self, 10, fmt24hr = fmt24hr)
- sb = wxSpinButton( self, 20, wxDefaultPosition, wxSize(-1,20), 0 )
+ self.tc = TimeCtrl(self, 10, fmt24hr = fmt24hr)
+ sb = wx.SpinButton( self, 20, wx.DefaultPosition, (-1,20), 0 )
self.tc.BindSpinButton(sb)
- sizer = wxBoxSizer( wxHORIZONTAL )
- sizer.AddWindow( self.tc, 0, wxALIGN_CENTRE|wxLEFT|wxTOP|wxBOTTOM, 5 )
- sizer.AddWindow( sb, 0, wxALIGN_CENTRE|wxRIGHT|wxTOP|wxBOTTOM, 5 )
+ sizer = wx.BoxSizer( wx.HORIZONTAL )
+ sizer.Add( self.tc, 0, wx.ALIGN_CENTRE|wx.LEFT|wx.TOP|wx.BOTTOM, 5 )
+ sizer.Add( sb, 0, wx.ALIGN_CENTRE|wx.RIGHT|wx.TOP|wx.BOTTOM, 5 )
self.SetAutoLayout( True )
self.SetSizer( sizer )
sizer.Fit( self )
sizer.SetSizeHints( self )
- EVT_TIMEUPDATE(self, self.tc.GetId(), self.OnTimeChange)
+ self.Bind(EVT_TIMEUPDATE, self.OnTimeChange, self.tc)
def OnTimeChange(self, event):
dbg('OnTimeChange: value = ', event.GetValue())
@@ -1145,14 +1286,14 @@ if __name__ == '__main__':
dbg('mxdt =', mxdt.hour, mxdt.minute, mxdt.second)
- class MyApp(wxApp):
+ class MyApp(wx.App):
def OnInit(self):
import sys
fmt24hr = '24' in sys.argv
test_mx = 'mx' in sys.argv
try:
- frame = wxFrame(NULL, -1, "wxTimeCtrl Test", wxPoint(20,20), wxSize(100,100) )
- panel = TestPanel(frame, -1, wxPoint(-1,-1), fmt24hr=fmt24hr, test_mx = test_mx)
+ frame = wx.Frame(None, -1, "TimeCtrl Test", (20,20), (100,100) )
+ panel = TestPanel(frame, -1, (-1,-1), fmt24hr=fmt24hr, test_mx = test_mx)
frame.Show(True)
except:
traceback.print_exc()
@@ -1164,3 +1305,11 @@ if __name__ == '__main__':
app.MainLoop()
except:
traceback.print_exc()
+i=0
+## Version 1.2
+## 1. Changed parameter name display_seconds to displaySeconds, to follow
+## other masked edit conventions.
+## 2. Added format parameter, to remove need to use both fmt24hr and displaySeconds.
+## 3. Changed inheritance to use BaseMaskedTextCtrl, to remove exposure of
+## nonsensical parameter methods from the control, so it will work
+## properly with Boa.