************************ wx.calendar.CalendarCtrl ************************ Inheritance diagram for `wx.calendar.CalendarCtrl`: | .. inheritance-diagram:: wx.calendar.CalendarCtrl | Description =========== The calendar control allows the user to pick a date. For this, it displays a window containing several parts: a control at the top to pick the month and the year (either or both of them may be disabled), and a month area below them which shows all the days in the month. The user can move the current selection using the keyboard and select the date (generating ``wx.calendar.EVT_CALENDAR`` event) by pressing ``Return`` or double clicking it. It has advanced possibilities for the customization of its display. All global settings (such as colours and fonts used) can, of course, be changed. But also, the display style for each day in the month can be set independently using `wx.calendar.CalendarDateAttr `_ class. An item without custom attributes is drawn with the default colours and font and without border, but setting custom attributes with `SetAttr <#SetAttr>`_ allows to modify its appearance. Just create a custom attribute object and set it for the day you want to be displayed specially (note that the control will take ownership of the pointer, i.e. it will delete it itself). A day may be marked as being a holiday, even if it is not recognized as one by `wx.DateTime <../Widgets/wx.DateTime.html>`_ using `SetHoliday <#SetHoliday>`_ method. As the attributes are specified for each day, they may change when the month is changed, so you will often want to update them in ``wx.calendar.EVT_CALENDAR_MONTH`` event handler. .. seealso:: `wx.CalendarDateAttr `_, `wx.calendar.CalendarEvent <../Events/wx.calendar.CalendarEvent.html>`_ Derived From ^^^^^^^^^^^^^ * `wx.Control <../Widgets/wx.Control.html>`_ * `wx.Window <../Widgets/wx.Window.html>`_ * `wx.EvtHandler <../Widgets/wx.EvtHandler.html>`_ * `wx.Object <../Widgets/wx.Object.html>`_ Window Styles ^^^^^^^^^^^^^ ================================================== ================================================== Window Style Description ================================================== ================================================== ``wx.calendar.CAL_SUNDAY_FIRST`` Show Sunday as the first day in the week ``wx.calendar.CAL_MONDAY_FIRST`` Show Monday as the first day in the week ``wx.calendar.CAL_SHOW_HOLIDAYS`` Highlight holidays in the calendar ``wx.calendar.CAL_NO_YEAR_CHANGE`` Disable the year changing ``wx.calendar.CAL_NO_MONTH_CHANGE`` Disable the month (and, implicitly, the year) changing ``wx.calendar.CAL_SHOW_SURROUNDING_WEEKS`` Show the neighbouring weeks in the previous and next months ``wx.calendar.CAL_SEQUENTIAL_MONTH_SELECTION`` Use alternative, more compact, style for the month and year selection controls. ================================================== ================================================== Event Handling ^^^^^^^^^^^^^^ To process input from a calendar control, use these event handler macros to direct input to member functions that take a `wx.calendar.CalendarEvent <../Events/wx.calendar.CalendarEvent.html>`_ argument. ================================================== ================================================== Event Name Description ================================================== ================================================== wx.calendar.EVT_CALENDAR(id, func) A day was double clicked in the calendar. wx.calendar.EVT_CALENDAR_SEL_CHANGED(id, func) The selected date changed. wx.calendar.EVT_CALENDAR_DAY(id, func) The selected day changed. wx.calendar.EVT_CALENDAR_MONTH(id, func) The selected month changed. wx.calendar.EVT_CALENDAR_YEAR(id, func) The selected year changed. wx.calendar.EVT_CALENDAR_WEEKDAY_CLICKED(id, func) User clicked on the week day header. ================================================== ================================================== .. note:: Note that changing the selected date will result in either of ``wx.calendar.EVT_CALENDAR_DAY``, ``MONTH`` or ``YEAR`` events and ``wx.calendar.EVT_CALENDAR_SEL_CHANGED`` one. | Control Appearance ^^^^^^^^^^^^^^^^^^ | .. figure:: ../images/wxWidgets/wxmsw/calendarctrl.png :alt: wxMSW :figclass: floatleft **wxMSW** .. figure:: ../images/wxWidgets/wxmac/calendarctrl.png :alt: wxMAC :figclass: floatright **wxMAC** .. figure:: ../images/wxWidgets/wxgtk/calendarctrl.png :alt: wxGTK :figclass: floatcenter **wxGTK** | Methods Summary ^^^^^^^^^^^^^^^ * `__init__ <#__init__>`_ * `Create <#Create>`_ * `EnableHolidayDisplay <#EnableHolidayDisplay>`_ * `EnableMonthChange <#EnableMonthChange>`_ * `EnableYearChange <#EnableYearChange>`_ * `GetAttr <#GetAttr>`_ * `GetDate <#GetDate>`_ * `GetHeaderColourBg <#GetHeaderColourBg>`_ * `GetHeaderColourFg <#GetHeaderColourFg>`_ * `GetHighlightColourBg <#GetHighlightColourBg>`_ * `GetHighlightColourFg <#GetHighlightColourFg>`_ * `GetHolidayColourBg <#GetHolidayColourBg>`_ * `GetHolidayColourFg <#GetHolidayColourFg>`_ * `GetLowerDateLimit <#GetLowerDateLimit>`_ * `GetMonthControl <#GetMonthControl>`_ * `GetUpperDateLimit <#GetUpperDateLimit>`_ * `GetYearControl <#GetYearControl>`_ * `HitTest <#HitTest>`_ * `PyGetDate <#PyGetDate>`_ * `PyGetLowerDateLimit <#PyGetLowerDateLimit>`_ * `PyGetUpperDateLimit <#PyGetUpperDateLimit>`_ * `PySetDate <#PySetDate>`_ * `PySetDateRange <#PySetDateRange>`_ * `PySetLowerDateLimit <#PySetLowerDateLimit>`_ * `PySetUpperDateLimit <#PySetUpperDateLimit>`_ * `ResetAttr <#ResetAttr>`_ * `SetAttr <#SetAttr>`_ * `SetDate <#SetDate>`_ * `SetDateRange <#SetDateRange>`_ * `SetHeaderColours <#SetHeaderColours>`_ * `SetHighlightColours <#SetHighlightColours>`_ * `SetHoliday <#SetHoliday>`_ * `SetHolidayColours <#SetHolidayColours>`_ * `SetLowerDateLimit <#SetLowerDateLimit>`_ * `SetUpperDateLimit <#SetUpperDateLimit>`_ Properties Summary ^^^^^^^^^^^^^^^^^^ * `Date <#Date>`_ * `HeaderColourBg <#HeaderColourBg>`_ * `HeaderColourFg <#HeaderColourFg>`_ * `HighlightColourBg <#HighlightColourBg>`_ * `HighlightColourFg <#HighlightColourFg>`_ * `HolidayColourBg <#HolidayColourBg>`_ * `HolidayColourFg <#HolidayColourFg>`_ * `LowerDateLimit <#LowerDateLimit>`_ * `MonthControl <#MonthControl>`_ * `UpperDateLimit <#UpperDateLimit>`_ * `YearControl <#YearControl>`_ Class API ========= Methods ^^^^^^^ .. method:: __init__(parent, id=-1, date=wx.DefaultDateTime, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.calendar.CAL_SHOW_HOLIDAYS|wx.WANTS_CHARS, name=CalendarNameStr) Create and show a calendar control. **Parameters:** * `parent` (`wx.Window <../Widgets/wx.Window.html>`_) * `id` (int) * `date` (`wx.DateTime <../Widgets/wx.DateTime.html>`_) * `pos` (`wx.Point <../Widgets/wx.Point.html>`_) * `size` (`wx.Size <../Widgets/wx.Size.html>`_) * `style` (long) * `name` (string) | **Returns:** `wx.calendar.CalendarCtrl `_ -------- .. method:: Create(parent, id=-1, date=wx.DefaultDateTime, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.calendar.CAL_SHOW_HOLIDAYS|wx.WANTS_CHARS, name=CalendarNameStr) Creates the control. See `wx.Window <../Widgets/wx.Window.html>`_ for the meaning of the parameters and the control overview for the possible styles. **Parameters:** * `parent` (`wx.Window <../Widgets/wx.Window.html>`_) * `id` (int) * `date` (`wx.DateTime <../Widgets/wx.DateTime.html>`_) * `pos` (`wx.Point <../Widgets/wx.Point.html>`_) * `size` (`wx.Size <../Widgets/wx.Size.html>`_) * `style` (long) * `name` (string) | **Returns:** `bool` -------- .. method:: EnableHolidayDisplay(display=True) This function should be used instead of changing ``wx.calendar.CAL_SHOW_HOLIDAYS`` style bit directly. It enables or disables the special highlighting of the holidays. **Parameters:** * `display` (bool) -------- .. method:: EnableMonthChange(enable=True) This function should be used instead of changing ``wx.calendar.CAL_NO_MONTH_CHANGE`` style bit. It allows or disallows the user to change the month interactively. **Parameters:** * `enable` (bool) .. note:: Note that if the month can not be changed, the year can not be changed neither. -------- .. method:: EnableYearChange(enable=True) This function should be used instead of changing ``wx.calendar.CAL_NO_YEAR_CHANGE`` style bit directly. It allows or disallows the user to change the year interactively. **Parameters:** * `enable` (bool) -------- .. method:: GetAttr(day) Returns the attribute for the given date (should be in the range 1...31). The returned pointer may be ``None``. **Parameters:** * `day` (long) | **Returns:** `wx.calendar.CalendarDateAttr `_ -------- .. method:: GetDate() Gets the currently selected date. | **Returns:** `wx.DateTime <../Widgets/wx.DateTime.html>`_ -------- .. method:: GetHeaderColourBg() Gets the background colour of the header part of the calendar window. | **Returns:** `wx.Colour <../Widgets/wx.Colour.html>`_ .. seealso:: `SetHeaderColours <#SetHeaderColours>`_ -------- .. method:: GetHeaderColourFg() Gets the foreground colour of the header part of the calendar window. | **Returns:** `wx.Colour <../Widgets/wx.Colour.html>`_ .. seealso:: `SetHeaderColours <#SetHeaderColours>`_ -------- .. method:: GetHighlightColourBg() Gets the background highlight colour. | **Returns:** `wx.Colour <../Widgets/wx.Colour.html>`_ .. seealso:: `SetHighlightColours <#SetHighlightColours>`_ -------- .. method:: GetHighlightColourFg() Gets the foreground highlight colour. | **Returns:** `wx.Colour <../Widgets/wx.Colour.html>`_ .. seealso:: `SetHighlightColours <#SetHighlightColours>`_ -------- .. method:: GetHolidayColourBg() Return the background colour currently used for holiday highlighting. | **Returns:** `wx.Colour <../Widgets/wx.Colour.html>`_ .. seealso:: `SetHolidayColours <#SetHolidayColours>`_ -------- .. method:: GetHolidayColourFg() Return the foreground colour currently used for holiday highlighting. | **Returns:** `wx.Colour <../Widgets/wx.Colour.html>`_ .. seealso:: `SetHolidayColours <#SetHolidayColours>`_ -------- .. method:: GetLowerDateLimit() Get the range in which selection can occur. | **Returns:** `wx.DateTime <../Widgets/wx.DateTime.html>`_ -------- .. method:: GetMonthControl() Get the currently shown control for month. | **Returns:** `wx.Control <../Widgets/wx.Control.html>`_ -------- .. method:: GetUpperDateLimit() Get the range in which selection can occur. | **Returns:** `wx.DateTime <../Widgets/wx.DateTime.html>`_ -------- .. method:: GetYearControl() Get the currently shown control for year. | **Returns:** `wx.Control <../Widgets/wx.Control.html>`_ -------- .. method:: HitTest(pos) Returns 3-tuple with information about the given position on the calendar control. **Parameters:** * `pos` (`wx.Point <../Widgets/wx.Point.html>`_): The position to test. | The first value of the tuple is a result code and determines the validity of the remaining two values. The result codes are: ===================================== ===================================== HitTest Result Flags Description ===================================== ===================================== ``wx.calendar.CAL_HITTEST_NOWHERE`` Hit outside of anything. ``wx.calendar.CAL_HITTEST_HEADER`` Hit on the header, weekday is valid. ``wx.calendar.CAL_HITTEST_DAY`` Hit on a day in the calendar, date is set. ===================================== ===================================== | **Returns:** `(result, date, weekday)` -------- .. method:: PyGetDate() Same as `GetDate <#GetDate>`_, but returns a `datetime.date` object. | **Returns:** `datetime.date `_ -------- .. method:: PyGetLowerDateLimit() Same as `GetLowerDateLimit <#GetLowerDateLimit>`_, but returns a `datetime.date` object. | **Returns:** `datetime.date `_ -------- .. method:: PyGetUpperDateLimit() Same as `GetUpperDateLimit <#GetUpperDateLimit>`_, but returns a `datetime.date` object. | **Returns:** `datetime.date `_ -------- .. method:: PySetDate(date) Same as `SetDate <#SetDate>`_, but takes a `datetime.date` object in input. **Parameters:** * `date` (`datetime.date `_) -------- .. method:: PySetDateRange(lowerdate, upperdate) Same as `SetDateRange <#SetDateRange>`_, but takes a `datetime.datetime` or `datetime.date` objects in input. **Parameters:** * `lowerdate` (`datetime.date `_) * `upperdate` (`datetime.date `_) -------- .. method:: PySetLowerDateLimit(date) Same as `SetLowerDateLimit <#SetLowerDateLimit>`_, but takes a `datetime.datetime` or `datetime.date` object in input. **Parameters:** * `date` (`datetime.date `_) -------- .. method:: PySetUpperDateLimit(date) Same as `SetUpperDateLimit <#SetUpperDateLimit>`_, but takes a `datetime.datetime` or `datetime.date` object in input. **Parameters:** * `date` (`datetime.date `_) -------- .. method:: ResetAttr(day) Clears any attributes associated with the given day (in the range 1...31). **Parameters:** * `day` (long) -------- .. method:: SetAttr(day, attr) Associates the attribute with the specified date (in the range 1...31). If the pointer is ``None``, the items attribute is cleared. **Parameters:** * `day` (long) * `attr` (`wx.calendar.CalendarDateAttr `_) -------- .. method:: SetDate(date) Sets the current date. **Parameters:** * `date` (`wx.DateTime <../Widgets/wx.DateTime.html>`_) -------- .. method:: SetDateRange(lowerdate=wx.DefaultDateTime, upperdate=wx.DefaultDateTime) Set the range in which selection can occur. **Parameters:** * `lowerdate` (`wx.DateTime <../Widgets/wx.DateTime.html>`_) * `upperdate` (`wx.DateTime <../Widgets/wx.DateTime.html>`_) | **Returns:** `bool` -------- .. method:: SetHeaderColours(colFg, colBg) Set the colours used for painting the weekdays at the top of the control. **Parameters:** * `colFg` (`wx.Colour <../Widgets/wx.Colour.html>`_) * `colBg` (`wx.Colour <../Widgets/wx.Colour.html>`_) -------- .. method:: SetHighlightColours(colFg, colBg) Set the colours to be used for highlighting the currently selected date. **Parameters:** * `colFg` (`wx.Colour <../Widgets/wx.Colour.html>`_) * `colBg` (`wx.Colour <../Widgets/wx.Colour.html>`_) -------- .. method:: SetHoliday(day) Marks the specified day as being a holiday in the current month. **Parameters:** * `day` (long) -------- .. method:: SetHolidayColours(colFg, colBg) Sets the colours to be used for the holidays highlighting (only used if the window style includes ``wx.calendar.CAL_SHOW_HOLIDAYS`` flag). **Parameters:** * `colFg` (`wx.Colour <../Widgets/wx.Colour.html>`_) * `colBg` (`wx.Colour <../Widgets/wx.Colour.html>`_) -------- .. method:: SetLowerDateLimit(date=wx.DefaultDateTime) set the range in which selection can occur **Parameters:** * `date` (`wx.DateTime <../Widgets/wx.DateTime.html>`_) | **Returns:** `bool` -------- .. method:: SetUpperDateLimit(date=wx.DefaultDateTime) set the range in which selection can occur **Parameters:** * `date` (`wx.DateTime <../Widgets/wx.DateTime.html>`_) | **Returns:** `bool` -------- Properties ^^^^^^^^^^ .. attribute:: Date See `GetDate <#GetDate>`_ and `SetDate <#SetDate>`_ .. attribute:: HeaderColourBg See `GetHeaderColourBg <#GetHeaderColourBg>`_ .. attribute:: HeaderColourFg See `GetHeaderColourFg <#GetHeaderColourFg>`_ .. attribute:: HighlightColourBg See `GetHighlightColourBg <#GetHighlightColourBg>`_ .. attribute:: HighlightColourFg See `GetHighlightColourFg <#GetHighlightColourFg>`_ .. attribute:: HolidayColourBg See `GetHolidayColourBg <#GetHolidayColourBg>`_ .. attribute:: HolidayColourFg See `GetHolidayColourFg <#GetHolidayColourFg>`_ .. attribute:: LowerDateLimit See `GetLowerDateLimit <#GetLowerDateLimit>`_ and `SetLowerDateLimit <#SetLowerDateLimit>`_ .. attribute:: MonthControl See `GetMonthControl <#GetMonthControl>`_ .. attribute:: UpperDateLimit See `GetUpperDateLimit <#GetUpperDateLimit>`_ and `SetUpperDateLimit <#SetUpperDateLimit>`_ .. attribute:: YearControl See `GetYearControl <#GetYearControl>`_