]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/calendar.i
better report if the subclass factory has import problems
[wxWidgets.git] / wxPython / src / calendar.i
CommitLineData
f6bcfd97
BP
1/////////////////////////////////////////////////////////////////////////////
2// Name: calendar.i
3// Purpose: SWIG definitions for the wxCalendarCtrl
4//
5// Author: Robin Dunn
6//
7// Created: 23-May-2000
8// RCS-ID: $Id$
9// Copyright: (c) 2000 by Total Control Software
10// Licence: wxWindows license
11/////////////////////////////////////////////////////////////////////////////
12
c8fac2b6
RD
13%define DOCSTRING
14"Classes for an interactive Calendar control."
15%enddef
b2eb030f
RD
16
17%module(package="wx", docstring=DOCSTRING) calendar
f6bcfd97
BP
18
19
20%{
d14a1e28
RD
21#include "wx/wxPython/wxPython.h"
22#include "wx/wxPython/pyclasses.h"
23
f6bcfd97
BP
24#include <wx/calctrl.h>
25%}
26
27//----------------------------------------------------------------------
28
f6bcfd97 29%import misc.i
54f9ee45 30%pythoncode { wx = _core }
99109c0f 31%pythoncode { __docfilter__ = wx.__DocFilter(globals()) }
f6bcfd97 32
f6bcfd97
BP
33//---------------------------------------------------------------------------
34
35enum {
36 wxCAL_SUNDAY_FIRST,
37 wxCAL_MONDAY_FIRST,
38 wxCAL_SHOW_HOLIDAYS,
39 wxCAL_NO_YEAR_CHANGE,
40 wxCAL_NO_MONTH_CHANGE,
ab11ebfa
RD
41 wxCAL_SEQUENTIAL_MONTH_SELECTION,
42 wxCAL_SHOW_SURROUNDING_WEEKS,
f6bcfd97
BP
43};
44
45
46enum wxCalendarHitTestResult
47{
48 wxCAL_HITTEST_NOWHERE, // outside of anything
49 wxCAL_HITTEST_HEADER, // on the header (weekdays)
b66824a5 50 wxCAL_HITTEST_DAY, // on a day in the calendar
ab11ebfa
RD
51 wxCAL_HITTEST_INCMONTH,
52 wxCAL_HITTEST_DECMONTH,
53 wxCAL_HITTEST_SURROUNDING_WEEK
f6bcfd97
BP
54};
55
56// border types for a date
57enum wxCalendarDateBorder
58{
59 wxCAL_BORDER_NONE, // no border (default)
60 wxCAL_BORDER_SQUARE, // a rectangular border
61 wxCAL_BORDER_ROUND // a round border
62};
63
64//---------------------------------------------------------------------------
65
856bf319 66DocStr(wxCalendarDateAttr,
dce2bd22 67"A set of customization attributes for a calendar date, which can be
d07d2bc9 68used to control the look of the Calendar object.", "");
f6bcfd97
BP
69
70class wxCalendarDateAttr
71{
72public:
856bf319 73 DocStr(wxCalendarDateAttr,
d07d2bc9 74 "Create a CalendarDateAttr.", "");
856bf319 75 wxCalendarDateAttr(const wxColour& colText = wxNullColour,
f6bcfd97
BP
76 const wxColour& colBack = wxNullColour,
77 const wxColour& colBorder = wxNullColour,
78 const wxFont& font = wxNullFont,
79 wxCalendarDateBorder border = wxCAL_BORDER_NONE);
80
90fb367e
RD
81 ~wxCalendarDateAttr();
82
856bf319 83
f6bcfd97
BP
84 // setters
85 void SetTextColour(const wxColour& colText);
86 void SetBackgroundColour(const wxColour& colBack);
87 void SetBorderColour(const wxColour& col);
88 void SetFont(const wxFont& font);
89 void SetBorder(wxCalendarDateBorder border);
90 void SetHoliday(bool holiday);
91
92 // accessors
93 bool HasTextColour() const;
94 bool HasBackgroundColour() const;
95 bool HasBorderColour() const;
96 bool HasFont() const;
97 bool HasBorder() const;
98
99 bool IsHoliday() const;
100
c5943253
RD
101 wxColour GetTextColour() const;
102 wxColour GetBackgroundColour() const;
103 wxColour GetBorderColour() const;
104 wxFont GetFont() const;
f6bcfd97 105 wxCalendarDateBorder GetBorder() const;
777e547f
RD
106
107 %property(BackgroundColour, GetBackgroundColour, SetBackgroundColour, doc="See `GetBackgroundColour` and `SetBackgroundColour`");
108 %property(Border, GetBorder, SetBorder, doc="See `GetBorder` and `SetBorder`");
109 %property(BorderColour, GetBorderColour, SetBorderColour, doc="See `GetBorderColour` and `SetBorderColour`");
110 %property(Font, GetFont, SetFont, doc="See `GetFont` and `SetFont`");
111 %property(TextColour, GetTextColour, SetTextColour, doc="See `GetTextColour` and `SetTextColour`");
f6bcfd97
BP
112};
113
114//---------------------------------------------------------------------------
115
116class wxCalendarCtrl;
117
b3b61cda 118class wxCalendarEvent : public wxDateEvent
f6bcfd97
BP
119{
120public:
121 wxCalendarEvent(wxCalendarCtrl *cal, wxEventType type);
122
3f0ff538 123 void SetWeekDay(const wxDateTime::WeekDay wd);
f6bcfd97
BP
124 wxDateTime::WeekDay GetWeekDay() const;
125
31b46829
RD
126 %pythoncode {
127 def PySetDate(self, date):
128 """takes datetime.datetime or datetime.date object"""
50b42eef 129 self.SetDate(_pydate2wxdate(date))
31b46829
RD
130
131 def PyGetDate(self):
132 """returns datetime.date object"""
50b42eef 133 return _wxdate2pydate(self.GetDate())
31b46829 134 }
777e547f
RD
135
136 %property(WeekDay, GetWeekDay, SetWeekDay, doc="See `GetWeekDay` and `SetWeekDay`");
f6bcfd97
BP
137};
138
f6bcfd97 139
d14a1e28
RD
140%constant wxEventType wxEVT_CALENDAR_DOUBLECLICKED;
141%constant wxEventType wxEVT_CALENDAR_SEL_CHANGED;
142%constant wxEventType wxEVT_CALENDAR_DAY_CHANGED;
143%constant wxEventType wxEVT_CALENDAR_MONTH_CHANGED;
144%constant wxEventType wxEVT_CALENDAR_YEAR_CHANGED;
145%constant wxEventType wxEVT_CALENDAR_WEEKDAY_CLICKED;
f6bcfd97 146
f6bcfd97 147
d14a1e28
RD
148%pythoncode {
149EVT_CALENDAR = wx.PyEventBinder( wxEVT_CALENDAR_DOUBLECLICKED, 1)
150EVT_CALENDAR_SEL_CHANGED = wx.PyEventBinder( wxEVT_CALENDAR_SEL_CHANGED, 1)
151EVT_CALENDAR_DAY = wx.PyEventBinder( wxEVT_CALENDAR_DAY_CHANGED, 1)
152EVT_CALENDAR_MONTH = wx.PyEventBinder( wxEVT_CALENDAR_MONTH_CHANGED, 1)
153EVT_CALENDAR_YEAR = wx.PyEventBinder( wxEVT_CALENDAR_YEAR_CHANGED, 1)
154EVT_CALENDAR_WEEKDAY_CLICKED = wx.PyEventBinder( wxEVT_CALENDAR_WEEKDAY_CLICKED, 1)
155}
f6bcfd97 156
f6bcfd97
BP
157
158//---------------------------------------------------------------------------
159
b2dc1044 160MAKE_CONST_WXSTRING(CalendarNameStr);
137b5242 161
d14a1e28 162
856bf319 163DocStr(wxCalendarCtrl,
dce2bd22
RD
164"The calendar control allows the user to pick a date interactively.
165
166The CalendarCtrl displays a window containing several parts: the
167control to pick the month and the year at the top (either or both of
168them may be disabled) and a month area below them which shows all the
169days in the month. The user can move the current selection using the
170keyboard and select the date (generating EVT_CALENDAR event) by
171pressing <Return> or double clicking it.
172
173It has advanced possibilities for the customization of its
174display. All global settings (such as colours and fonts used) can, of
175course, be changed. But also, the display style for each day in the
176month can be set independently using CalendarDateAttr class.
177
178An item without custom attributes is drawn with the default colours
179and font and without border, but setting custom attributes with
90fb367e 180`SetAttr` allows to modify its appearance. Just create a custom
dce2bd22
RD
181attribute object and set it for the day you want to be displayed
182specially A day may be marked as being a holiday, (even if it is not
b3b61cda 183recognized as one by `wx.DateTime`) by using the SetHoliday method.
dce2bd22
RD
184
185As the attributes are specified for each day, they may change when the
186month is changed, so you will often want to update them in an
d07d2bc9 187EVT_CALENDAR_MONTH event handler.", "
dce2bd22
RD
188
189Window Styles
190-------------
191 ============================== ============================
192 CAL_SUNDAY_FIRST Show Sunday as the first day
193 in the week
194 CAL_MONDAY_FIRST Show Monday as the first day
195 in the week
196 CAL_SHOW_HOLIDAYS Highlight holidays in the
197 calendar
198 CAL_NO_YEAR_CHANGE Disable the year changing
199 CAL_NO_MONTH_CHANGE Disable the month (and,
200 implicitly, the year) changing
201 CAL_SHOW_SURROUNDING_WEEKS Show the neighbouring weeks in
202 the previous and next months
203 CAL_SEQUENTIAL_MONTH_SELECTION Use alternative, more compact,
204 style for the month and year
205 selection controls.
c8fac2b6 206 ============================== ============================
dce2bd22
RD
207
208The default calendar style is CAL_SHOW_HOLIDAYS.
209
210Events
211-------
c8fac2b6 212 ============================= ==============================
dce2bd22
RD
213 EVT_CALENDAR A day was double clicked in the
214 calendar.
215 EVT_CALENDAR_SEL_CHANGED The selected date changed.
216 EVT_CALENDAR_DAY The selected day changed.
217 EVT_CALENDAR_MONTH The selected month changed.
218 EVT_CALENDAR_YEAR The selected year changed.
219 EVT_CALENDAR_WEEKDAY_CLICKED User clicked on the week day
220 header
c8fac2b6 221 ============================= ==============================
dce2bd22
RD
222
223Note that changing the selected date will result in one of
224EVT_CALENDAR_DAY, MONTH or YEAR events and an EVT_CALENDAR_SEL_CHANGED
225event.
856bf319
RD
226
227");
228
229
ab1f7d2a
RD
230MustHaveApp(wxCalendarCtrl);
231
f6bcfd97
BP
232class wxCalendarCtrl : public wxControl
233{
234public:
2b9048c5
RD
235 %pythonAppend wxCalendarCtrl "self._setOORInfo(self)"
236 %pythonAppend wxCalendarCtrl() ""
d14a1e28 237
dce2bd22
RD
238 DocCtorStr(
239 wxCalendarCtrl(wxWindow *parent,
240 wxWindowID id=-1,
241 const wxDateTime& date = wxDefaultDateTime,
242 const wxPoint& pos = wxDefaultPosition,
243 const wxSize& size = wxDefaultSize,
244 long style = wxCAL_SHOW_HOLIDAYS | wxWANTS_CHARS,
245 const wxString& name = wxPyCalendarNameStr),
d07d2bc9 246 "Create and show a calendar control.", "");
dce2bd22
RD
247
248 DocCtorStrName(
249 wxCalendarCtrl(),
d07d2bc9 250 "Precreate a CalendarCtrl for 2-phase creation.", "",
dce2bd22 251 PreCalendarCtrl);
09f3d4e6 252
dce2bd22
RD
253 DocDeclStr(
254 bool , Create(wxWindow *parent,
255 wxWindowID id,
256 const wxDateTime& date = wxDefaultDateTime,
257 const wxPoint& pos = wxDefaultPosition,
258 const wxSize& size = wxDefaultSize,
259 long style = wxCAL_SHOW_HOLIDAYS | wxWANTS_CHARS,
260 const wxString& name = wxPyCalendarNameStr),
261 "Acutally create the GUI portion of the CalendarCtrl for 2-phase
d07d2bc9 262creation.", "");
dce2bd22 263
f6bcfd97 264
0122b7e3 265
856bf319
RD
266 DocDeclStr(
267 void, SetDate(const wxDateTime& date),
d07d2bc9 268 "Sets the current date.", "");
856bf319
RD
269
270 DocDeclStr(
b4b426fe 271 const wxDateTime, GetDate() const,
d07d2bc9 272 "Gets the currently selected date.", "");
856bf319
RD
273
274
275
276 DocDeclStr(
277 bool, SetLowerDateLimit(const wxDateTime& date = wxDefaultDateTime),
d07d2bc9 278 "set the range in which selection can occur", "");
856bf319
RD
279
280 DocDeclStr(
281 bool, SetUpperDateLimit(const wxDateTime& date = wxDefaultDateTime),
d07d2bc9 282 "set the range in which selection can occur", "");
856bf319
RD
283
284 DocDeclStr(
b4b426fe 285 const wxDateTime, GetLowerDateLimit() const,
d07d2bc9 286 "get the range in which selection can occur", "");
856bf319
RD
287
288 DocDeclStr(
b4b426fe 289 const wxDateTime, GetUpperDateLimit() const,
d07d2bc9 290 "get the range in which selection can occur", "");
856bf319
RD
291
292 DocDeclStr(
293 bool, SetDateRange(const wxDateTime& lowerdate = wxDefaultDateTime,
294 const wxDateTime& upperdate = wxDefaultDateTime),
d07d2bc9 295 "set the range in which selection can occur", "");
856bf319
RD
296
297
298
299
300 DocDeclStr(
a72f4631 301 void, EnableYearChange(bool enable = true),
dce2bd22
RD
302 "This function should be used instead of changing CAL_NO_YEAR_CHANGE
303style bit directly. It allows or disallows the user to change the year
d07d2bc9 304interactively.", "");
856bf319
RD
305
306 DocDeclStr(
a72f4631 307 void, EnableMonthChange(bool enable = true),
dce2bd22
RD
308 "This function should be used instead of changing CAL_NO_MONTH_CHANGE
309style bit. It allows or disallows the user to change the month
310interactively. Note that if the month can not be changed, the year can
d07d2bc9 311not be changed either.", "");
856bf319
RD
312
313 DocDeclStr(
a72f4631 314 void, EnableHolidayDisplay(bool display = true),
dce2bd22
RD
315 "This function should be used instead of changing CAL_SHOW_HOLIDAYS
316style bit directly. It enables or disables the special highlighting of
d07d2bc9 317the holidays.", "");
856bf319
RD
318
319
320
321 DocDeclStr(
322 void, SetHeaderColours(const wxColour& colFg, const wxColour& colBg),
d07d2bc9 323 "Header colours are used for painting the weekdays at the top.", "");
856bf319
RD
324
325 DocDeclStr(
326 wxColour, GetHeaderColourFg() const,
d07d2bc9 327 "Header colours are used for painting the weekdays at the top.", "");
856bf319
RD
328
329 DocDeclStr(
330 wxColour, GetHeaderColourBg() const,
d07d2bc9 331 "Header colours are used for painting the weekdays at the top.", "");
856bf319
RD
332
333
334
335 DocDeclStr(
336 void, SetHighlightColours(const wxColour& colFg, const wxColour& colBg),
d07d2bc9 337 "Highlight colour is used for the currently selected date.", "");
856bf319
RD
338
339 DocDeclStr(
340 wxColour, GetHighlightColourFg() const,
d07d2bc9 341 "Highlight colour is used for the currently selected date.", "");
856bf319
RD
342
343 DocDeclStr(
344 wxColour, GetHighlightColourBg() const,
d07d2bc9 345 "Highlight colour is used for the currently selected date.", "");
856bf319
RD
346
347
348
349 DocDeclStr(
350 void, SetHolidayColours(const wxColour& colFg, const wxColour& colBg),
dce2bd22 351 "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is
d07d2bc9 352used).", "");
856bf319
RD
353
354 DocDeclStr(
355 wxColour, GetHolidayColourFg() const,
dce2bd22 356 "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is
d07d2bc9 357used).", "");
856bf319
RD
358
359 DocDeclStr(
360 wxColour, GetHolidayColourBg() const,
dce2bd22 361 "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is
d07d2bc9 362used).", "");
856bf319
RD
363
364
365
366 DocDeclStr(
367 wxCalendarDateAttr*, GetAttr(size_t day) const,
dce2bd22 368 "Returns the attribute for the given date (should be in the range
d07d2bc9 3691...31). The returned value may be None", "");
90fb367e
RD
370
371 %disownarg(wxCalendarDateAttr *attr);
856bf319
RD
372 DocDeclStr(
373 void, SetAttr(size_t day, wxCalendarDateAttr *attr),
dce2bd22
RD
374 "Associates the attribute with the specified date (in the range
3751...31). If the attribute passed is None, the items attribute is
d07d2bc9 376cleared.", "");
90fb367e 377 %cleardisown(wxCalendarDateAttr *attr);
856bf319
RD
378
379 DocDeclStr(
380 void, SetHoliday(size_t day),
d07d2bc9 381 "Marks the specified day as being a holiday in the current month.", "");
856bf319
RD
382
383 DocDeclStr(
384 void, ResetAttr(size_t day),
dce2bd22 385 "Clears any attributes associated with the given day (in the range
d07d2bc9 3861...31).", "");
856bf319
RD
387
388
389
390 DocAStr(HitTest,
391 "HitTest(Point pos) -> (result, date, weekday)",
dce2bd22
RD
392"Returns 3-tuple with information about the given position on the
393calendar control. The first value of the tuple is a result code and
d07d2bc9
RD
394determines the validity of the remaining two values.",
395"
396The result codes are:
dce2bd22
RD
397
398 =================== ============================================
399 CAL_HITTEST_NOWHERE hit outside of anything
400 CAL_HITTEST_HEADER hit on the header, weekday is valid
401 CAL_HITTEST_DAY hit on a day in the calendar, date is set.
402 =================== ============================================
856bf319
RD
403");
404 %extend {
405 PyObject* HitTest(const wxPoint& pos) {
406 wxDateTime* date = new wxDateTime;
407 wxDateTime::WeekDay wd;
408 wxCalendarHitTestResult result = self->HitTest(pos, date, &wd);
6e6b3557 409 wxPyBlock_t blocked = wxPyBeginBlockThreads();
856bf319
RD
410 PyObject* tup = PyTuple_New(3);
411 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(result));
412 PyTuple_SET_ITEM(tup, 1, wxPyConstructObject(date, wxT("wxDateTime"), 1));
413 PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(wd));
da32eb53 414 wxPyEndBlockThreads(blocked);
856bf319
RD
415 return tup;
416 }
417 }
418
419 DocDeclStr(
420 wxControl*, GetMonthControl() const,
d07d2bc9 421 "Get the currently shown control for month.", "");
856bf319
RD
422
423 DocDeclStr(
424 wxControl*, GetYearControl() const,
d07d2bc9 425 "Get the currently shown control for year.", "");
880715c9
RD
426
427 static wxVisualAttributes
428 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
f6bcfd97 429
31b46829
RD
430 %pythoncode {
431 def PySetDate(self, date):
432 """takes datetime.datetime or datetime.date object"""
50b42eef 433 self.SetDate(_pydate2wxdate(date))
31b46829
RD
434
435 def PyGetDate(self):
436 """returns datetime.date object"""
50b42eef 437 return _wxdate2pydate(self.GetDate())
31b46829
RD
438
439 def PySetLowerDateLimit(self, date):
440 """takes datetime.datetime or datetime.date object"""
50b42eef 441 self.SetLowerDateLimit(_pydate2wxdate(date))
31b46829
RD
442
443 def PySetUpperDateLimit(self, date):
444 """takes datetime.datetime or datetime.date object"""
50b42eef 445 self.SetUpperDateLimit(_pydate2wxdate(date))
31b46829
RD
446
447 def PySetDateRange(self, lowerdate, upperdate):
448 """takes datetime.datetime or datetime.date objects"""
449 self.PySetLowerDateLimit(lowerdate)
450 self.PySetUpperDateLimit(upperdate)
451
452 def PyGetLowerDateLimit(self):
453 """returns datetime.date object"""
50b42eef 454 return _wxdate2pydate(self.GetLowerDateLimit())
f6bcfd97 455
31b46829
RD
456 def PyGetUpperDateLimit(self):
457 """returns datetime.date object"""
50b42eef 458 return _wxdate2pydate(self.GetUpperDateLimit())
31b46829 459 }
777e547f
RD
460
461 %property(Date, GetDate, SetDate, doc="See `GetDate` and `SetDate`");
462 %property(HeaderColourBg, GetHeaderColourBg, doc="See `GetHeaderColourBg`");
463 %property(HeaderColourFg, GetHeaderColourFg, doc="See `GetHeaderColourFg`");
464 %property(HighlightColourBg, GetHighlightColourBg, doc="See `GetHighlightColourBg`");
465 %property(HighlightColourFg, GetHighlightColourFg, doc="See `GetHighlightColourFg`");
466 %property(HolidayColourBg, GetHolidayColourBg, doc="See `GetHolidayColourBg`");
467 %property(HolidayColourFg, GetHolidayColourFg, doc="See `GetHolidayColourFg`");
468 %property(LowerDateLimit, GetLowerDateLimit, SetLowerDateLimit, doc="See `GetLowerDateLimit` and `SetLowerDateLimit`");
469 %property(MonthControl, GetMonthControl, doc="See `GetMonthControl`");
470 %property(UpperDateLimit, GetUpperDateLimit, SetUpperDateLimit, doc="See `GetUpperDateLimit` and `SetUpperDateLimit`");
471 %property(YearControl, GetYearControl, doc="See `GetYearControl`");
31b46829
RD
472};
473
474%pythoncode {
50b42eef 475def _pydate2wxdate(date):
31b46829
RD
476 import datetime
477 assert isinstance(date, (datetime.datetime, datetime.date))
478 tt = date.timetuple()
479 dmy = (tt[2], tt[1]-1, tt[0])
480 return wx.DateTimeFromDMY(*dmy)
481
50b42eef 482def _wxdate2pydate(date):
31b46829
RD
483 import datetime
484 assert isinstance(date, wx.DateTime)
50b42eef
RD
485 if date.IsValid():
486 ymd = map(int, date.FormatISODate().split('-'))
487 return datetime.date(*ymd)
488 else:
489 return None
31b46829
RD
490}
491
f6bcfd97 492//---------------------------------------------------------------------------
e508a2b6
RD
493
494%init %{
e508a2b6
RD
495%}
496
f6bcfd97
BP
497//---------------------------------------------------------------------------
498