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 /////////////////////////////////////////////////////////////////////////////
14 "Classes for an interactive Calendar control."
17 %module(package="wx", docstring=DOCSTRING) calendar
21 #include "wx/wxPython/wxPython.h"
22 #include "wx/wxPython/pyclasses.h"
24 #include <wx/calctrl.h>
27 //----------------------------------------------------------------------
30 %pythoncode { wx = _core }
31 %pythoncode { __docfilter__ = wx.__DocFilter(globals()) }
33 //---------------------------------------------------------------------------
40 wxCAL_NO_MONTH_CHANGE,
41 wxCAL_SEQUENTIAL_MONTH_SELECTION,
42 wxCAL_SHOW_SURROUNDING_WEEKS,
46 enum wxCalendarHitTestResult
48 wxCAL_HITTEST_NOWHERE, // outside of anything
49 wxCAL_HITTEST_HEADER, // on the header (weekdays)
50 wxCAL_HITTEST_DAY, // on a day in the calendar
51 wxCAL_HITTEST_INCMONTH,
52 wxCAL_HITTEST_DECMONTH,
53 wxCAL_HITTEST_SURROUNDING_WEEK
56 // border types for a date
57 enum wxCalendarDateBorder
59 wxCAL_BORDER_NONE, // no border (default)
60 wxCAL_BORDER_SQUARE, // a rectangular border
61 wxCAL_BORDER_ROUND // a round border
64 //---------------------------------------------------------------------------
66 DocStr(wxCalendarDateAttr,
67 "A set of customization attributes for a calendar date, which can be
68 used to control the look of the Calendar object.", "");
70 class wxCalendarDateAttr
73 DocStr(wxCalendarDateAttr,
74 "Create a CalendarDateAttr.", "");
75 wxCalendarDateAttr(const wxColour& colText = wxNullColour,
76 const wxColour& colBack = wxNullColour,
77 const wxColour& colBorder = wxNullColour,
78 const wxFont& font = wxNullFont,
79 wxCalendarDateBorder border = wxCAL_BORDER_NONE);
83 void SetTextColour(const wxColour& colText);
84 void SetBackgroundColour(const wxColour& colBack);
85 void SetBorderColour(const wxColour& col);
86 void SetFont(const wxFont& font);
87 void SetBorder(wxCalendarDateBorder border);
88 void SetHoliday(bool holiday);
91 bool HasTextColour() const;
92 bool HasBackgroundColour() const;
93 bool HasBorderColour() const;
95 bool HasBorder() const;
97 bool IsHoliday() const;
99 wxColour GetTextColour() const;
100 wxColour GetBackgroundColour() const;
101 wxColour GetBorderColour() const;
102 wxFont GetFont() const;
103 wxCalendarDateBorder GetBorder() const;
106 //---------------------------------------------------------------------------
108 class wxCalendarCtrl;
110 class wxCalendarEvent : public wxDateEvent
113 wxCalendarEvent(wxCalendarCtrl *cal, wxEventType type);
115 void SetWeekDay(const wxDateTime::WeekDay wd);
116 wxDateTime::WeekDay GetWeekDay() const;
119 def PySetDate(self, date):
120 """takes datetime.datetime or datetime.date object"""
121 self.SetDate(_pydate2wxdate(date))
124 """returns datetime.date object"""
125 return _wxdate2pydate(self.GetDate())
130 %constant wxEventType wxEVT_CALENDAR_DOUBLECLICKED;
131 %constant wxEventType wxEVT_CALENDAR_SEL_CHANGED;
132 %constant wxEventType wxEVT_CALENDAR_DAY_CHANGED;
133 %constant wxEventType wxEVT_CALENDAR_MONTH_CHANGED;
134 %constant wxEventType wxEVT_CALENDAR_YEAR_CHANGED;
135 %constant wxEventType wxEVT_CALENDAR_WEEKDAY_CLICKED;
139 EVT_CALENDAR = wx.PyEventBinder( wxEVT_CALENDAR_DOUBLECLICKED, 1)
140 EVT_CALENDAR_SEL_CHANGED = wx.PyEventBinder( wxEVT_CALENDAR_SEL_CHANGED, 1)
141 EVT_CALENDAR_DAY = wx.PyEventBinder( wxEVT_CALENDAR_DAY_CHANGED, 1)
142 EVT_CALENDAR_MONTH = wx.PyEventBinder( wxEVT_CALENDAR_MONTH_CHANGED, 1)
143 EVT_CALENDAR_YEAR = wx.PyEventBinder( wxEVT_CALENDAR_YEAR_CHANGED, 1)
144 EVT_CALENDAR_WEEKDAY_CLICKED = wx.PyEventBinder( wxEVT_CALENDAR_WEEKDAY_CLICKED, 1)
148 //---------------------------------------------------------------------------
150 MAKE_CONST_WXSTRING(CalendarNameStr);
153 DocStr(wxCalendarCtrl,
154 "The calendar control allows the user to pick a date interactively.
156 The CalendarCtrl displays a window containing several parts: the
157 control to pick the month and the year at the top (either or both of
158 them may be disabled) and a month area below them which shows all the
159 days in the month. The user can move the current selection using the
160 keyboard and select the date (generating EVT_CALENDAR event) by
161 pressing <Return> or double clicking it.
163 It has advanced possibilities for the customization of its
164 display. All global settings (such as colours and fonts used) can, of
165 course, be changed. But also, the display style for each day in the
166 month can be set independently using CalendarDateAttr class.
168 An item without custom attributes is drawn with the default colours
169 and font and without border, but setting custom attributes with
170 SetAttr allows to modify its appearance. Just create a custom
171 attribute object and set it for the day you want to be displayed
172 specially A day may be marked as being a holiday, (even if it is not
173 recognized as one by `wx.DateTime`) by using the SetHoliday method.
175 As the attributes are specified for each day, they may change when the
176 month is changed, so you will often want to update them in an
177 EVT_CALENDAR_MONTH event handler.", "
181 ============================== ============================
182 CAL_SUNDAY_FIRST Show Sunday as the first day
184 CAL_MONDAY_FIRST Show Monday as the first day
186 CAL_SHOW_HOLIDAYS Highlight holidays in the
188 CAL_NO_YEAR_CHANGE Disable the year changing
189 CAL_NO_MONTH_CHANGE Disable the month (and,
190 implicitly, the year) changing
191 CAL_SHOW_SURROUNDING_WEEKS Show the neighbouring weeks in
192 the previous and next months
193 CAL_SEQUENTIAL_MONTH_SELECTION Use alternative, more compact,
194 style for the month and year
196 ============================== ============================
198 The default calendar style is CAL_SHOW_HOLIDAYS.
202 ============================= ==============================
203 EVT_CALENDAR A day was double clicked in the
205 EVT_CALENDAR_SEL_CHANGED The selected date changed.
206 EVT_CALENDAR_DAY The selected day changed.
207 EVT_CALENDAR_MONTH The selected month changed.
208 EVT_CALENDAR_YEAR The selected year changed.
209 EVT_CALENDAR_WEEKDAY_CLICKED User clicked on the week day
211 ============================= ==============================
213 Note that changing the selected date will result in one of
214 EVT_CALENDAR_DAY, MONTH or YEAR events and an EVT_CALENDAR_SEL_CHANGED
220 MustHaveApp(wxCalendarCtrl);
222 class wxCalendarCtrl : public wxControl
225 %pythonAppend wxCalendarCtrl "self._setOORInfo(self)"
226 %pythonAppend wxCalendarCtrl() ""
229 wxCalendarCtrl(wxWindow *parent,
231 const wxDateTime& date = wxDefaultDateTime,
232 const wxPoint& pos = wxDefaultPosition,
233 const wxSize& size = wxDefaultSize,
234 long style = wxCAL_SHOW_HOLIDAYS | wxWANTS_CHARS,
235 const wxString& name = wxPyCalendarNameStr),
236 "Create and show a calendar control.", "");
240 "Precreate a CalendarCtrl for 2-phase creation.", "",
244 bool , Create(wxWindow *parent,
246 const wxDateTime& date = wxDefaultDateTime,
247 const wxPoint& pos = wxDefaultPosition,
248 const wxSize& size = wxDefaultSize,
249 long style = wxCAL_SHOW_HOLIDAYS | wxWANTS_CHARS,
250 const wxString& name = wxPyCalendarNameStr),
251 "Acutally create the GUI portion of the CalendarCtrl for 2-phase
257 void, SetDate(const wxDateTime& date),
258 "Sets the current date.", "");
261 const wxDateTime, GetDate() const,
262 "Gets the currently selected date.", "");
267 bool, SetLowerDateLimit(const wxDateTime& date = wxDefaultDateTime),
268 "set the range in which selection can occur", "");
271 bool, SetUpperDateLimit(const wxDateTime& date = wxDefaultDateTime),
272 "set the range in which selection can occur", "");
275 const wxDateTime, GetLowerDateLimit() const,
276 "get the range in which selection can occur", "");
279 const wxDateTime, GetUpperDateLimit() const,
280 "get the range in which selection can occur", "");
283 bool, SetDateRange(const wxDateTime& lowerdate = wxDefaultDateTime,
284 const wxDateTime& upperdate = wxDefaultDateTime),
285 "set the range in which selection can occur", "");
291 void, EnableYearChange(bool enable = true),
292 "This function should be used instead of changing CAL_NO_YEAR_CHANGE
293 style bit directly. It allows or disallows the user to change the year
294 interactively.", "");
297 void, EnableMonthChange(bool enable = true),
298 "This function should be used instead of changing CAL_NO_MONTH_CHANGE
299 style bit. It allows or disallows the user to change the month
300 interactively. Note that if the month can not be changed, the year can
301 not be changed either.", "");
304 void, EnableHolidayDisplay(bool display = true),
305 "This function should be used instead of changing CAL_SHOW_HOLIDAYS
306 style bit directly. It enables or disables the special highlighting of
312 void, SetHeaderColours(const wxColour& colFg, const wxColour& colBg),
313 "Header colours are used for painting the weekdays at the top.", "");
316 wxColour, GetHeaderColourFg() const,
317 "Header colours are used for painting the weekdays at the top.", "");
320 wxColour, GetHeaderColourBg() const,
321 "Header colours are used for painting the weekdays at the top.", "");
326 void, SetHighlightColours(const wxColour& colFg, const wxColour& colBg),
327 "Highlight colour is used for the currently selected date.", "");
330 wxColour, GetHighlightColourFg() const,
331 "Highlight colour is used for the currently selected date.", "");
334 wxColour, GetHighlightColourBg() const,
335 "Highlight colour is used for the currently selected date.", "");
340 void, SetHolidayColours(const wxColour& colFg, const wxColour& colBg),
341 "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is
345 wxColour, GetHolidayColourFg() const,
346 "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is
350 wxColour, GetHolidayColourBg() const,
351 "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is
357 wxCalendarDateAttr*, GetAttr(size_t day) const,
358 "Returns the attribute for the given date (should be in the range
359 1...31). The returned value may be None", "");
362 void, SetAttr(size_t day, wxCalendarDateAttr *attr),
363 "Associates the attribute with the specified date (in the range
364 1...31). If the attribute passed is None, the items attribute is
368 void, SetHoliday(size_t day),
369 "Marks the specified day as being a holiday in the current month.", "");
372 void, ResetAttr(size_t day),
373 "Clears any attributes associated with the given day (in the range
379 "HitTest(Point pos) -> (result, date, weekday)",
380 "Returns 3-tuple with information about the given position on the
381 calendar control. The first value of the tuple is a result code and
382 determines the validity of the remaining two values.",
384 The result codes are:
386 =================== ============================================
387 CAL_HITTEST_NOWHERE hit outside of anything
388 CAL_HITTEST_HEADER hit on the header, weekday is valid
389 CAL_HITTEST_DAY hit on a day in the calendar, date is set.
390 =================== ============================================
393 PyObject* HitTest(const wxPoint& pos) {
394 wxDateTime* date = new wxDateTime;
395 wxDateTime::WeekDay wd;
396 wxCalendarHitTestResult result = self->HitTest(pos, date, &wd);
397 wxPyBlock_t blocked = wxPyBeginBlockThreads();
398 PyObject* tup = PyTuple_New(3);
399 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(result));
400 PyTuple_SET_ITEM(tup, 1, wxPyConstructObject(date, wxT("wxDateTime"), 1));
401 PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(wd));
402 wxPyEndBlockThreads(blocked);
408 wxControl*, GetMonthControl() const,
409 "Get the currently shown control for month.", "");
412 wxControl*, GetYearControl() const,
413 "Get the currently shown control for year.", "");
415 static wxVisualAttributes
416 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
419 def PySetDate(self, date):
420 """takes datetime.datetime or datetime.date object"""
421 self.SetDate(_pydate2wxdate(date))
424 """returns datetime.date object"""
425 return _wxdate2pydate(self.GetDate())
427 def PySetLowerDateLimit(self, date):
428 """takes datetime.datetime or datetime.date object"""
429 self.SetLowerDateLimit(_pydate2wxdate(date))
431 def PySetUpperDateLimit(self, date):
432 """takes datetime.datetime or datetime.date object"""
433 self.SetUpperDateLimit(_pydate2wxdate(date))
435 def PySetDateRange(self, lowerdate, upperdate):
436 """takes datetime.datetime or datetime.date objects"""
437 self.PySetLowerDateLimit(lowerdate)
438 self.PySetUpperDateLimit(upperdate)
440 def PyGetLowerDateLimit(self):
441 """returns datetime.date object"""
442 return _wxdate2pydate(self.GetLowerDateLimit())
444 def PyGetUpperDateLimit(self):
445 """returns datetime.date object"""
446 return _wxdate2pydate(self.GetUpperDateLimit())
451 def _pydate2wxdate(date):
453 assert isinstance(date, (datetime.datetime, datetime.date))
454 tt = date.timetuple()
455 dmy = (tt[2], tt[1]-1, tt[0])
456 return wx.DateTimeFromDMY(*dmy)
458 def _wxdate2pydate(date):
460 assert isinstance(date, wx.DateTime)
462 ymd = map(int, date.FormatISODate().split('-'))
463 return datetime.date(*ymd)
468 //---------------------------------------------------------------------------
473 //---------------------------------------------------------------------------