]>
Commit | Line | Data |
---|---|---|
f6bcfd97 | 1 | |
8fa876ca | 2 | import wx |
95bfd958 | 3 | import wx.calendar |
f6bcfd97 BP |
4 | |
5 | #---------------------------------------------------------------------- | |
6 | ||
8fa876ca | 7 | class TestPanel(wx.Panel): |
f6bcfd97 | 8 | def __init__(self, parent, ID, log): |
8fa876ca | 9 | wx.Panel.__init__(self, parent, ID) |
f6bcfd97 BP |
10 | self.log = log |
11 | ||
95bfd958 RD |
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 | |
1fded56b | 16 | ) |
f6bcfd97 | 17 | |
95bfd958 | 18 | self.Bind(wx.calendar.EVT_CALENDAR, self.OnCalSelected, id=cal.GetId()) |
f6bcfd97 | 19 | |
8fa876ca RD |
20 | b = wx.Button(self, -1, "Destroy the Calendar", pos = (250, 50)) |
21 | self.Bind(wx.EVT_BUTTON, self.OnButton, id= b.GetId()) | |
b96c7a38 RD |
22 | self.cal = cal |
23 | ||
1e4a197e | 24 | # Set up control to display a set of holidays: |
95bfd958 | 25 | self.Bind(wx.calendar.EVT_CALENDAR_MONTH, self.OnChangeMonth, cal) |
1e4a197e RD |
26 | self.holidays = [(1,1), (10,31), (12,25) ] # (these don't move around) |
27 | self.OnChangeMonth() | |
28 | ||
b96c7a38 RD |
29 | def OnButton(self, evt): |
30 | self.cal.Destroy() | |
31 | self.cal = None | |
f6bcfd97 BP |
32 | |
33 | def OnCalSelected(self, evt): | |
34 | self.log.write('OnCalSelected: %s\n' % evt.GetDate()) | |
35 | ||
1e4a197e RD |
36 | def OnChangeMonth(self, evt=None): |
37 | cur_month = self.cal.GetDate().GetMonth() + 1 # convert wxDateTime 0-11 => 1-12 | |
8fa876ca | 38 | |
1e4a197e RD |
39 | for month, day in self.holidays: |
40 | if month == cur_month: | |
41 | self.cal.SetHoliday(day) | |
f6bcfd97 BP |
42 | |
43 | #---------------------------------------------------------------------- | |
44 | ||
45 | def runTest(frame, nb, log): | |
46 | win = TestPanel(nb, -1, log) | |
47 | return win | |
48 | ||
49 | #---------------------------------------------------------------------- | |
50 | ||
51 | ||
52 | overview = """\ | |
53 | <html><body> | |
95bfd958 | 54 | <h2>CalendarCtrl</h2> |
f6bcfd97 BP |
55 | |
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. | |
60 | """ | |
1fded56b RD |
61 | |
62 | ||
1fded56b RD |
63 | if __name__ == '__main__': |
64 | import sys,os | |
65 | import run | |
66 | run.main(['', os.path.basename(sys.argv[0])]) | |
67 |