]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxCalendarCtrl.py
delete the .pyc files before making a preview
[wxWidgets.git] / wxPython / demo / wxCalendarCtrl.py
1 # 11/15/2003 - Jeff Grimmett (grimmtooth@softhome.net)
2 #
3 # o Updated for wx namespace
4 #
5
6 import wx
7 import wx.lib.calendar as calendar
8
9 #----------------------------------------------------------------------
10
11 class TestPanel(wx.Panel):
12 def __init__(self, parent, ID, log):
13 wx.Panel.__init__(self, parent, ID)
14 self.log = log
15
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
20 )
21
22 self.Bind(calendar.EVT_CALENDAR, self.OnCalSelected, id=cal.GetId())
23
24 b = wx.Button(self, -1, "Destroy the Calendar", pos = (250, 50))
25 self.Bind(wx.EVT_BUTTON, self.OnButton, id= b.GetId())
26 self.cal = cal
27
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)
31 self.OnChangeMonth()
32
33 def OnButton(self, evt):
34 self.cal.Destroy()
35 self.cal = None
36
37 def OnCalSelected(self, evt):
38 self.log.write('OnCalSelected: %s\n' % evt.GetDate())
39
40 def OnChangeMonth(self, evt=None):
41 cur_month = self.cal.GetDate().GetMonth() + 1 # convert wxDateTime 0-11 => 1-12
42
43 for month, day in self.holidays:
44 if month == cur_month:
45 self.cal.SetHoliday(day)
46
47 #----------------------------------------------------------------------
48
49 def runTest(frame, nb, log):
50 win = TestPanel(nb, -1, log)
51 return win
52
53 #----------------------------------------------------------------------
54
55
56 overview = """\
57 <html><body>
58 <h2>wxCalendarCtrl</h2>
59
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.
64 """
65
66
67
68
69 if __name__ == '__main__':
70 import sys,os
71 import run
72 run.main(['', os.path.basename(sys.argv[0])])
73