X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/fd3f2efe791cf99c2e4944cd615f02a5502ed93e..d19a83a5ac67c97c208e28289bbf4adaee6b4134:/wxPython/wx/lib/timectrl.py diff --git a/wxPython/wx/lib/timectrl.py b/wxPython/wx/lib/timectrl.py index 8a0384476e..c7d08a8ba7 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,23 +29,35 @@ # 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,
@@ -70,10 +82,10 @@ Here's the API for wxTimeCtrl:
     
The size of the control will be automatically adjusted for 12/24 hour format if wxDefaultSize 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.
@@ -84,11 +96,11 @@ Here's the API for wxTimeCtrl:
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. @@ -239,10 +251,14 @@ value to fall within the current bounds. """ -import string, copy, types -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 MaskedTextCtrl, Field dbg = Logger() dbg(enable=0) @@ -254,21 +270,19 @@ 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 TimeCtrl(MaskedTextCtrl): valid_ctrl_params = { 'display_seconds' : True, # by default, shows seconds @@ -276,25 +290,25 @@ class wxTimeCtrl(wxMaskedTextCtrl): '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: @@ -311,7 +325,7 @@ class wxTimeCtrl(wxMaskedTextCtrl): # assign keyword args as appropriate: for key, param_value in kwargs.items(): - if key not in wxTimeCtrl.valid_ctrl_params.keys(): + if key not in TimeCtrl.valid_ctrl_params.keys(): raise AttributeError('invalid keyword argument "%s"' % key) if key == "display_seconds": @@ -369,12 +383,12 @@ class wxTimeCtrl(wxMaskedTextCtrl): maskededit_kwargs['useFixedWidthFont'] = self.__useFixedWidthFont # allow for explicit size specification: - if size != wxDefaultSize: + if size != wx.DefaultSize: # override (and remove) "autofit" autoformat code in standard time formats: maskededit_kwargs['formatcodes'] = 'T!' # Now we can initialize the base control: - wxMaskedTextCtrl.__init__( + MaskedTextCtrl.__init__( self, parent, id=id, pos=pos, size=size, style = style, @@ -389,8 +403,8 @@ class wxTimeCtrl(wxMaskedTextCtrl): # This makes the up/down keys act like spin button controls: - self._SetKeycodeHandler(WXK_UP, self.__OnSpinUp) - self._SetKeycodeHandler(WXK_DOWN, self.__OnSpinDown) + self._SetKeycodeHandler(wx.WXK_UP, self.__OnSpinUp) + self._SetKeycodeHandler(wx.WXK_DOWN, self.__OnSpinDown) # This allows ! and c/C to set the control to the current time: @@ -405,15 +419,15 @@ class wxTimeCtrl(wxMaskedTextCtrl): # that : takes you forward, not back, and so we can issue # EVT_TIMEUPDATE events on changes: - EVT_SET_FOCUS( self, self._OnFocus ) ## defeat automatic full selection - EVT_KILL_FOCUS( self, self._OnKillFocus ) ## run internal validator - EVT_LEFT_UP(self, self.__LimitSelection) ## limit selections to single field - EVT_LEFT_DCLICK(self, self._OnDoubleClick ) ## select field under cursor on dclick - EVT_KEY_DOWN( self, self._OnKeyDown ) ## capture control events not normally seen, eg ctrl-tab. - EVT_CHAR( self, self.__OnChar ) ## remove "shift" attribute from colon key event, - ## then call wxMaskedTextCtrl._OnChar with - ## the possibly modified event. - EVT_TEXT( self, self.GetId(), self.__OnTextChange ) ## color control appropriately and EVT_TIMEUPDATE events + self.Bind(wx.EVT_SET_FOCUS, self._OnFocus ) ## defeat automatic full selection + self.Bind(wx.EVT_KILL_FOCUS, self._OnKillFocus ) ## run internal validator + self.Bind(wx.EVT_LEFT_UP, self.__LimitSelection) ## limit selections to single field + self.Bind(wx.EVT_LEFT_DCLICK, self._OnDoubleClick ) ## select field under cursor on dclick + self.Bind(wx.EVT_KEY_DOWN, self._OnKeyDown ) ## capture control events not normally seen, eg ctrl-tab. + self.Bind(wx.EVT_CHAR, self.__OnChar ) ## remove "shift" attribute from colon key event, + ## then call MaskedTextCtrl._OnChar with + ## the possibly modified event. + self.Bind(wx.EVT_TEXT, self.__OnTextChange, self ) ## color control appropriately and EVT_TIMEUPDATE events # Validate initial value and set if appropriate @@ -434,16 +448,16 @@ class wxTimeCtrl(wxMaskedTextCtrl): This function binds an externally created spin button to the control, so that up/down events from the button automatically change the control. """ - dbg('wxTimeCtrl::BindSpinButton') + dbg('TimeCtrl::BindSpinButton') self.__spinButton = sb if self.__spinButton: # bind event handlers to spin ctrl - EVT_SPIN_UP(self.__spinButton, self.__spinButton.GetId(), self.__OnSpinUp) - EVT_SPIN_DOWN(self.__spinButton, self.__spinButton.GetId(), self.__OnSpinDown) + self.__spinButton.Bind(wx.EVT_SPIN_UP, self.__OnSpinUp, self.__spinButton) + self.__spinButton.Bind(wx.EVT_SPIN_DOWN, self.__OnSpinDown, self.__spinButton) def __repr__(self): - return "" % self.GetValue() + return "" % self.GetValue() def SetValue(self, value): @@ -453,7 +467,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 +492,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 = MaskedTextCtrl.GetValue(self) return value @@ -495,7 +509,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 +525,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 +538,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 +550,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 +571,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 +613,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 +641,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 +672,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 +700,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 +751,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 +786,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 +796,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 +847,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 +864,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 @@ -880,7 +894,7 @@ class wxTimeCtrl(wxMaskedTextCtrl): def __OnTextChange(self, event=None): - dbg('wxTimeCtrl::OnTextChange', indent=1) + dbg('TimeCtrl::OnTextChange', indent=1) # Allow wxMaskedtext base control to color as appropriate, # and Skip the EVT_TEXT event (if appropriate.) @@ -891,7 +905,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 MaskedTextCtrl._OnTextChange(self, event): return dbg('firing TimeUpdatedEvent...') @@ -907,14 +921,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) + MaskedTextCtrl.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 +941,7 @@ class wxTimeCtrl(wxMaskedTextCtrl): sel_to = cell_end self.__bSelection = sel_start != sel_to - wxMaskedTextCtrl.SetSelection(self, sel_start, sel_to) + MaskedTextCtrl.SetSelection(self, sel_start, sel_to) dbg(indent=0) @@ -952,8 +966,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 +978,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 +992,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 + MaskedTextCtrl._OnChar(self, event ) ## handle each keypress dbg(indent=0) @@ -993,7 +1007,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 +1017,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 +1036,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 +1054,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 +1073,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) @@ -1086,7 +1100,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 +1120,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 +1159,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()