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