-# test the calendar control in a dialog
-
-class CalenDlg(wxDialog):
- def __init__(self, parent, log):
- self.log = log
- wxDialog.__init__(self, parent, -1, "Test Calendar", wxPyDefaultPosition, wxSize(280, 300))
-
- start_month = 2
- start_year = 1999
-
-# get month list from DateTime
-
- monthlist = GetMonthList()
-
-# select the month
-
- self.date = wxComboBox(self, 100, Month[start_month], wxPoint(20, 20), wxSize(90, -1), monthlist, wxCB_DROPDOWN)
- EVT_COMBOBOX(self, 100, self.EvtComboBox)
-
-# alternate spin button to control the month
-
- h = self.date.GetSize().height
- self.m_spin = wxSpinButton(self, 120, wxPoint(120, 20), wxSize(h*2, h), wxSP_VERTICAL)
- self.m_spin.SetRange(1, 12)
- self.m_spin.SetValue(start_month)
-
- EVT_SPIN(self, 120, self.OnMonthSpin)
-
-# spin button to conrol the year
-
- self.dtext = wxTextCtrl(self, -1, str(start_year), wxPoint(160, 20), wxSize(60, -1))
- h = self.dtext.GetSize().height
-
- self.y_spin = wxSpinButton(self, 20, wxPoint(220, 20), wxSize(h*2, h), wxSP_VERTICAL)
- self.y_spin.SetRange(1980, 2010)
- self.y_spin.SetValue(start_year)
-
- EVT_SPIN(self, 20, self.OnYrSpin)
-
-# set the calendar and attributes
-
- self.calend = wxCalendar(self, -1, wxPoint(20, 60), wxSize(240, 200))
- self.calend.SetMonth(start_month)
- self.calend.SetYear(start_year)
-
- self.calend.HideTitle()
- self.calend.ShowWeekEnd()
-
- self.ResetDisplay()
-
- self.Connect(self.calend.GetId(), -1, 2100, self.MouseClick)
-
-# log the mouse clicks
-
- def MouseClick(self, evt):
- text = '%s CLICK %02d/%02d/%d' % (evt.click, evt.day, evt.month, evt.year) # format date
- self.log.WriteText('Date Selected: ' + text + '\n')
-
- if evt.click == 'DLEFT':
- self.EndModal(wxID_OK)
-
-# month and year spin selection routines
-
- def OnMonthSpin(self, event):
- month = event.GetPosition()
- if month >= 0 and month <= 12:
- self.date.SetValue(Month[month])
- self.calend.SetMonth(month)
- self.calend.Refresh()
-
- def OnYrSpin(self, event):
- year = event.GetPosition()
- self.dtext.SetValue(str(year))
- self.calend.SetYear(year)
- self.calend.Refresh()
-
- def EvtComboBox(self, event):
- name = event.GetString()
- self.log.WriteText('EvtComboBox: %s\n' % name)
- monthval = self.date.FindString(name)
- self.m_spin.SetValue(monthval+1)
-
- self.calend.SetMonth(monthval+1)
- self.ResetDisplay()
-
-# set the calendar for highlighted days
-
- def ResetDisplay(self):
- month = self.calend.GetMonth()
- try:
- set_days = test_days[month]
- except:
- set_days = [1, 5, 12]
-
- self.calend.AddSelect([4, 11], 'BLUE', 'WHITE')
-
- self.calend.SetSelDay(set_days)
- self.calend.Refresh()
-