]>
Commit | Line | Data |
---|---|---|
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 | ||
13 | %define DOCSTRING | |
14 | "Classes for an interactive Calendar control." | |
15 | %enddef | |
16 | ||
17 | %module(package="wx", docstring=DOCSTRING) calendar | |
18 | ||
19 | ||
20 | %{ | |
21 | #include "wx/wxPython/wxPython.h" | |
22 | #include "wx/wxPython/pyclasses.h" | |
23 | ||
24 | #include <wx/calctrl.h> | |
25 | %} | |
26 | ||
27 | //---------------------------------------------------------------------- | |
28 | ||
29 | %import misc.i | |
30 | %pythoncode { wx = _core } | |
31 | %pythoncode { __docfilter__ = wx.__DocFilter(globals()) } | |
32 | ||
33 | //--------------------------------------------------------------------------- | |
34 | ||
35 | enum { | |
36 | wxCAL_SUNDAY_FIRST, | |
37 | wxCAL_MONDAY_FIRST, | |
38 | wxCAL_SHOW_HOLIDAYS, | |
39 | wxCAL_NO_YEAR_CHANGE, | |
40 | wxCAL_NO_MONTH_CHANGE, | |
41 | wxCAL_SEQUENTIAL_MONTH_SELECTION, | |
42 | wxCAL_SHOW_SURROUNDING_WEEKS, | |
43 | }; | |
44 | ||
45 | ||
46 | enum wxCalendarHitTestResult | |
47 | { | |
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 | |
54 | }; | |
55 | ||
56 | // border types for a date | |
57 | enum 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 | ||
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.", ""); | |
69 | ||
70 | class wxCalendarDateAttr | |
71 | { | |
72 | public: | |
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); | |
80 | ||
81 | ~wxCalendarDateAttr(); | |
82 | ||
83 | ||
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 | ||
101 | wxColour GetTextColour() const; | |
102 | wxColour GetBackgroundColour() const; | |
103 | wxColour GetBorderColour() const; | |
104 | wxFont GetFont() const; | |
105 | wxCalendarDateBorder GetBorder() const; | |
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`"); | |
112 | }; | |
113 | ||
114 | //--------------------------------------------------------------------------- | |
115 | ||
116 | class wxCalendarCtrl; | |
117 | ||
118 | class wxCalendarEvent : public wxDateEvent | |
119 | { | |
120 | public: | |
121 | wxCalendarEvent(wxCalendarCtrl *cal, wxEventType type); | |
122 | ||
123 | void SetWeekDay(const wxDateTime::WeekDay wd); | |
124 | wxDateTime::WeekDay GetWeekDay() const; | |
125 | ||
126 | %pythoncode { | |
127 | def PySetDate(self, date): | |
128 | """takes datetime.datetime or datetime.date object""" | |
129 | self.SetDate(_pydate2wxdate(date)) | |
130 | ||
131 | def PyGetDate(self): | |
132 | """returns datetime.date object""" | |
133 | return _wxdate2pydate(self.GetDate()) | |
134 | } | |
135 | ||
136 | %property(WeekDay, GetWeekDay, SetWeekDay, doc="See `GetWeekDay` and `SetWeekDay`"); | |
137 | }; | |
138 | ||
139 | ||
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; | |
146 | ||
147 | ||
148 | %pythoncode { | |
149 | EVT_CALENDAR = wx.PyEventBinder( wxEVT_CALENDAR_DOUBLECLICKED, 1) | |
150 | EVT_CALENDAR_SEL_CHANGED = wx.PyEventBinder( wxEVT_CALENDAR_SEL_CHANGED, 1) | |
151 | EVT_CALENDAR_DAY = wx.PyEventBinder( wxEVT_CALENDAR_DAY_CHANGED, 1) | |
152 | EVT_CALENDAR_MONTH = wx.PyEventBinder( wxEVT_CALENDAR_MONTH_CHANGED, 1) | |
153 | EVT_CALENDAR_YEAR = wx.PyEventBinder( wxEVT_CALENDAR_YEAR_CHANGED, 1) | |
154 | EVT_CALENDAR_WEEKDAY_CLICKED = wx.PyEventBinder( wxEVT_CALENDAR_WEEKDAY_CLICKED, 1) | |
155 | } | |
156 | ||
157 | ||
158 | //--------------------------------------------------------------------------- | |
159 | ||
160 | MAKE_CONST_WXSTRING(CalendarNameStr); | |
161 | ||
162 | ||
163 | DocStr(wxCalendarCtrl, | |
164 | "The calendar control allows the user to pick a date interactively. | |
165 | ||
166 | The CalendarCtrl displays a window containing several parts: the | |
167 | control to pick the month and the year at the top (either or both of | |
168 | them may be disabled) and a month area below them which shows all the | |
169 | days in the month. The user can move the current selection using the | |
170 | keyboard and select the date (generating EVT_CALENDAR event) by | |
171 | pressing <Return> or double clicking it. | |
172 | ||
173 | It has advanced possibilities for the customization of its | |
174 | display. All global settings (such as colours and fonts used) can, of | |
175 | course, be changed. But also, the display style for each day in the | |
176 | month can be set independently using CalendarDateAttr class. | |
177 | ||
178 | An item without custom attributes is drawn with the default colours | |
179 | and font and without border, but setting custom attributes with | |
180 | `SetAttr` allows to modify its appearance. Just create a custom | |
181 | attribute object and set it for the day you want to be displayed | |
182 | specially A day may be marked as being a holiday, (even if it is not | |
183 | recognized as one by `wx.DateTime`) by using the SetHoliday method. | |
184 | ||
185 | As the attributes are specified for each day, they may change when the | |
186 | month is changed, so you will often want to update them in an | |
187 | EVT_CALENDAR_MONTH event handler.", " | |
188 | ||
189 | Window 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. | |
206 | ============================== ============================ | |
207 | ||
208 | The default calendar style is CAL_SHOW_HOLIDAYS. | |
209 | ||
210 | Events | |
211 | ------- | |
212 | ============================= ============================== | |
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 | |
221 | ============================= ============================== | |
222 | ||
223 | Note that changing the selected date will result in one of | |
224 | EVT_CALENDAR_DAY, MONTH or YEAR events and an EVT_CALENDAR_SEL_CHANGED | |
225 | event. | |
226 | ||
227 | "); | |
228 | ||
229 | ||
230 | MustHaveApp(wxCalendarCtrl); | |
231 | ||
232 | class wxCalendarCtrl : public wxControl | |
233 | { | |
234 | public: | |
235 | %pythonAppend wxCalendarCtrl "self._setOORInfo(self)" | |
236 | %pythonAppend wxCalendarCtrl() "" | |
237 | ||
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), | |
246 | "Create and show a calendar control.", ""); | |
247 | ||
248 | DocCtorStrName( | |
249 | wxCalendarCtrl(), | |
250 | "Precreate a CalendarCtrl for 2-phase creation.", "", | |
251 | PreCalendarCtrl); | |
252 | ||
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 | |
262 | creation.", ""); | |
263 | ||
264 | ||
265 | ||
266 | DocDeclStr( | |
267 | void, SetDate(const wxDateTime& date), | |
268 | "Sets the current date.", ""); | |
269 | ||
270 | DocDeclStr( | |
271 | const wxDateTime, GetDate() const, | |
272 | "Gets the currently selected date.", ""); | |
273 | ||
274 | ||
275 | ||
276 | DocDeclStr( | |
277 | bool, SetLowerDateLimit(const wxDateTime& date = wxDefaultDateTime), | |
278 | "set the range in which selection can occur", ""); | |
279 | ||
280 | DocDeclStr( | |
281 | bool, SetUpperDateLimit(const wxDateTime& date = wxDefaultDateTime), | |
282 | "set the range in which selection can occur", ""); | |
283 | ||
284 | DocDeclStr( | |
285 | const wxDateTime, GetLowerDateLimit() const, | |
286 | "get the range in which selection can occur", ""); | |
287 | ||
288 | DocDeclStr( | |
289 | const wxDateTime, GetUpperDateLimit() const, | |
290 | "get the range in which selection can occur", ""); | |
291 | ||
292 | DocDeclStr( | |
293 | bool, SetDateRange(const wxDateTime& lowerdate = wxDefaultDateTime, | |
294 | const wxDateTime& upperdate = wxDefaultDateTime), | |
295 | "set the range in which selection can occur", ""); | |
296 | ||
297 | ||
298 | ||
299 | ||
300 | DocDeclStr( | |
301 | void, EnableYearChange(bool enable = true), | |
302 | "This function should be used instead of changing CAL_NO_YEAR_CHANGE | |
303 | style bit directly. It allows or disallows the user to change the year | |
304 | interactively.", ""); | |
305 | ||
306 | DocDeclStr( | |
307 | void, EnableMonthChange(bool enable = true), | |
308 | "This function should be used instead of changing CAL_NO_MONTH_CHANGE | |
309 | style bit. It allows or disallows the user to change the month | |
310 | interactively. Note that if the month can not be changed, the year can | |
311 | not be changed either.", ""); | |
312 | ||
313 | DocDeclStr( | |
314 | void, EnableHolidayDisplay(bool display = true), | |
315 | "This function should be used instead of changing CAL_SHOW_HOLIDAYS | |
316 | style bit directly. It enables or disables the special highlighting of | |
317 | the holidays.", ""); | |
318 | ||
319 | ||
320 | ||
321 | DocDeclStr( | |
322 | void, SetHeaderColours(const wxColour& colFg, const wxColour& colBg), | |
323 | "Header colours are used for painting the weekdays at the top.", ""); | |
324 | ||
325 | DocDeclStr( | |
326 | wxColour, GetHeaderColourFg() const, | |
327 | "Header colours are used for painting the weekdays at the top.", ""); | |
328 | ||
329 | DocDeclStr( | |
330 | wxColour, GetHeaderColourBg() const, | |
331 | "Header colours are used for painting the weekdays at the top.", ""); | |
332 | ||
333 | ||
334 | ||
335 | DocDeclStr( | |
336 | void, SetHighlightColours(const wxColour& colFg, const wxColour& colBg), | |
337 | "Highlight colour is used for the currently selected date.", ""); | |
338 | ||
339 | DocDeclStr( | |
340 | wxColour, GetHighlightColourFg() const, | |
341 | "Highlight colour is used for the currently selected date.", ""); | |
342 | ||
343 | DocDeclStr( | |
344 | wxColour, GetHighlightColourBg() const, | |
345 | "Highlight colour is used for the currently selected date.", ""); | |
346 | ||
347 | ||
348 | ||
349 | DocDeclStr( | |
350 | void, SetHolidayColours(const wxColour& colFg, const wxColour& colBg), | |
351 | "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is | |
352 | used).", ""); | |
353 | ||
354 | DocDeclStr( | |
355 | wxColour, GetHolidayColourFg() const, | |
356 | "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is | |
357 | used).", ""); | |
358 | ||
359 | DocDeclStr( | |
360 | wxColour, GetHolidayColourBg() const, | |
361 | "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is | |
362 | used).", ""); | |
363 | ||
364 | ||
365 | ||
366 | DocDeclStr( | |
367 | wxCalendarDateAttr*, GetAttr(size_t day) const, | |
368 | "Returns the attribute for the given date (should be in the range | |
369 | 1...31). The returned value may be None", ""); | |
370 | ||
371 | %disownarg(wxCalendarDateAttr *attr); | |
372 | DocDeclStr( | |
373 | void, SetAttr(size_t day, wxCalendarDateAttr *attr), | |
374 | "Associates the attribute with the specified date (in the range | |
375 | 1...31). If the attribute passed is None, the items attribute is | |
376 | cleared.", ""); | |
377 | %cleardisown(wxCalendarDateAttr *attr); | |
378 | ||
379 | DocDeclStr( | |
380 | void, SetHoliday(size_t day), | |
381 | "Marks the specified day as being a holiday in the current month.", ""); | |
382 | ||
383 | DocDeclStr( | |
384 | void, ResetAttr(size_t day), | |
385 | "Clears any attributes associated with the given day (in the range | |
386 | 1...31).", ""); | |
387 | ||
388 | ||
389 | ||
390 | DocAStr(HitTest, | |
391 | "HitTest(Point pos) -> (result, date, weekday)", | |
392 | "Returns 3-tuple with information about the given position on the | |
393 | calendar control. The first value of the tuple is a result code and | |
394 | determines the validity of the remaining two values.", | |
395 | " | |
396 | The result codes are: | |
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 | =================== ============================================ | |
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); | |
409 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
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)); | |
414 | wxPyEndBlockThreads(blocked); | |
415 | return tup; | |
416 | } | |
417 | } | |
418 | ||
419 | DocDeclStr( | |
420 | wxControl*, GetMonthControl() const, | |
421 | "Get the currently shown control for month.", ""); | |
422 | ||
423 | DocDeclStr( | |
424 | wxControl*, GetYearControl() const, | |
425 | "Get the currently shown control for year.", ""); | |
426 | ||
427 | static wxVisualAttributes | |
428 | GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); | |
429 | ||
430 | %pythoncode { | |
431 | def PySetDate(self, date): | |
432 | """takes datetime.datetime or datetime.date object""" | |
433 | self.SetDate(_pydate2wxdate(date)) | |
434 | ||
435 | def PyGetDate(self): | |
436 | """returns datetime.date object""" | |
437 | return _wxdate2pydate(self.GetDate()) | |
438 | ||
439 | def PySetLowerDateLimit(self, date): | |
440 | """takes datetime.datetime or datetime.date object""" | |
441 | self.SetLowerDateLimit(_pydate2wxdate(date)) | |
442 | ||
443 | def PySetUpperDateLimit(self, date): | |
444 | """takes datetime.datetime or datetime.date object""" | |
445 | self.SetUpperDateLimit(_pydate2wxdate(date)) | |
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""" | |
454 | return _wxdate2pydate(self.GetLowerDateLimit()) | |
455 | ||
456 | def PyGetUpperDateLimit(self): | |
457 | """returns datetime.date object""" | |
458 | return _wxdate2pydate(self.GetUpperDateLimit()) | |
459 | } | |
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`"); | |
472 | }; | |
473 | ||
474 | %pythoncode { | |
475 | def _pydate2wxdate(date): | |
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 | ||
482 | def _wxdate2pydate(date): | |
483 | import datetime | |
484 | assert isinstance(date, wx.DateTime) | |
485 | if date.IsValid(): | |
486 | ymd = map(int, date.FormatISODate().split('-')) | |
487 | return datetime.date(*ymd) | |
488 | else: | |
489 | return None | |
490 | } | |
491 | ||
492 | //--------------------------------------------------------------------------- | |
493 | ||
494 | %init %{ | |
495 | %} | |
496 | ||
497 | //--------------------------------------------------------------------------- | |
498 |