1 # 11/15/2003 - Jeff Grimmett (grimmtooth@softhome.net)
3 # o Updated for wx namespace
7 import wx
.lib
.calendar
as calendar
9 #----------------------------------------------------------------------
11 class TestPanel(wx
.Panel
):
12 def __init__(self
, parent
, ID
, log
):
13 wx
.Panel
.__init
__(self
, parent
, ID
)
16 cal
= calendar
.CalendarCtrl(self
, -1, wx
.DateTime_Now(), pos
= (25,50),
17 style
= calendar
.CAL_SHOW_HOLIDAYS
18 | calendar
.CAL_SUNDAY_FIRST
19 | calendar
.CAL_SEQUENTIAL_MONTH_SELECTION
22 self
.Bind(calendar
.EVT_CALENDAR
, self
.OnCalSelected
, id=cal
.GetId())
24 b
= wx
.Button(self
, -1, "Destroy the Calendar", pos
= (250, 50))
25 self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, id= b
.GetId())
28 # Set up control to display a set of holidays:
29 self
.Bind(calendar
.EVT_CALENDAR_MONTH
, self
.OnChangeMonth
, id=cal
.GetId())
30 self
.holidays
= [(1,1), (10,31), (12,25) ] # (these don't move around)
33 def OnButton(self
, evt
):
37 def OnCalSelected(self
, evt
):
38 self
.log
.write('OnCalSelected: %s\n' % evt
.GetDate())
40 def OnChangeMonth(self
, evt
=None):
41 cur_month
= self
.cal
.GetDate().GetMonth() + 1 # convert wxDateTime 0-11 => 1-12
43 for month
, day
in self
.holidays
:
44 if month
== cur_month
:
45 self
.cal
.SetHoliday(day
)
47 #----------------------------------------------------------------------
49 def runTest(frame
, nb
, log
):
50 win
= TestPanel(nb
, -1, log
)
53 #----------------------------------------------------------------------
58 <h2>wxCalendarCtrl</h2>
60 Yet <i>another</i> calendar control. This one is a wrapper around the C++
61 version described in the docs. This one will probably be a bit more efficient
62 than the one in wxPython.lib.calendar, but I like a few things about it better,
63 so I think both will stay in wxPython.
69 if __name__
== '__main__':
72 run
.main(['', os
.path
.basename(sys
.argv
[0])])