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