]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/calendar.i
Add AddStretchSpacer and friends
[wxWidgets.git] / wxPython / src / calendar.i
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
108 //---------------------------------------------------------------------------
109
110 class wxCalendarCtrl;
111
112 class wxCalendarEvent : public wxDateEvent
113 {
114 public:
115 wxCalendarEvent(wxCalendarCtrl *cal, wxEventType type);
116
117 void SetWeekDay(const wxDateTime::WeekDay wd);
118 wxDateTime::WeekDay GetWeekDay() const;
119
120 %pythoncode {
121 def PySetDate(self, date):
122 """takes datetime.datetime or datetime.date object"""
123 self.SetDate(_pydate2wxdate(date))
124
125 def PyGetDate(self):
126 """returns datetime.date object"""
127 return _wxdate2pydate(self.GetDate())
128 }
129 };
130
131
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;
138
139
140 %pythoncode {
141 EVT_CALENDAR = wx.PyEventBinder( wxEVT_CALENDAR_DOUBLECLICKED, 1)
142 EVT_CALENDAR_SEL_CHANGED = wx.PyEventBinder( wxEVT_CALENDAR_SEL_CHANGED, 1)
143 EVT_CALENDAR_DAY = wx.PyEventBinder( wxEVT_CALENDAR_DAY_CHANGED, 1)
144 EVT_CALENDAR_MONTH = wx.PyEventBinder( wxEVT_CALENDAR_MONTH_CHANGED, 1)
145 EVT_CALENDAR_YEAR = wx.PyEventBinder( wxEVT_CALENDAR_YEAR_CHANGED, 1)
146 EVT_CALENDAR_WEEKDAY_CLICKED = wx.PyEventBinder( wxEVT_CALENDAR_WEEKDAY_CLICKED, 1)
147 }
148
149
150 //---------------------------------------------------------------------------
151
152 MAKE_CONST_WXSTRING(CalendarNameStr);
153
154
155 DocStr(wxCalendarCtrl,
156 "The calendar control allows the user to pick a date interactively.
157
158 The CalendarCtrl displays a window containing several parts: the
159 control to pick the month and the year at the top (either or both of
160 them may be disabled) and a month area below them which shows all the
161 days in the month. The user can move the current selection using the
162 keyboard and select the date (generating EVT_CALENDAR event) by
163 pressing <Return> or double clicking it.
164
165 It has advanced possibilities for the customization of its
166 display. All global settings (such as colours and fonts used) can, of
167 course, be changed. But also, the display style for each day in the
168 month can be set independently using CalendarDateAttr class.
169
170 An item without custom attributes is drawn with the default colours
171 and font and without border, but setting custom attributes with
172 `SetAttr` allows to modify its appearance. Just create a custom
173 attribute object and set it for the day you want to be displayed
174 specially A day may be marked as being a holiday, (even if it is not
175 recognized as one by `wx.DateTime`) by using the SetHoliday method.
176
177 As the attributes are specified for each day, they may change when the
178 month is changed, so you will often want to update them in an
179 EVT_CALENDAR_MONTH event handler.", "
180
181 Window 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.
198 ============================== ============================
199
200 The default calendar style is CAL_SHOW_HOLIDAYS.
201
202 Events
203 -------
204 ============================= ==============================
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
213 ============================= ==============================
214
215 Note that changing the selected date will result in one of
216 EVT_CALENDAR_DAY, MONTH or YEAR events and an EVT_CALENDAR_SEL_CHANGED
217 event.
218
219 ");
220
221
222 MustHaveApp(wxCalendarCtrl);
223
224 class wxCalendarCtrl : public wxControl
225 {
226 public:
227 %pythonAppend wxCalendarCtrl "self._setOORInfo(self)"
228 %pythonAppend wxCalendarCtrl() ""
229
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),
238 "Create and show a calendar control.", "");
239
240 DocCtorStrName(
241 wxCalendarCtrl(),
242 "Precreate a CalendarCtrl for 2-phase creation.", "",
243 PreCalendarCtrl);
244
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
254 creation.", "");
255
256
257
258 DocDeclStr(
259 void, SetDate(const wxDateTime& date),
260 "Sets the current date.", "");
261
262 DocDeclStr(
263 const wxDateTime, GetDate() const,
264 "Gets the currently selected date.", "");
265
266
267
268 DocDeclStr(
269 bool, SetLowerDateLimit(const wxDateTime& date = wxDefaultDateTime),
270 "set the range in which selection can occur", "");
271
272 DocDeclStr(
273 bool, SetUpperDateLimit(const wxDateTime& date = wxDefaultDateTime),
274 "set the range in which selection can occur", "");
275
276 DocDeclStr(
277 const wxDateTime, GetLowerDateLimit() const,
278 "get the range in which selection can occur", "");
279
280 DocDeclStr(
281 const wxDateTime, GetUpperDateLimit() const,
282 "get the range in which selection can occur", "");
283
284 DocDeclStr(
285 bool, SetDateRange(const wxDateTime& lowerdate = wxDefaultDateTime,
286 const wxDateTime& upperdate = wxDefaultDateTime),
287 "set the range in which selection can occur", "");
288
289
290
291
292 DocDeclStr(
293 void, EnableYearChange(bool enable = true),
294 "This function should be used instead of changing CAL_NO_YEAR_CHANGE
295 style bit directly. It allows or disallows the user to change the year
296 interactively.", "");
297
298 DocDeclStr(
299 void, EnableMonthChange(bool enable = true),
300 "This function should be used instead of changing CAL_NO_MONTH_CHANGE
301 style bit. It allows or disallows the user to change the month
302 interactively. Note that if the month can not be changed, the year can
303 not be changed either.", "");
304
305 DocDeclStr(
306 void, EnableHolidayDisplay(bool display = true),
307 "This function should be used instead of changing CAL_SHOW_HOLIDAYS
308 style bit directly. It enables or disables the special highlighting of
309 the holidays.", "");
310
311
312
313 DocDeclStr(
314 void, SetHeaderColours(const wxColour& colFg, const wxColour& colBg),
315 "Header colours are used for painting the weekdays at the top.", "");
316
317 DocDeclStr(
318 wxColour, GetHeaderColourFg() const,
319 "Header colours are used for painting the weekdays at the top.", "");
320
321 DocDeclStr(
322 wxColour, GetHeaderColourBg() const,
323 "Header colours are used for painting the weekdays at the top.", "");
324
325
326
327 DocDeclStr(
328 void, SetHighlightColours(const wxColour& colFg, const wxColour& colBg),
329 "Highlight colour is used for the currently selected date.", "");
330
331 DocDeclStr(
332 wxColour, GetHighlightColourFg() const,
333 "Highlight colour is used for the currently selected date.", "");
334
335 DocDeclStr(
336 wxColour, GetHighlightColourBg() const,
337 "Highlight colour is used for the currently selected date.", "");
338
339
340
341 DocDeclStr(
342 void, SetHolidayColours(const wxColour& colFg, const wxColour& colBg),
343 "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is
344 used).", "");
345
346 DocDeclStr(
347 wxColour, GetHolidayColourFg() const,
348 "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is
349 used).", "");
350
351 DocDeclStr(
352 wxColour, GetHolidayColourBg() const,
353 "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is
354 used).", "");
355
356
357
358 DocDeclStr(
359 wxCalendarDateAttr*, GetAttr(size_t day) const,
360 "Returns the attribute for the given date (should be in the range
361 1...31). The returned value may be None", "");
362
363 %disownarg(wxCalendarDateAttr *attr);
364 DocDeclStr(
365 void, SetAttr(size_t day, wxCalendarDateAttr *attr),
366 "Associates the attribute with the specified date (in the range
367 1...31). If the attribute passed is None, the items attribute is
368 cleared.", "");
369 %cleardisown(wxCalendarDateAttr *attr);
370
371 DocDeclStr(
372 void, SetHoliday(size_t day),
373 "Marks the specified day as being a holiday in the current month.", "");
374
375 DocDeclStr(
376 void, ResetAttr(size_t day),
377 "Clears any attributes associated with the given day (in the range
378 1...31).", "");
379
380
381
382 DocAStr(HitTest,
383 "HitTest(Point pos) -> (result, date, weekday)",
384 "Returns 3-tuple with information about the given position on the
385 calendar control. The first value of the tuple is a result code and
386 determines the validity of the remaining two values.",
387 "
388 The result codes are:
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 =================== ============================================
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);
401 wxPyBlock_t blocked = wxPyBeginBlockThreads();
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));
406 wxPyEndBlockThreads(blocked);
407 return tup;
408 }
409 }
410
411 DocDeclStr(
412 wxControl*, GetMonthControl() const,
413 "Get the currently shown control for month.", "");
414
415 DocDeclStr(
416 wxControl*, GetYearControl() const,
417 "Get the currently shown control for year.", "");
418
419 static wxVisualAttributes
420 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
421
422 %pythoncode {
423 def PySetDate(self, date):
424 """takes datetime.datetime or datetime.date object"""
425 self.SetDate(_pydate2wxdate(date))
426
427 def PyGetDate(self):
428 """returns datetime.date object"""
429 return _wxdate2pydate(self.GetDate())
430
431 def PySetLowerDateLimit(self, date):
432 """takes datetime.datetime or datetime.date object"""
433 self.SetLowerDateLimit(_pydate2wxdate(date))
434
435 def PySetUpperDateLimit(self, date):
436 """takes datetime.datetime or datetime.date object"""
437 self.SetUpperDateLimit(_pydate2wxdate(date))
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"""
446 return _wxdate2pydate(self.GetLowerDateLimit())
447
448 def PyGetUpperDateLimit(self):
449 """returns datetime.date object"""
450 return _wxdate2pydate(self.GetUpperDateLimit())
451 }
452 };
453
454 %pythoncode {
455 def _pydate2wxdate(date):
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
462 def _wxdate2pydate(date):
463 import datetime
464 assert isinstance(date, wx.DateTime)
465 if date.IsValid():
466 ymd = map(int, date.FormatISODate().split('-'))
467 return datetime.date(*ymd)
468 else:
469 return None
470 }
471
472 //---------------------------------------------------------------------------
473
474 %init %{
475 %}
476
477 //---------------------------------------------------------------------------
478