]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/calendar.i
Build fix for motif.
[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
856bf319 81
f6bcfd97
BP
82 // setters
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);
89
90 // accessors
91 bool HasTextColour() const;
92 bool HasBackgroundColour() const;
93 bool HasBorderColour() const;
94 bool HasFont() const;
95 bool HasBorder() const;
96
97 bool IsHoliday() const;
98
c5943253
RD
99 wxColour GetTextColour() const;
100 wxColour GetBackgroundColour() const;
101 wxColour GetBorderColour() const;
102 wxFont GetFont() const;
f6bcfd97
BP
103 wxCalendarDateBorder GetBorder() const;
104};
105
106//---------------------------------------------------------------------------
107
108class wxCalendarCtrl;
109
b3b61cda 110class wxCalendarEvent : public wxDateEvent
f6bcfd97
BP
111{
112public:
113 wxCalendarEvent(wxCalendarCtrl *cal, wxEventType type);
114
3f0ff538 115 void SetWeekDay(const wxDateTime::WeekDay wd);
f6bcfd97
BP
116 wxDateTime::WeekDay GetWeekDay() const;
117
31b46829
RD
118 %pythoncode {
119 def PySetDate(self, date):
120 """takes datetime.datetime or datetime.date object"""
50b42eef 121 self.SetDate(_pydate2wxdate(date))
31b46829
RD
122
123 def PyGetDate(self):
124 """returns datetime.date object"""
50b42eef 125 return _wxdate2pydate(self.GetDate())
31b46829 126 }
f6bcfd97
BP
127};
128
f6bcfd97 129
d14a1e28
RD
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;
f6bcfd97 136
f6bcfd97 137
d14a1e28
RD
138%pythoncode {
139EVT_CALENDAR = wx.PyEventBinder( wxEVT_CALENDAR_DOUBLECLICKED, 1)
140EVT_CALENDAR_SEL_CHANGED = wx.PyEventBinder( wxEVT_CALENDAR_SEL_CHANGED, 1)
141EVT_CALENDAR_DAY = wx.PyEventBinder( wxEVT_CALENDAR_DAY_CHANGED, 1)
142EVT_CALENDAR_MONTH = wx.PyEventBinder( wxEVT_CALENDAR_MONTH_CHANGED, 1)
143EVT_CALENDAR_YEAR = wx.PyEventBinder( wxEVT_CALENDAR_YEAR_CHANGED, 1)
144EVT_CALENDAR_WEEKDAY_CLICKED = wx.PyEventBinder( wxEVT_CALENDAR_WEEKDAY_CLICKED, 1)
145}
f6bcfd97 146
f6bcfd97
BP
147
148//---------------------------------------------------------------------------
149
b2dc1044 150MAKE_CONST_WXSTRING(CalendarNameStr);
137b5242 151
d14a1e28 152
856bf319 153DocStr(wxCalendarCtrl,
dce2bd22
RD
154"The calendar control allows the user to pick a date interactively.
155
156The CalendarCtrl displays a window containing several parts: the
157control to pick the month and the year at the top (either or both of
158them may be disabled) and a month area below them which shows all the
159days in the month. The user can move the current selection using the
160keyboard and select the date (generating EVT_CALENDAR event) by
161pressing <Return> or double clicking it.
162
163It has advanced possibilities for the customization of its
164display. All global settings (such as colours and fonts used) can, of
165course, be changed. But also, the display style for each day in the
166month can be set independently using CalendarDateAttr class.
167
168An item without custom attributes is drawn with the default colours
169and font and without border, but setting custom attributes with
170SetAttr allows to modify its appearance. Just create a custom
171attribute object and set it for the day you want to be displayed
172specially A day may be marked as being a holiday, (even if it is not
b3b61cda 173recognized as one by `wx.DateTime`) by using the SetHoliday method.
dce2bd22
RD
174
175As the attributes are specified for each day, they may change when the
176month is changed, so you will often want to update them in an
d07d2bc9 177EVT_CALENDAR_MONTH event handler.", "
dce2bd22
RD
178
179Window Styles
180-------------
181 ============================== ============================
182 CAL_SUNDAY_FIRST Show Sunday as the first day
183 in the week
184 CAL_MONDAY_FIRST Show Monday as the first day
185 in the week
186 CAL_SHOW_HOLIDAYS Highlight holidays in the
187 calendar
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
195 selection controls.
c8fac2b6 196 ============================== ============================
dce2bd22
RD
197
198The default calendar style is CAL_SHOW_HOLIDAYS.
199
200Events
201-------
c8fac2b6 202 ============================= ==============================
dce2bd22
RD
203 EVT_CALENDAR A day was double clicked in the
204 calendar.
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
210 header
c8fac2b6 211 ============================= ==============================
dce2bd22
RD
212
213Note that changing the selected date will result in one of
214EVT_CALENDAR_DAY, MONTH or YEAR events and an EVT_CALENDAR_SEL_CHANGED
215event.
856bf319
RD
216
217");
218
219
ab1f7d2a
RD
220MustHaveApp(wxCalendarCtrl);
221
f6bcfd97
BP
222class wxCalendarCtrl : public wxControl
223{
224public:
2b9048c5
RD
225 %pythonAppend wxCalendarCtrl "self._setOORInfo(self)"
226 %pythonAppend wxCalendarCtrl() ""
d14a1e28 227
dce2bd22
RD
228 DocCtorStr(
229 wxCalendarCtrl(wxWindow *parent,
230 wxWindowID id=-1,
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),
d07d2bc9 236 "Create and show a calendar control.", "");
dce2bd22
RD
237
238 DocCtorStrName(
239 wxCalendarCtrl(),
d07d2bc9 240 "Precreate a CalendarCtrl for 2-phase creation.", "",
dce2bd22 241 PreCalendarCtrl);
09f3d4e6 242
dce2bd22
RD
243 DocDeclStr(
244 bool , Create(wxWindow *parent,
245 wxWindowID id,
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
d07d2bc9 252creation.", "");
dce2bd22 253
f6bcfd97 254
0122b7e3 255
856bf319
RD
256 DocDeclStr(
257 void, SetDate(const wxDateTime& date),
d07d2bc9 258 "Sets the current date.", "");
856bf319
RD
259
260 DocDeclStr(
b4b426fe 261 const wxDateTime, GetDate() const,
d07d2bc9 262 "Gets the currently selected date.", "");
856bf319
RD
263
264
265
266 DocDeclStr(
267 bool, SetLowerDateLimit(const wxDateTime& date = wxDefaultDateTime),
d07d2bc9 268 "set the range in which selection can occur", "");
856bf319
RD
269
270 DocDeclStr(
271 bool, SetUpperDateLimit(const wxDateTime& date = wxDefaultDateTime),
d07d2bc9 272 "set the range in which selection can occur", "");
856bf319
RD
273
274 DocDeclStr(
b4b426fe 275 const wxDateTime, GetLowerDateLimit() const,
d07d2bc9 276 "get the range in which selection can occur", "");
856bf319
RD
277
278 DocDeclStr(
b4b426fe 279 const wxDateTime, GetUpperDateLimit() const,
d07d2bc9 280 "get the range in which selection can occur", "");
856bf319
RD
281
282 DocDeclStr(
283 bool, SetDateRange(const wxDateTime& lowerdate = wxDefaultDateTime,
284 const wxDateTime& upperdate = wxDefaultDateTime),
d07d2bc9 285 "set the range in which selection can occur", "");
856bf319
RD
286
287
288
289
290 DocDeclStr(
a72f4631 291 void, EnableYearChange(bool enable = true),
dce2bd22
RD
292 "This function should be used instead of changing CAL_NO_YEAR_CHANGE
293style bit directly. It allows or disallows the user to change the year
d07d2bc9 294interactively.", "");
856bf319
RD
295
296 DocDeclStr(
a72f4631 297 void, EnableMonthChange(bool enable = true),
dce2bd22
RD
298 "This function should be used instead of changing CAL_NO_MONTH_CHANGE
299style bit. It allows or disallows the user to change the month
300interactively. Note that if the month can not be changed, the year can
d07d2bc9 301not be changed either.", "");
856bf319
RD
302
303 DocDeclStr(
a72f4631 304 void, EnableHolidayDisplay(bool display = true),
dce2bd22
RD
305 "This function should be used instead of changing CAL_SHOW_HOLIDAYS
306style bit directly. It enables or disables the special highlighting of
d07d2bc9 307the holidays.", "");
856bf319
RD
308
309
310
311 DocDeclStr(
312 void, SetHeaderColours(const wxColour& colFg, const wxColour& colBg),
d07d2bc9 313 "Header colours are used for painting the weekdays at the top.", "");
856bf319
RD
314
315 DocDeclStr(
316 wxColour, GetHeaderColourFg() const,
d07d2bc9 317 "Header colours are used for painting the weekdays at the top.", "");
856bf319
RD
318
319 DocDeclStr(
320 wxColour, GetHeaderColourBg() const,
d07d2bc9 321 "Header colours are used for painting the weekdays at the top.", "");
856bf319
RD
322
323
324
325 DocDeclStr(
326 void, SetHighlightColours(const wxColour& colFg, const wxColour& colBg),
d07d2bc9 327 "Highlight colour is used for the currently selected date.", "");
856bf319
RD
328
329 DocDeclStr(
330 wxColour, GetHighlightColourFg() const,
d07d2bc9 331 "Highlight colour is used for the currently selected date.", "");
856bf319
RD
332
333 DocDeclStr(
334 wxColour, GetHighlightColourBg() const,
d07d2bc9 335 "Highlight colour is used for the currently selected date.", "");
856bf319
RD
336
337
338
339 DocDeclStr(
340 void, SetHolidayColours(const wxColour& colFg, const wxColour& colBg),
dce2bd22 341 "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is
d07d2bc9 342used).", "");
856bf319
RD
343
344 DocDeclStr(
345 wxColour, GetHolidayColourFg() const,
dce2bd22 346 "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is
d07d2bc9 347used).", "");
856bf319
RD
348
349 DocDeclStr(
350 wxColour, GetHolidayColourBg() const,
dce2bd22 351 "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is
d07d2bc9 352used).", "");
856bf319
RD
353
354
355
356 DocDeclStr(
357 wxCalendarDateAttr*, GetAttr(size_t day) const,
dce2bd22 358 "Returns the attribute for the given date (should be in the range
d07d2bc9 3591...31). The returned value may be None", "");
856bf319
RD
360
361 DocDeclStr(
362 void, SetAttr(size_t day, wxCalendarDateAttr *attr),
dce2bd22
RD
363 "Associates the attribute with the specified date (in the range
3641...31). If the attribute passed is None, the items attribute is
d07d2bc9 365cleared.", "");
856bf319
RD
366
367 DocDeclStr(
368 void, SetHoliday(size_t day),
d07d2bc9 369 "Marks the specified day as being a holiday in the current month.", "");
856bf319
RD
370
371 DocDeclStr(
372 void, ResetAttr(size_t day),
dce2bd22 373 "Clears any attributes associated with the given day (in the range
d07d2bc9 3741...31).", "");
856bf319
RD
375
376
377
378 DocAStr(HitTest,
379 "HitTest(Point pos) -> (result, date, weekday)",
dce2bd22
RD
380"Returns 3-tuple with information about the given position on the
381calendar control. The first value of the tuple is a result code and
d07d2bc9
RD
382determines the validity of the remaining two values.",
383"
384The result codes are:
dce2bd22
RD
385
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 =================== ============================================
856bf319
RD
391");
392 %extend {
393 PyObject* HitTest(const wxPoint& pos) {
394 wxDateTime* date = new wxDateTime;
395 wxDateTime::WeekDay wd;
396 wxCalendarHitTestResult result = self->HitTest(pos, date, &wd);
6e6b3557 397 wxPyBlock_t blocked = wxPyBeginBlockThreads();
856bf319
RD
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));
da32eb53 402 wxPyEndBlockThreads(blocked);
856bf319
RD
403 return tup;
404 }
405 }
406
407 DocDeclStr(
408 wxControl*, GetMonthControl() const,
d07d2bc9 409 "Get the currently shown control for month.", "");
856bf319
RD
410
411 DocDeclStr(
412 wxControl*, GetYearControl() const,
d07d2bc9 413 "Get the currently shown control for year.", "");
880715c9
RD
414
415 static wxVisualAttributes
416 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
f6bcfd97 417
31b46829
RD
418 %pythoncode {
419 def PySetDate(self, date):
420 """takes datetime.datetime or datetime.date object"""
50b42eef 421 self.SetDate(_pydate2wxdate(date))
31b46829
RD
422
423 def PyGetDate(self):
424 """returns datetime.date object"""
50b42eef 425 return _wxdate2pydate(self.GetDate())
31b46829
RD
426
427 def PySetLowerDateLimit(self, date):
428 """takes datetime.datetime or datetime.date object"""
50b42eef 429 self.SetLowerDateLimit(_pydate2wxdate(date))
31b46829
RD
430
431 def PySetUpperDateLimit(self, date):
432 """takes datetime.datetime or datetime.date object"""
50b42eef 433 self.SetUpperDateLimit(_pydate2wxdate(date))
31b46829
RD
434
435 def PySetDateRange(self, lowerdate, upperdate):
436 """takes datetime.datetime or datetime.date objects"""
437 self.PySetLowerDateLimit(lowerdate)
438 self.PySetUpperDateLimit(upperdate)
439
440 def PyGetLowerDateLimit(self):
441 """returns datetime.date object"""
50b42eef 442 return _wxdate2pydate(self.GetLowerDateLimit())
f6bcfd97 443
31b46829
RD
444 def PyGetUpperDateLimit(self):
445 """returns datetime.date object"""
50b42eef 446 return _wxdate2pydate(self.GetUpperDateLimit())
31b46829
RD
447 }
448};
449
450%pythoncode {
50b42eef 451def _pydate2wxdate(date):
31b46829
RD
452 import datetime
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)
457
50b42eef 458def _wxdate2pydate(date):
31b46829
RD
459 import datetime
460 assert isinstance(date, wx.DateTime)
50b42eef
RD
461 if date.IsValid():
462 ymd = map(int, date.FormatISODate().split('-'))
463 return datetime.date(*ymd)
464 else:
465 return None
31b46829
RD
466}
467
f6bcfd97 468//---------------------------------------------------------------------------
e508a2b6
RD
469
470%init %{
e508a2b6
RD
471%}
472
f6bcfd97
BP
473//---------------------------------------------------------------------------
474