2 from wxPython
.wx
import *
3 from wxPython
.calendar
import *
4 from wxPython
.utils
import *
6 #----------------------------------------------------------------------
8 class TestPanel(wxPanel
):
9 def __init__(self
, parent
, ID
, log
):
10 wxPanel
.__init
__(self
, parent
, ID
)
13 cal
= wxCalendarCtrl(self
, -1, wxDateTime_Now(), pos
= (25,50),
14 style
= wxCAL_SHOW_HOLIDAYS
16 | wxCAL_SEQUENTIAL_MONTH_SELECTION
19 EVT_CALENDAR(self
, cal
.GetId(), self
.OnCalSelected
)
21 b
= wxButton(self
, -1, "Destroy the Calendar", pos
= (250, 50))
22 EVT_BUTTON(self
, b
.GetId(), self
.OnButton
)
25 # Set up control to display a set of holidays:
26 EVT_CALENDAR_MONTH(self
, cal
.GetId(), self
.OnChangeMonth
)
27 self
.holidays
= [(1,1), (10,31), (12,25) ] # (these don't move around)
30 def OnButton(self
, evt
):
34 def OnCalSelected(self
, evt
):
35 self
.log
.write('OnCalSelected: %s\n' % evt
.GetDate())
37 def OnChangeMonth(self
, evt
=None):
38 cur_month
= self
.cal
.GetDate().GetMonth() + 1 # convert wxDateTime 0-11 => 1-12
39 for month
, day
in self
.holidays
:
40 if month
== cur_month
:
41 self
.cal
.SetHoliday(day
)
43 #----------------------------------------------------------------------
45 def runTest(frame
, nb
, log
):
46 win
= TestPanel(nb
, -1, log
)
49 #----------------------------------------------------------------------
54 <h2>wxCalendarCtrl</h2>
56 Yet <i>another</i> calendar control. This one is a wrapper around the C++
57 version described in the docs. This one will probably be a bit more efficient
58 than the one in wxPython.lib.calendar, but I like a few things about it better,
59 so I think both will stay in wxPython.
65 if __name__
== '__main__':
68 run
.main(['', os
.path
.basename(sys
.argv
[0])])