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 wxCalendarCtrl(wxWindow *parent,
205 const wxDateTime& date = wxDefaultDateTime,
206 const wxPoint& pos = wxDefaultPosition,
207 const wxSize& size = wxDefaultSize,
208 long style = wxCAL_SHOW_HOLIDAYS | wxWANTS_CHARS,
209 const wxString& name = wxPyCalendarNameStr);
212 DocStr(wxCalendarCtrl(), "Precreate a CalendarCtrl for 2-phase creation.");
213 %name(PreCalendarCtrl)wxCalendarCtrl();
215 DocStr(Create, "Acutally create the GUI portion of the CalendarCtrl for 2-phase creation.");
216 bool Create(wxWindow *parent,
218 const wxDateTime& date = wxDefaultDateTime,
219 const wxPoint& pos = wxDefaultPosition,
220 const wxSize& size = wxDefaultSize,
221 long style = wxCAL_SHOW_HOLIDAYS | wxWANTS_CHARS,
222 const wxString& name = wxPyCalendarNameStr);
226 void, SetDate(const wxDateTime& date),
227 "Sets the current date.");
230 const wxDateTime&, GetDate() const,
231 "Gets the currently selected date.");
236 bool, SetLowerDateLimit(const wxDateTime& date = wxDefaultDateTime),
237 "set the range in which selection can occur");
240 bool, SetUpperDateLimit(const wxDateTime& date = wxDefaultDateTime),
241 "set the range in which selection can occur");
244 const wxDateTime&, GetLowerDateLimit() const,
245 "get the range in which selection can occur");
248 const wxDateTime&, GetUpperDateLimit() const,
249 "get the range in which selection can occur");
252 bool, SetDateRange(const wxDateTime& lowerdate = wxDefaultDateTime,
253 const wxDateTime& upperdate = wxDefaultDateTime),
254 "set the range in which selection can occur");
260 void, EnableYearChange(bool enable = True),
261 "This function should be used instead of changing CAL_NO_YEAR_CHANGE\n"
262 "style bit directly. It allows or disallows the user to change the year\n"
266 void, EnableMonthChange(bool enable = True),
267 "This function should be used instead of changing CAL_NO_MONTH_CHANGE style\n"
268 "bit. It allows or disallows the user to change the month interactively. Note\n"
269 "that if the month can not be changed, the year can not be changed either.");
272 void, EnableHolidayDisplay(bool display = True),
273 "This function should be used instead of changing CAL_SHOW_HOLIDAYS style\n"
274 "bit directly. It enables or disables the special highlighting of the holidays.");
279 void, SetHeaderColours(const wxColour& colFg, const wxColour& colBg),
280 "header colours are used for painting the weekdays at the top");
283 wxColour, GetHeaderColourFg() const,
284 "header colours are used for painting the weekdays at the top");
287 wxColour, GetHeaderColourBg() const,
288 "header colours are used for painting the weekdays at the top");
293 void, SetHighlightColours(const wxColour& colFg, const wxColour& colBg),
294 "highlight colour is used for the currently selected date");
297 wxColour, GetHighlightColourFg() const,
298 "highlight colour is used for the currently selected date");
301 wxColour, GetHighlightColourBg() const,
302 "highlight colour is used for the currently selected date");
307 void, SetHolidayColours(const wxColour& colFg, const wxColour& colBg),
308 "holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is used)");
311 wxColour, GetHolidayColourFg() const,
312 "holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is used)");
315 wxColour, GetHolidayColourBg() const,
316 "holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is used)");
321 wxCalendarDateAttr*, GetAttr(size_t day) const,
322 "Returns the attribute for the given date (should be in the range 1...31).\n"
323 "The returned value may be None");
326 void, SetAttr(size_t day, wxCalendarDateAttr *attr),
327 "Associates the attribute with the specified date (in the range 1...31).\n"
328 "If the attribute passed is None, the items attribute is cleared.");
331 void, SetHoliday(size_t day),
332 "Marks the specified day as being a holiday in the current month.");
335 void, ResetAttr(size_t day),
336 "Clears any attributes associated with the given day (in the range 1...31).");
341 "HitTest(Point pos) -> (result, date, weekday)",
342 "Returns 3-tuple with information about the given position on the calendar
343 control. The first value of the tuple is a result code and determines the
344 validity of the remaining two values. The result codes are:
346 CAL_HITTEST_NOWHERE: hit outside of anything
347 CAL_HITTEST_HEADER: hit on the header, weekday is valid
348 CAL_HITTEST_DAY: hit on a day in the calendar, date is set.
351 PyObject* HitTest(const wxPoint& pos) {
352 wxDateTime* date = new wxDateTime;
353 wxDateTime::WeekDay wd;
354 wxCalendarHitTestResult result = self->HitTest(pos, date, &wd);
355 bool blocked = wxPyBeginBlockThreads();
356 PyObject* tup = PyTuple_New(3);
357 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(result));
358 PyTuple_SET_ITEM(tup, 1, wxPyConstructObject(date, wxT("wxDateTime"), 1));
359 PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(wd));
360 wxPyEndBlockThreads(blocked);
366 wxControl*, GetMonthControl() const,
367 "get the currently shown control for month");
370 wxControl*, GetYearControl() const,
371 "get the currently shown control for year");
375 //---------------------------------------------------------------------------
380 //---------------------------------------------------------------------------