from wxPython.wx import * from wxPython.lib.timectrl import * import string #---------------------------------------------------------------------- class TestPanel(wxPanel): def __init__(self, parent, log): wxPanel.__init__(self, parent, -1) self.log = log panel = wxPanel(self, -1) grid = wxFlexGridSizer( 0, 2, 20, 0 ) text1 = wxStaticText( panel, 10, "A 12-hour format wxTimeCtrl:", wxDefaultPosition, wxDefaultSize, 0 ) grid.AddWindow( text1, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5 ) hsizer1 = wxBoxSizer( wxHORIZONTAL ) self.time12 = wxTimeCtrl(panel, 20, name="12 hour time") hsizer1.AddWindow( self.time12, 0, wxALIGN_CENTRE, 5 ) spin1 = wxSpinButton( panel, 30, wxDefaultPosition, wxSize(-1,20), 0 ) self.time12.BindSpinButton(spin1) hsizer1.AddWindow( spin1, 0, wxALIGN_CENTRE, 5 ) grid.AddSizer( hsizer1, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ) text2 = wxStaticText( panel, 40, "A 24-hour format wxTimeCtrl:", wxDefaultPosition, wxDefaultSize, 0 ) grid.AddWindow( text2, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxLEFT|wxTOP|wxBOTTOM, 5 ) hsizer2 = wxBoxSizer( wxHORIZONTAL ) self.time24 = wxTimeCtrl(panel, 50, fmt24hr=true, name="24 hour time") hsizer2.AddWindow( self.time24, 0, wxALIGN_CENTRE, 5 ) spin2 = wxSpinButton( panel, 60, wxDefaultPosition, wxSize(-1,20), 0 ) self.time24.BindSpinButton(spin2) hsizer2.AddWindow( spin2, 0, wxALIGN_CENTRE, 5 ) grid.AddSizer( hsizer2, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ) panel.SetAutoLayout(true) panel.SetSizer(grid) grid.Fit(panel) panel.Move((50,50)) self.panel = panel EVT_TIMEUPDATE(self, self.time12.GetId(), self.OnTimeChange) EVT_TIMEUPDATE(self, self.time24.GetId(), self.OnTimeChange) def OnTimeChange(self, event): timectrl = self.panel.FindWindowById(event.GetId()) self.log.write('%s = %s\n' % ( timectrl.GetName(), timectrl.GetValue() ) ) #---------------------------------------------------------------------- def runTest(frame, nb, log): win = TestPanel(nb, log) return win #---------------------------------------------------------------------- # It's nice to be able to use HTML here, but line breaks in the triple quoted string # cause the resulting output to look funny, as they seem to be interpreted by the # parser... overview = """
wxTimeCtrl 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 mxDateTimet o 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 to the control, so that it acts like the up/down arrow keys.
Here's the interface for wxTimeCtrl:
wxTimeCtrl(parent, id = -1, value = '12:00:00 AM', pos = wxDefaultPosition, size = wxDefaultSize, fmt24hr = false, spinButton = None, style = wxTE_PROCESS_TAB, name = "time")