5 #---------------------------------------------------------------------- 
   7 class TestPanel(wx
.Panel
): 
   8     def __init__(self
, parent
, ID
, log
): 
   9         wx
.Panel
.__init
__(self
, parent
, ID
) 
  12         cal 
= wx
.calendar
.CalendarCtrl(self
, -1, wx
.DateTime_Now(), pos 
= (25,50), 
  13                              style 
= wx
.calendar
.CAL_SHOW_HOLIDAYS
 
  14                              | wx
.calendar
.CAL_SUNDAY_FIRST
 
  15                              | wx
.calendar
.CAL_SEQUENTIAL_MONTH_SELECTION
 
  18         self
.Bind(wx
.calendar
.EVT_CALENDAR
, self
.OnCalSelected
, id=cal
.GetId()) 
  20         # Set up control to display a set of holidays: 
  21         self
.Bind(wx
.calendar
.EVT_CALENDAR_MONTH
, self
.OnChangeMonth
, cal
) 
  22         self
.holidays 
= [(1,1), (10,31), (12,25) ]    # (these don't move around) 
  25         cal2 
= wx
.calendar
.CalendarCtrl(self
, -1, wx
.DateTime_Now(), pos 
= (325,50)) 
  26         self
.Bind(wx
.calendar
.EVT_CALENDAR_SEL_CHANGED
, 
  27                   self
.OnCalSelChanged
, cal2
) 
  29     def OnCalSelected(self
, evt
): 
  30         self
.log
.write('OnCalSelected: %s\n' % evt
.GetDate()) 
  32     def OnChangeMonth(self
, evt
=None): 
  33         cur_month 
= self
.cal
.GetDate().GetMonth() + 1   # convert wxDateTime 0-11 => 1-12 
  34         for month
, day 
in self
.holidays
: 
  35             if month 
== cur_month
: 
  36                 self
.cal
.SetHoliday(day
) 
  38             attr 
= wx
.calendar
.CalendarDateAttr(border
=wx
.calendar
.CAL_BORDER_SQUARE
, 
  40             self
.cal
.SetAttr(14, attr
) 
  42             self
.cal
.ResetAttr(14) 
  44     def OnCalSelChanged(self
, evt
): 
  45         cal 
= evt
.GetEventObject() 
  46         self
.log
.write("OnCalSelChanged:\n\t%s: %s\n\t%s: %s\n\t%s: %s\n\t" % 
  48                         "Date       ", cal
.GetDate(), 
  49                         "Ticks      ", cal
.GetDate().GetTicks(), 
  52 #---------------------------------------------------------------------- 
  54 def runTest(frame
, nb
, log
): 
  55     win 
= TestPanel(nb
, -1, log
) 
  58 #---------------------------------------------------------------------- 
  65 Yet <i>another</i> calendar control.  This one is a wrapper around the C++ 
  66 version described in the docs.  This one will probably be a bit more efficient 
  67 than the one in wxPython.lib.calendar, but I like a few things about it better, 
  68 so I think both will stay in wxPython. 
  72 if __name__ 
== '__main__': 
  75     run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])