wx.lib.calendar.CalenDlg, how to set the yearsrange?

Re: [wxPython-users] wx.lib.calendar.CalenDlg,how to set the yearsrange?
Bad news is I wrote that years ago and didn’t make it very reusable or anyway to override that.

I need to revisit someday and also use the newer wx.DateTime methods instead of my own code

For now you are best off to either create your own custom calendar.py module and modify that line 1175 for your new range

Or inherit the CalenDlg Class and override that init section with a copy of it

E.g

Import CalenDlg from calendar

class CalenDlgCustom(CalenDlg):

def __init__(self, parent, month=None, day = None, year=None):

    wx.Dialog.__init__(self, parent, -1, "Event Calendar", wx.DefaultPosition, (280, 360))

    self.result = None

   

    # set the calendar and attributes

    self.calend = Calendar(self, -1, (20, 60), (240, 200))

    if month == None:

        self.calend.SetCurrentDay()

        start_month = self.calend.GetMonth()

        start_year = self.calend.GetYear()

    else:

        self.calend.month = start_month = month

        self.calend.year = start_year = year

        self.calend.SetDayValue(day)

    self.calend.HideTitle()

    self.ResetDisplay()

    # get month list from DateTime

    monthlist = GetMonthList()

    # select the month

    self.date = wx.ComboBox(self, -1, Month[start_month], (20, 20), (90, -1),

                            monthlist, wx.CB_DROPDOWN)

    self.Bind(wx.EVT_COMBOBOX, self.EvtComboBox, self.date)

    # alternate spin button to control the month

    h = self.date.GetSize().height

    self.m_spin = wx.SpinButton(self, -1, (115, 20), (h*1.5, h), wx.SP_VERTICAL)

    self.m_spin.SetRange(1, 12)

    self.m_spin.SetValue(start_month)

    self.Bind(wx.EVT_SPIN, self.OnMonthSpin, self.m_spin)

    # spin button to control the year

    self.dtext = wx.TextCtrl(self, -1, str(start_year), (160, 20), (60, -1))

    h = self.dtext.GetSize().height

    self.y_spin = wx.SpinButton(self, -1, (225, 20), (h*1.5, h), wx.SP_VERTICAL)

    self.y_spin.SetRange(1900, 2010)                # modified code

    self.y_spin.SetValue(start_year)

    self.Bind(wx.EVT_SPIN, self.OnYrSpin, self.y_spin)

    self.Bind(EVT_CALENDAR, self.MouseClick, self.calend)

    x_pos = 50

    y_pos = 280

    but_size = (60, 25)

    btn = wx.Button(self, wx.ID_OK, ' Ok ', (x_pos, y_pos), but_size)

    self.Bind(wx.EVT_BUTTON, self.OnOk, btn)

    btn = wx.Button(self, wx.ID_CANCEL, ' Close ', (x_pos + 120, y_pos), but_size)

    self.Bind(wx.EVT_BUTTON, self.OnCancel, btn)