1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG definitions for the wxCalendarCtrl
7 // Created: 23-May-2000
9 // Copyright: (c) 2000 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
17 #include "wx/wxPython/wxPython.h"
18 #include "wx/wxPython/pyclasses.h"
20 #include <wx/calctrl.h>
23 //----------------------------------------------------------------------
26 %pythoncode { wx = core }
28 %include _calendar_rename.i
30 //---------------------------------------------------------------------------
37 wxCAL_NO_MONTH_CHANGE,
38 wxCAL_SEQUENTIAL_MONTH_SELECTION,
39 wxCAL_SHOW_SURROUNDING_WEEKS,
43 enum wxCalendarHitTestResult
45 wxCAL_HITTEST_NOWHERE, // outside of anything
46 wxCAL_HITTEST_HEADER, // on the header (weekdays)
47 wxCAL_HITTEST_DAY, // on a day in the calendar
48 wxCAL_HITTEST_INCMONTH,
49 wxCAL_HITTEST_DECMONTH,
50 wxCAL_HITTEST_SURROUNDING_WEEK
53 // border types for a date
54 enum wxCalendarDateBorder
56 wxCAL_BORDER_NONE, // no border (default)
57 wxCAL_BORDER_SQUARE, // a rectangular border
58 wxCAL_BORDER_ROUND // a round border
61 //---------------------------------------------------------------------------
63 DocStr(wxCalendarDateAttr,
64 "A set of customization attributes for a calendar date, which can be used to
65 control the look of the Calendar object.");
67 class wxCalendarDateAttr
70 DocStr(wxCalendarDateAttr,
71 "Create a CalendarDateAttr.");
72 wxCalendarDateAttr(const wxColour& colText = wxNullColour,
73 const wxColour& colBack = wxNullColour,
74 const wxColour& colBorder = wxNullColour,
75 const wxFont& font = wxNullFont,
76 wxCalendarDateBorder border = wxCAL_BORDER_NONE);
80 void SetTextColour(const wxColour& colText);
81 void SetBackgroundColour(const wxColour& colBack);
82 void SetBorderColour(const wxColour& col);
83 void SetFont(const wxFont& font);
84 void SetBorder(wxCalendarDateBorder border);
85 void SetHoliday(bool holiday);
88 bool HasTextColour() const;
89 bool HasBackgroundColour() const;
90 bool HasBorderColour() const;
92 bool HasBorder() const;
94 bool IsHoliday() const;
96 wxColour GetTextColour() const;
97 wxColour GetBackgroundColour() const;
98 wxColour GetBorderColour() const;
99 wxFont GetFont() const;
100 wxCalendarDateBorder GetBorder() const;
103 //---------------------------------------------------------------------------
105 class wxCalendarCtrl;
107 class wxCalendarEvent : public wxCommandEvent
110 wxCalendarEvent(wxCalendarCtrl *cal, wxEventType type);
112 const wxDateTime GetDate() const;
113 void SetDate(const wxDateTime &date);
114 void SetWeekDay(const wxDateTime::WeekDay wd);
115 wxDateTime::WeekDay GetWeekDay() const;
120 %constant wxEventType wxEVT_CALENDAR_DOUBLECLICKED;
121 %constant wxEventType wxEVT_CALENDAR_SEL_CHANGED;
122 %constant wxEventType wxEVT_CALENDAR_DAY_CHANGED;
123 %constant wxEventType wxEVT_CALENDAR_MONTH_CHANGED;
124 %constant wxEventType wxEVT_CALENDAR_YEAR_CHANGED;
125 %constant wxEventType wxEVT_CALENDAR_WEEKDAY_CLICKED;
129 EVT_CALENDAR = wx.PyEventBinder( wxEVT_CALENDAR_DOUBLECLICKED, 1)
130 EVT_CALENDAR_SEL_CHANGED = wx.PyEventBinder( wxEVT_CALENDAR_SEL_CHANGED, 1)
131 EVT_CALENDAR_DAY = wx.PyEventBinder( wxEVT_CALENDAR_DAY_CHANGED, 1)
132 EVT_CALENDAR_MONTH = wx.PyEventBinder( wxEVT_CALENDAR_MONTH_CHANGED, 1)
133 EVT_CALENDAR_YEAR = wx.PyEventBinder( wxEVT_CALENDAR_YEAR_CHANGED, 1)
134 EVT_CALENDAR_WEEKDAY_CLICKED = wx.PyEventBinder( wxEVT_CALENDAR_WEEKDAY_CLICKED, 1)
138 //---------------------------------------------------------------------------
140 MAKE_CONST_WXSTRING(CalendarNameStr);
143 DocStr(wxCalendarCtrl,
144 "The calendar control allows the user to pick a date interactively.");
146 RefDoc(wxCalendarCtrl,
148 "The CalendarCtrl displays a window containing several parts: the control to
149 pick the month and the year at the top (either or both of them may be
150 disabled) and a month area below them which shows all the days in the
151 month. The user can move the current selection using the keyboard and select
152 the date (generating EVT_CALENDAR event) by pressing <Return> or double
155 It has advanced possibilities for the customization of its display. All global
156 settings (such as colours and fonts used) can, of course, be changed. But
157 also, the display style for each day in the month can be set independently
158 using CalendarDateAttr class.
160 An item without custom attributes is drawn with the default colours and font
161 and without border, but setting custom attributes with SetAttr allows to
162 modify its appearance. Just create a custom attribute object and set it for
163 the day you want to be displayed specially A day may be marked as being a
164 holiday, (even if it is not recognized as one by wx.DateTime) by using the
167 As the attributes are specified for each day, they may change when the month
168 is changed, so you will often want to update them in an EVT_CALENDAR_MONTH
172 CAL_SUNDAY_FIRST: Show Sunday as the first day in the week
173 CAL_MONDAY_FIRST: Show Monday as the first day in the week
174 CAL_SHOW_HOLIDAYS: Highlight holidays in the calendar
175 CAL_NO_YEAR_CHANGE: Disable the year changing
176 CAL_NO_MONTH_CHANGE: Disable the month (and, implicitly, the year) changing
177 CAL_SHOW_SURROUNDING_WEEKS: Show the neighbouring weeks in the previous and next months
178 CAL_SEQUENTIAL_MONTH_SELECTION: Use alternative, more compact, style for the month and year selection controls.
180 The default calendar style is wxCAL_SHOW_HOLIDAYS.
183 EVT_CALENDAR: A day was double clicked in the calendar.
184 EVT_CALENDAR_SEL_CHANGED: The selected date changed.
185 EVT_CALENDAR_DAY: The selected day changed.
186 EVT_CALENDAR_MONTH: The selected month changed.
187 EVT_CALENDAR_YEAR: The selected year changed.
188 EVT_CALENDAR_WEEKDAY_CLICKED: User clicked on the week day header
190 Note that changing the selected date will result in either of
191 EVT_CALENDAR_DAY, MONTH or YEAR events and an EVT_CALENDAR_SEL_CHANGED event.
196 class wxCalendarCtrl : public wxControl
199 %pythonAppend wxCalendarCtrl "self._setOORInfo(self)"
200 %pythonAppend wxCalendarCtrl() ""
202 DocStr(wxCalendarCtrl, "Create and show a calendar control.");
203 RefDoc(wxCalendarCtrl, ""); // turn it off for the ctors
205 wxCalendarCtrl(wxWindow *parent,
207 const wxDateTime& date = wxDefaultDateTime,
208 const wxPoint& pos = wxDefaultPosition,
209 const wxSize& size = wxDefaultSize,
210 long style = wxCAL_SHOW_HOLIDAYS | wxWANTS_CHARS,
211 const wxString& name = wxPyCalendarNameStr);
214 DocStr(wxCalendarCtrl(), "Precreate a CalendarCtrl for 2-phase creation.");
215 %name(PreCalendarCtrl)wxCalendarCtrl();
217 DocStr(Create, "Acutally create the GUI portion of the CalendarCtrl for 2-phase creation.");
218 bool Create(wxWindow *parent,
220 const wxDateTime& date = wxDefaultDateTime,
221 const wxPoint& pos = wxDefaultPosition,
222 const wxSize& size = wxDefaultSize,
223 long style = wxCAL_SHOW_HOLIDAYS | wxWANTS_CHARS,
224 const wxString& name = wxPyCalendarNameStr);
228 void, SetDate(const wxDateTime& date),
229 "Sets the current date.");
232 const wxDateTime&, GetDate() const,
233 "Gets the currently selected date.");
238 bool, SetLowerDateLimit(const wxDateTime& date = wxDefaultDateTime),
239 "set the range in which selection can occur");
242 bool, SetUpperDateLimit(const wxDateTime& date = wxDefaultDateTime),
243 "set the range in which selection can occur");
246 const wxDateTime&, GetLowerDateLimit() const,
247 "get the range in which selection can occur");
250 const wxDateTime&, GetUpperDateLimit() const,
251 "get the range in which selection can occur");
254 bool, SetDateRange(const wxDateTime& lowerdate = wxDefaultDateTime,
255 const wxDateTime& upperdate = wxDefaultDateTime),
256 "set the range in which selection can occur");
262 void, EnableYearChange(bool enable = True),
263 "This function should be used instead of changing CAL_NO_YEAR_CHANGE\n"
264 "style bit directly. It allows or disallows the user to change the year\n"
268 void, EnableMonthChange(bool enable = True),
269 "This function should be used instead of changing CAL_NO_MONTH_CHANGE style\n"
270 "bit. It allows or disallows the user to change the month interactively. Note\n"
271 "that if the month can not be changed, the year can not be changed either.");
274 void, EnableHolidayDisplay(bool display = True),
275 "This function should be used instead of changing CAL_SHOW_HOLIDAYS style\n"
276 "bit directly. It enables or disables the special highlighting of the holidays.");
281 void, SetHeaderColours(const wxColour& colFg, const wxColour& colBg),
282 "header colours are used for painting the weekdays at the top");
285 wxColour, GetHeaderColourFg() const,
286 "header colours are used for painting the weekdays at the top");
289 wxColour, GetHeaderColourBg() const,
290 "header colours are used for painting the weekdays at the top");
295 void, SetHighlightColours(const wxColour& colFg, const wxColour& colBg),
296 "highlight colour is used for the currently selected date");
299 wxColour, GetHighlightColourFg() const,
300 "highlight colour is used for the currently selected date");
303 wxColour, GetHighlightColourBg() const,
304 "highlight colour is used for the currently selected date");
309 void, SetHolidayColours(const wxColour& colFg, const wxColour& colBg),
310 "holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is used)");
313 wxColour, GetHolidayColourFg() const,
314 "holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is used)");
317 wxColour, GetHolidayColourBg() const,
318 "holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is used)");
323 wxCalendarDateAttr*, GetAttr(size_t day) const,
324 "Returns the attribute for the given date (should be in the range 1...31).\n"
325 "The returned value may be None");
328 void, SetAttr(size_t day, wxCalendarDateAttr *attr),
329 "Associates the attribute with the specified date (in the range 1...31).\n"
330 "If the attribute passed is None, the items attribute is cleared.");
333 void, SetHoliday(size_t day),
334 "Marks the specified day as being a holiday in the current month.");
337 void, ResetAttr(size_t day),
338 "Clears any attributes associated with the given day (in the range 1...31).");
343 "HitTest(Point pos) -> (result, date, weekday)",
344 "Returns 3-tuple with information about the given position on the calendar
345 control. The first value of the tuple is a result code and determines the
346 validity of the remaining two values. The result codes are:
348 CAL_HITTEST_NOWHERE: hit outside of anything
349 CAL_HITTEST_HEADER: hit on the header, weekday is valid
350 CAL_HITTEST_DAY: hit on a day in the calendar, date is set.
353 PyObject* HitTest(const wxPoint& pos) {
354 wxDateTime* date = new wxDateTime;
355 wxDateTime::WeekDay wd;
356 wxCalendarHitTestResult result = self->HitTest(pos, date, &wd);
357 bool blocked = wxPyBeginBlockThreads();
358 PyObject* tup = PyTuple_New(3);
359 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(result));
360 PyTuple_SET_ITEM(tup, 1, wxPyConstructObject(date, wxT("wxDateTime"), 1));
361 PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(wd));
362 wxPyEndBlockThreads(blocked);
368 wxControl*, GetMonthControl() const,
369 "get the currently shown control for month");
372 wxControl*, GetYearControl() const,
373 "get the currently shown control for year");
377 //---------------------------------------------------------------------------
382 //---------------------------------------------------------------------------