wx.adv.GenericCalendarCtrl¶
The calendar control allows the user to pick a date.
The user can move the current selection using the keyboard and select the date (generating EVT_CALENDAR
event) by pressing <Return>
or double clicking it.
Generic calendar has advanced possibilities for the customization of its display, described below. If you want to use these possibilities on every platform, use GenericCalendarCtrl instead of wx.adv.CalendarCtrl.
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.adv.CalendarDateAttr class.
An item without custom attributes is drawn with the default colours and font and without border, but setting custom attributes with SetAttr
allows modifying 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 using the wx.adv.CalendarDateAttr.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 EVT_CALENDAR_PAGE_CHANGED
event handler.
If neither the CAL_SUNDAY_FIRST
or CAL_MONDAY_FIRST
style is given, the first day of the week is determined from operating system’s settings, if possible. The native wxGTK calendar chooses the first weekday based on locale, and these styles have no effect on it.
Window Styles¶
This class supports the following styles:
wx.adv.CAL_SUNDAY_FIRST
: Show Sunday as the first day in the week (not in wxGTK)wx.adv.CAL_MONDAY_FIRST
: Show Monday as the first day in the week (not in wxGTK)wx.adv.CAL_SHOW_HOLIDAYS
: Highlight holidays in the calendar (only generic)wx.adv.CAL_NO_YEAR_CHANGE
: Disable the year changing (deprecated, only generic)wx.adv.CAL_NO_MONTH_CHANGE
: Disable the month (and, implicitly, the year) changingwx.adv.CAL_SHOW_SURROUNDING_WEEKS
: Show the neighbouring weeks in the previous and next months (only generic, always on for the native controls)wx.adv.CAL_SEQUENTIAL_MONTH_SELECTION
: Use alternative, more compact, style for the month and year selection controls. (only generic)wx.adv.CAL_SHOW_WEEK_NUMBERS
: Show week numbers on the left side of the calendar. (not in generic)
Events Emitted by this Class¶
Handlers bound for the following event types will receive a wx.adv.CalendarEvent parameter.
EVT_CALENDAR: A day was double clicked in the calendar.
EVT_CALENDAR_SEL_CHANGED: The selected date changed.
EVT_CALENDAR_PAGE_CHANGED: The selected month (and/or year) changed.
EVT_CALENDAR_WEEKDAY_CLICKED: User clicked on the week day header (only generic).
EVT_CALENDAR_WEEK_CLICKED: User clicked on the week of the year number (only generic).
Implementations:GTK, MSW ports; a generic implementation is used elsewhere.
Note
Changing the selected date will trigger an EVT_CALENDAR_DAY
, MONTH
or YEAR
event as well as an EVT_CALENDAR_SEL_CHANGED
event.
See also
Calendar Sample, wx.adv.CalendarDateAttr, wx.adv.CalendarEvent, wx.adv.DatePickerCtrl
Class Hierarchy¶
Methods Summary¶
Default constructor. |
|
Creates the control. |
|
This function should be used instead of changing |
|
This function should be used instead of changing |
|
Returns the attribute for the given date (should be in the range 1…31). |
|
Gets the currently selected date. |
|
Returns the limits currently being used. |
|
Gets the background colour of the header part of the calendar window. |
|
Gets the foreground colour of the header part of the calendar window. |
|
Gets the background highlight colour. |
|
Gets the foreground highlight colour. |
|
Return the background colour currently used for holiday highlighting. |
|
Return the foreground colour currently used for holiday highlighting. |
|
Returns one of CalendarHitTestResult constants and fills either date or wd pointer with the corresponding value depending on the hit test code. |
|
Mark or unmark the day. |
|
Return the date as a Python datetime.date object. |
|
Clears any attributes associated with the given day (in the range 1…31). |
|
Associates the attribute with the specified date (in the range 1…31). |
|
Sets the current date. |
|
Restrict the dates that can be selected in the control to the specified range. |
|
Set the colours used for painting the weekdays at the top of the control. |
|
Set the colours to be used for highlighting the currently selected date. |
|
Marks the specified day as being a holiday in the current month. |
|
Sets the colours to be used for the holidays highlighting. |
Properties Summary¶
See |
|
Class API¶
- class wx.adv.GenericCalendarCtrl(Control)¶
Possible constructors:
GenericCalendarCtrl() -> None GenericCalendarCtrl(parent, id=ID_ANY, date=DefaultDateTime, pos=DefaultPosition, size=DefaultSize, style=CAL_SHOW_HOLIDAYS, name=CalendarNameStr) -> None
The calendar control allows the user to pick a date.
Methods¶
- __init__(self, *args, **kw)¶
-
__init__ (self)
Default constructor.
- Return type:
None
__init__ (self, parent, id=ID_ANY, date=DefaultDateTime, pos=DefaultPosition, size=DefaultSize, style=CAL_SHOW_HOLIDAYS, name=CalendarNameStr)
Does the same as
Create
method.- Parameters:
parent (wx.Window)
id (wx.WindowID)
date (wx.DateTime)
pos (wx.Point)
size (wx.Size)
style (long)
name (string)
- Return type:
None
- Create(self, parent, id=ID_ANY, date=DefaultDateTime, pos=DefaultPosition, size=DefaultSize, style=CAL_SHOW_HOLIDAYS, name=CalendarNameStr)¶
Creates the control.
See
Window.__init__
for the meaning of the parameters and the control overview for the possible styles.- Parameters:
parent (wx.Window)
id (wx.WindowID)
date (wx.DateTime)
pos (wx.Point)
size (wx.Size)
style (long)
name (string)
- Return type:
bool
- EnableHolidayDisplay(self, display=True)¶
This function should be used instead of changing
CAL_SHOW_HOLIDAYS
style bit directly.It enables or disables the special highlighting of the holidays.
- Parameters:
display (bool)
- Return type:
None
- EnableMonthChange(self, enable=True)¶
This function should be used instead of changing
CAL_NO_MONTH_CHANGE
style bit.It allows or disallows the user to change the month interactively. Note that if the month cannot be changed, the year cannot be changed either.
- Parameters:
enable (bool)
- Return type:
bool
- Returns:
True
if the value of this option really changed orFalse
if it was already set to the requested value.
- EnableYearChange(self, enable=True)¶
This function should be used instead of changing
CAL_NO_YEAR_CHANGE
style bit directly. It allows or disallows the user to change the year interactively. Only in generic wx.adv.CalendarCtrl.- Parameters:
enable (bool)
- Return type:
None
- GetAttr(self, day)¶
Returns the attribute for the given date (should be in the range 1…31).
The returned pointer may be
None
. Only in generic wx.adv.CalendarCtrl.- Parameters:
day (int)
- Return type:
- static GetClassDefaultAttributes(variant=WINDOW_VARIANT_NORMAL)¶
- Parameters:
variant (WindowVariant)
- Return type:
VisualAttributes
- GetDate(self)¶
Gets the currently selected date.
- Return type:
DateTime
- GetDateRange(self)¶
Returns the limits currently being used.
- Return type:
le[bool, wx.DateTime, wx.DateTime]
- Returns:
True
if either limit is set,False
otherwise
See also
- GetHeaderColourBg(self)¶
Gets the background colour of the header part of the calendar window.
This method is currently only implemented in generic wx.adv.CalendarCtrl and always returns
NullColour
in the native versions.- Return type:
Colour
See also
- GetHeaderColourFg(self)¶
Gets the foreground colour of the header part of the calendar window.
This method is currently only implemented in generic wx.adv.CalendarCtrl and always returns
NullColour
in the native versions.- Return type:
Colour
See also
- GetHighlightColourBg(self)¶
Gets the background highlight colour.
Only in generic wx.adv.CalendarCtrl.
This method is currently only implemented in generic wx.adv.CalendarCtrl and always returns
NullColour
in the native versions.- Return type:
Colour
See also
- GetHighlightColourFg(self)¶
Gets the foreground highlight colour.
Only in generic wx.adv.CalendarCtrl.
This method is currently only implemented in generic wx.adv.CalendarCtrl and always returns
NullColour
in the native versions.- Return type:
Colour
See also
- GetHolidayColourBg(self)¶
Return the background colour currently used for holiday highlighting.
Only useful with generic wx.adv.CalendarCtrl as native versions currently don’t support holidays display at all and always return
NullColour
.- Return type:
Colour
See also
- GetHolidayColourFg(self)¶
Return the foreground colour currently used for holiday highlighting.
Only useful with generic wx.adv.CalendarCtrl as native versions currently don’t support holidays display at all and always return
NullColour
.- Return type:
Colour
See also
- HitTest(self, pos)¶
Returns one of CalendarHitTestResult constants and fills either date or wd pointer with the corresponding value depending on the hit test code.
Not implemented in wxGTK currently.
- Parameters:
pos (wx.Point)
- Return type:
le[CalendarHitTestResult, wx.DateTime, wx.DateTime.WeekDay]
- Mark(self, day, mark)¶
Mark or unmark the day.
This day of month will be marked in every month. In generic wx.adv.CalendarCtrl,
- Parameters:
day (int)
mark (bool)
- Return type:
None
- PyGetDate(self)¶
Return the date as a Python datetime.date object.
- ResetAttr(self, day)¶
Clears any attributes associated with the given day (in the range 1…31).
Only in generic wx.adv.CalendarCtrl.
- Parameters:
day (int)
- Return type:
None
- SetAttr(self, day, attr)¶
Associates the attribute with the specified date (in the range 1…31).
If the pointer is
None
, the items attribute is cleared. Only in generic wx.adv.CalendarCtrl.- Parameters:
day (int)
attr (wx.adv.CalendarDateAttr)
- Return type:
None
- SetDate(self, date)¶
Sets the current date.
The date parameter must be valid and in the currently valid range as set by
SetDateRange
, otherwise the current date is not changed and the function returnsFalse
and, additionally, triggers an assertion failure if the date is invalid.- Parameters:
date (wx.DateTime)
- Return type:
bool
- SetDateRange(self, lowerdate=DefaultDateTime, upperdate=DefaultDateTime)¶
Restrict the dates that can be selected in the control to the specified range.
If either date is set, the corresponding limit will be enforced and
True
returned. If none are set, the existing restrictions are removed andFalse
is returned.- Parameters:
lowerdate (wx.DateTime) – The low limit for the dates shown by the control or
wx.DefaultDateTime
.upperdate (wx.DateTime) – The high limit for the dates shown by the control or
wx.DefaultDateTime
.
- Return type:
bool
- Returns:
True
if either limit is valid,False
otherwise
See also
- SetHeaderColours(self, colFg, colBg)¶
Set the colours used for painting the weekdays at the top of the control.
This method is currently only implemented in generic wx.adv.CalendarCtrl and does nothing in the native versions.
- SetHighlightColours(self, colFg, colBg)¶
Set the colours to be used for highlighting the currently selected date.
This method is currently only implemented in generic wx.adv.CalendarCtrl and does nothing in the native versions.
- SetHoliday(self, day)¶
Marks the specified day as being a holiday in the current month.
This method is only implemented in the generic version of the control and does nothing in the native ones.
- Parameters:
day (int)
- Return type:
None
- SetHolidayColours(self, colFg, colBg)¶
Sets the colours to be used for the holidays highlighting.
This method is only implemented in the generic version of the control and does nothing in the native ones. It should also only be called if the window style includes
CAL_SHOW_HOLIDAYS
flag orEnableHolidayDisplay
had been called.
Properties¶
- DateRange¶
See
GetDateRange
andSetDateRange
- HeaderColourBg¶
- HeaderColourFg¶
- HighlightColourBg¶
- HighlightColourFg¶
- HolidayColourBg¶
- HolidayColourFg¶