]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/CalendarCtrl.py
added missing button state
[wxWidgets.git] / wxPython / demo / CalendarCtrl.py
CommitLineData
f6bcfd97 1
8fa876ca 2import wx
95bfd958 3import wx.calendar
f6bcfd97
BP
4
5#----------------------------------------------------------------------
6
8fa876ca 7class 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 )
b96c7a38 17 self.cal = cal
a0415e12 18 self.Bind(wx.calendar.EVT_CALENDAR, self.OnCalSelected, id=cal.GetId())
b96c7a38 19
1e4a197e 20 # Set up control to display a set of holidays:
95bfd958 21 self.Bind(wx.calendar.EVT_CALENDAR_MONTH, self.OnChangeMonth, cal)
1e4a197e
RD
22 self.holidays = [(1,1), (10,31), (12,25) ] # (these don't move around)
23 self.OnChangeMonth()
24
a0415e12 25 cal2 = wx.calendar.CalendarCtrl(self, -1, wx.DateTime_Now(), pos = (325,50))
28ff70c2
RD
26 self.Bind(wx.calendar.EVT_CALENDAR_SEL_CHANGED,
27 self.OnCalSelChanged, cal2)
f6bcfd97
BP
28
29 def OnCalSelected(self, evt):
30 self.log.write('OnCalSelected: %s\n' % evt.GetDate())
31
1e4a197e
RD
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)
47f116cc
RD
37 if cur_month == 8:
38 attr = wx.calendar.CalendarDateAttr(border=wx.calendar.CAL_BORDER_SQUARE,
39 colBorder="blue")
40 self.cal.SetAttr(14, attr)
41 else:
42 self.cal.ResetAttr(14)
f6bcfd97 43
28ff70c2
RD
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" %
47 ("EventObject", cal,
48 "Date ", cal.GetDate(),
49 "Ticks ", cal.GetDate().GetTicks(),
50 ))
51
f6bcfd97
BP
52#----------------------------------------------------------------------
53
54def runTest(frame, nb, log):
55 win = TestPanel(nb, -1, log)
56 return win
57
58#----------------------------------------------------------------------
59
60
61overview = """\
62<html><body>
95bfd958 63<h2>CalendarCtrl</h2>
f6bcfd97
BP
64
65Yet <i>another</i> calendar control. This one is a wrapper around the C++
66version described in the docs. This one will probably be a bit more efficient
67than the one in wxPython.lib.calendar, but I like a few things about it better,
68so I think both will stay in wxPython.
69"""
1fded56b
RD
70
71
1fded56b
RD
72if __name__ == '__main__':
73 import sys,os
74 import run
8eca4fef 75 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
1fded56b 76