]>
Commit | Line | Data |
---|---|---|
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 | ||
13 | %module calendar | |
14 | ||
15 | ||
16 | %{ | |
d14a1e28 RD |
17 | #include "wx/wxPython/wxPython.h" |
18 | #include "wx/wxPython/pyclasses.h" | |
19 | ||
f6bcfd97 BP |
20 | #include <wx/calctrl.h> |
21 | %} | |
22 | ||
23 | //---------------------------------------------------------------------- | |
24 | ||
f6bcfd97 | 25 | %import misc.i |
d14a1e28 | 26 | %pythoncode { wx = core } |
f6bcfd97 | 27 | |
d14a1e28 | 28 | %include _calendar_rename.i |
f6bcfd97 BP |
29 | |
30 | //--------------------------------------------------------------------------- | |
31 | ||
32 | enum { | |
33 | wxCAL_SUNDAY_FIRST, | |
34 | wxCAL_MONDAY_FIRST, | |
35 | wxCAL_SHOW_HOLIDAYS, | |
36 | wxCAL_NO_YEAR_CHANGE, | |
37 | wxCAL_NO_MONTH_CHANGE, | |
ab11ebfa RD |
38 | wxCAL_SEQUENTIAL_MONTH_SELECTION, |
39 | wxCAL_SHOW_SURROUNDING_WEEKS, | |
f6bcfd97 BP |
40 | }; |
41 | ||
42 | ||
43 | enum wxCalendarHitTestResult | |
44 | { | |
45 | wxCAL_HITTEST_NOWHERE, // outside of anything | |
46 | wxCAL_HITTEST_HEADER, // on the header (weekdays) | |
b66824a5 | 47 | wxCAL_HITTEST_DAY, // on a day in the calendar |
ab11ebfa RD |
48 | wxCAL_HITTEST_INCMONTH, |
49 | wxCAL_HITTEST_DECMONTH, | |
50 | wxCAL_HITTEST_SURROUNDING_WEEK | |
f6bcfd97 BP |
51 | }; |
52 | ||
53 | // border types for a date | |
54 | enum wxCalendarDateBorder | |
55 | { | |
56 | wxCAL_BORDER_NONE, // no border (default) | |
57 | wxCAL_BORDER_SQUARE, // a rectangular border | |
58 | wxCAL_BORDER_ROUND // a round border | |
59 | }; | |
60 | ||
61 | //--------------------------------------------------------------------------- | |
62 | ||
856bf319 RD |
63 | DocStr(wxCalendarDateAttr, |
64 | "A set of customization attributes for a calendar date, which can be used to | |
65 | control the look of the Calendar object."); | |
f6bcfd97 BP |
66 | |
67 | class wxCalendarDateAttr | |
68 | { | |
69 | public: | |
856bf319 RD |
70 | DocStr(wxCalendarDateAttr, |
71 | "Create a CalendarDateAttr."); | |
72 | wxCalendarDateAttr(const wxColour& colText = wxNullColour, | |
f6bcfd97 BP |
73 | const wxColour& colBack = wxNullColour, |
74 | const wxColour& colBorder = wxNullColour, | |
75 | const wxFont& font = wxNullFont, | |
76 | wxCalendarDateBorder border = wxCAL_BORDER_NONE); | |
77 | ||
856bf319 | 78 | |
f6bcfd97 BP |
79 | // setters |
80 | void SetTextColour(const wxColour& colText); | |
81 | void SetBackgroundColour(const wxColour& colBack); | |
82 | void SetBorderColour(const wxColour& col); | |
83 | void SetFont(const wxFont& font); | |
84 | void SetBorder(wxCalendarDateBorder border); | |
85 | void SetHoliday(bool holiday); | |
86 | ||
87 | // accessors | |
88 | bool HasTextColour() const; | |
89 | bool HasBackgroundColour() const; | |
90 | bool HasBorderColour() const; | |
91 | bool HasFont() const; | |
92 | bool HasBorder() const; | |
93 | ||
94 | bool IsHoliday() const; | |
95 | ||
c5943253 RD |
96 | wxColour GetTextColour() const; |
97 | wxColour GetBackgroundColour() const; | |
98 | wxColour GetBorderColour() const; | |
99 | wxFont GetFont() const; | |
f6bcfd97 BP |
100 | wxCalendarDateBorder GetBorder() const; |
101 | }; | |
102 | ||
103 | //--------------------------------------------------------------------------- | |
104 | ||
105 | class wxCalendarCtrl; | |
106 | ||
107 | class wxCalendarEvent : public wxCommandEvent | |
108 | { | |
109 | public: | |
110 | wxCalendarEvent(wxCalendarCtrl *cal, wxEventType type); | |
111 | ||
ae5343ec | 112 | const wxDateTime GetDate() const; |
3f0ff538 RD |
113 | void SetDate(const wxDateTime &date); |
114 | void SetWeekDay(const wxDateTime::WeekDay wd); | |
f6bcfd97 BP |
115 | wxDateTime::WeekDay GetWeekDay() const; |
116 | ||
117 | }; | |
118 | ||
f6bcfd97 | 119 | |
d14a1e28 RD |
120 | %constant wxEventType wxEVT_CALENDAR_DOUBLECLICKED; |
121 | %constant wxEventType wxEVT_CALENDAR_SEL_CHANGED; | |
122 | %constant wxEventType wxEVT_CALENDAR_DAY_CHANGED; | |
123 | %constant wxEventType wxEVT_CALENDAR_MONTH_CHANGED; | |
124 | %constant wxEventType wxEVT_CALENDAR_YEAR_CHANGED; | |
125 | %constant wxEventType wxEVT_CALENDAR_WEEKDAY_CLICKED; | |
f6bcfd97 | 126 | |
f6bcfd97 | 127 | |
d14a1e28 RD |
128 | %pythoncode { |
129 | EVT_CALENDAR = wx.PyEventBinder( wxEVT_CALENDAR_DOUBLECLICKED, 1) | |
130 | EVT_CALENDAR_SEL_CHANGED = wx.PyEventBinder( wxEVT_CALENDAR_SEL_CHANGED, 1) | |
131 | EVT_CALENDAR_DAY = wx.PyEventBinder( wxEVT_CALENDAR_DAY_CHANGED, 1) | |
132 | EVT_CALENDAR_MONTH = wx.PyEventBinder( wxEVT_CALENDAR_MONTH_CHANGED, 1) | |
133 | EVT_CALENDAR_YEAR = wx.PyEventBinder( wxEVT_CALENDAR_YEAR_CHANGED, 1) | |
134 | EVT_CALENDAR_WEEKDAY_CLICKED = wx.PyEventBinder( wxEVT_CALENDAR_WEEKDAY_CLICKED, 1) | |
135 | } | |
f6bcfd97 | 136 | |
f6bcfd97 BP |
137 | |
138 | //--------------------------------------------------------------------------- | |
139 | ||
b2dc1044 | 140 | MAKE_CONST_WXSTRING(CalendarNameStr); |
137b5242 | 141 | |
d14a1e28 | 142 | |
856bf319 RD |
143 | DocStr(wxCalendarCtrl, |
144 | "The calendar control allows the user to pick a date interactively."); | |
145 | ||
146 | RefDoc(wxCalendarCtrl, | |
147 | ||
148 | "The CalendarCtrl displays a window containing several parts: the control to | |
149 | pick the month and the year at the top (either or both of them may be | |
150 | disabled) and a month area below them which shows all the days in the | |
151 | month. The user can move the current selection using the keyboard and select | |
152 | the date (generating EVT_CALENDAR event) by pressing <Return> or double | |
153 | clicking it. | |
154 | ||
155 | It has advanced possibilities for the customization of its display. All global | |
156 | settings (such as colours and fonts used) can, of course, be changed. But | |
157 | also, the display style for each day in the month can be set independently | |
158 | using CalendarDateAttr class. | |
159 | ||
160 | An item without custom attributes is drawn with the default colours and font | |
161 | and without border, but setting custom attributes with SetAttr allows to | |
162 | modify its appearance. Just create a custom attribute object and set it for | |
163 | the day you want to be displayed specially A day may be marked as being a | |
164 | holiday, (even if it is not recognized as one by wx.DateTime) by using the | |
165 | SetHoliday method. | |
166 | ||
167 | As the attributes are specified for each day, they may change when the month | |
168 | is changed, so you will often want to update them in an EVT_CALENDAR_MONTH | |
169 | event handler. | |
170 | ||
171 | Styles | |
172 | CAL_SUNDAY_FIRST: Show Sunday as the first day in the week | |
173 | CAL_MONDAY_FIRST: Show Monday as the first day in the week | |
174 | CAL_SHOW_HOLIDAYS: Highlight holidays in the calendar | |
175 | CAL_NO_YEAR_CHANGE: Disable the year changing | |
176 | CAL_NO_MONTH_CHANGE: Disable the month (and, implicitly, the year) changing | |
177 | CAL_SHOW_SURROUNDING_WEEKS: Show the neighbouring weeks in the previous and next months | |
178 | CAL_SEQUENTIAL_MONTH_SELECTION: Use alternative, more compact, style for the month and year selection controls. | |
179 | ||
180 | The default calendar style is wxCAL_SHOW_HOLIDAYS. | |
181 | ||
182 | Events | |
183 | EVT_CALENDAR: A day was double clicked in the calendar. | |
184 | EVT_CALENDAR_SEL_CHANGED: The selected date changed. | |
185 | EVT_CALENDAR_DAY: The selected day changed. | |
186 | EVT_CALENDAR_MONTH: The selected month changed. | |
187 | EVT_CALENDAR_YEAR: The selected year changed. | |
188 | EVT_CALENDAR_WEEKDAY_CLICKED: User clicked on the week day header | |
189 | ||
190 | Note that changing the selected date will result in either of | |
191 | EVT_CALENDAR_DAY, MONTH or YEAR events and an EVT_CALENDAR_SEL_CHANGED event. | |
192 | ||
193 | "); | |
194 | ||
195 | ||
f6bcfd97 BP |
196 | class wxCalendarCtrl : public wxControl |
197 | { | |
198 | public: | |
2b9048c5 RD |
199 | %pythonAppend wxCalendarCtrl "self._setOORInfo(self)" |
200 | %pythonAppend wxCalendarCtrl() "" | |
d14a1e28 | 201 | |
856bf319 | 202 | DocStr(wxCalendarCtrl, "Create and show a calendar control."); |
f6bcfd97 BP |
203 | wxCalendarCtrl(wxWindow *parent, |
204 | wxWindowID id, | |
205 | const wxDateTime& date = wxDefaultDateTime, | |
206 | const wxPoint& pos = wxDefaultPosition, | |
207 | const wxSize& size = wxDefaultSize, | |
bae17009 | 208 | long style = wxCAL_SHOW_HOLIDAYS | wxWANTS_CHARS, |
137b5242 | 209 | const wxString& name = wxPyCalendarNameStr); |
856bf319 RD |
210 | |
211 | ||
212 | DocStr(wxCalendarCtrl(), "Precreate a CalendarCtrl for 2-phase creation."); | |
d14a1e28 | 213 | %name(PreCalendarCtrl)wxCalendarCtrl(); |
09f3d4e6 | 214 | |
856bf319 | 215 | DocStr(Create, "Acutally create the GUI portion of the CalendarCtrl for 2-phase creation."); |
09f3d4e6 RD |
216 | bool Create(wxWindow *parent, |
217 | wxWindowID id, | |
218 | const wxDateTime& date = wxDefaultDateTime, | |
219 | const wxPoint& pos = wxDefaultPosition, | |
220 | const wxSize& size = wxDefaultSize, | |
bae17009 | 221 | long style = wxCAL_SHOW_HOLIDAYS | wxWANTS_CHARS, |
137b5242 | 222 | const wxString& name = wxPyCalendarNameStr); |
f6bcfd97 | 223 | |
0122b7e3 | 224 | |
856bf319 RD |
225 | DocDeclStr( |
226 | void, SetDate(const wxDateTime& date), | |
227 | "Sets the current date."); | |
228 | ||
229 | DocDeclStr( | |
230 | const wxDateTime&, GetDate() const, | |
231 | "Gets the currently selected date."); | |
232 | ||
233 | ||
234 | ||
235 | DocDeclStr( | |
236 | bool, SetLowerDateLimit(const wxDateTime& date = wxDefaultDateTime), | |
237 | "set the range in which selection can occur"); | |
238 | ||
239 | DocDeclStr( | |
240 | bool, SetUpperDateLimit(const wxDateTime& date = wxDefaultDateTime), | |
241 | "set the range in which selection can occur"); | |
242 | ||
243 | DocDeclStr( | |
244 | const wxDateTime&, GetLowerDateLimit() const, | |
245 | "get the range in which selection can occur"); | |
246 | ||
247 | DocDeclStr( | |
248 | const wxDateTime&, GetUpperDateLimit() const, | |
249 | "get the range in which selection can occur"); | |
250 | ||
251 | DocDeclStr( | |
252 | bool, SetDateRange(const wxDateTime& lowerdate = wxDefaultDateTime, | |
253 | const wxDateTime& upperdate = wxDefaultDateTime), | |
254 | "set the range in which selection can occur"); | |
255 | ||
256 | ||
257 | ||
258 | ||
259 | DocDeclStr( | |
260 | void, EnableYearChange(bool enable = True), | |
261 | "This function should be used instead of changing CAL_NO_YEAR_CHANGE\n" | |
262 | "style bit directly. It allows or disallows the user to change the year\n" | |
263 | "interactively."); | |
264 | ||
265 | DocDeclStr( | |
266 | void, EnableMonthChange(bool enable = True), | |
267 | "This function should be used instead of changing CAL_NO_MONTH_CHANGE style\n" | |
268 | "bit. It allows or disallows the user to change the month interactively. Note\n" | |
269 | "that if the month can not be changed, the year can not be changed either."); | |
270 | ||
271 | DocDeclStr( | |
272 | void, EnableHolidayDisplay(bool display = True), | |
273 | "This function should be used instead of changing CAL_SHOW_HOLIDAYS style\n" | |
274 | "bit directly. It enables or disables the special highlighting of the holidays."); | |
275 | ||
276 | ||
277 | ||
278 | DocDeclStr( | |
279 | void, SetHeaderColours(const wxColour& colFg, const wxColour& colBg), | |
280 | "header colours are used for painting the weekdays at the top"); | |
281 | ||
282 | DocDeclStr( | |
283 | wxColour, GetHeaderColourFg() const, | |
284 | "header colours are used for painting the weekdays at the top"); | |
285 | ||
286 | DocDeclStr( | |
287 | wxColour, GetHeaderColourBg() const, | |
288 | "header colours are used for painting the weekdays at the top"); | |
289 | ||
290 | ||
291 | ||
292 | DocDeclStr( | |
293 | void, SetHighlightColours(const wxColour& colFg, const wxColour& colBg), | |
294 | "highlight colour is used for the currently selected date"); | |
295 | ||
296 | DocDeclStr( | |
297 | wxColour, GetHighlightColourFg() const, | |
298 | "highlight colour is used for the currently selected date"); | |
299 | ||
300 | DocDeclStr( | |
301 | wxColour, GetHighlightColourBg() const, | |
302 | "highlight colour is used for the currently selected date"); | |
303 | ||
304 | ||
305 | ||
306 | DocDeclStr( | |
307 | void, SetHolidayColours(const wxColour& colFg, const wxColour& colBg), | |
308 | "holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is used)"); | |
309 | ||
310 | DocDeclStr( | |
311 | wxColour, GetHolidayColourFg() const, | |
312 | "holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is used)"); | |
313 | ||
314 | DocDeclStr( | |
315 | wxColour, GetHolidayColourBg() const, | |
316 | "holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is used)"); | |
317 | ||
318 | ||
319 | ||
320 | DocDeclStr( | |
321 | wxCalendarDateAttr*, GetAttr(size_t day) const, | |
322 | "Returns the attribute for the given date (should be in the range 1...31).\n" | |
323 | "The returned value may be None"); | |
324 | ||
325 | DocDeclStr( | |
326 | void, SetAttr(size_t day, wxCalendarDateAttr *attr), | |
327 | "Associates the attribute with the specified date (in the range 1...31).\n" | |
328 | "If the attribute passed is None, the items attribute is cleared."); | |
329 | ||
330 | DocDeclStr( | |
331 | void, SetHoliday(size_t day), | |
332 | "Marks the specified day as being a holiday in the current month."); | |
333 | ||
334 | DocDeclStr( | |
335 | void, ResetAttr(size_t day), | |
336 | "Clears any attributes associated with the given day (in the range 1...31)."); | |
337 | ||
338 | ||
339 | ||
340 | DocAStr(HitTest, | |
341 | "HitTest(Point pos) -> (result, date, weekday)", | |
342 | "Returns 3-tuple with information about the given position on the calendar | |
343 | control. The first value of the tuple is a result code and determines the | |
344 | validity of the remaining two values. The result codes are: | |
345 | ||
346 | CAL_HITTEST_NOWHERE: hit outside of anything | |
347 | CAL_HITTEST_HEADER: hit on the header, weekday is valid | |
348 | CAL_HITTEST_DAY: hit on a day in the calendar, date is set. | |
349 | "); | |
350 | %extend { | |
351 | PyObject* HitTest(const wxPoint& pos) { | |
352 | wxDateTime* date = new wxDateTime; | |
353 | wxDateTime::WeekDay wd; | |
354 | wxCalendarHitTestResult result = self->HitTest(pos, date, &wd); | |
da32eb53 | 355 | bool blocked = wxPyBeginBlockThreads(); |
856bf319 RD |
356 | PyObject* tup = PyTuple_New(3); |
357 | PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(result)); | |
358 | PyTuple_SET_ITEM(tup, 1, wxPyConstructObject(date, wxT("wxDateTime"), 1)); | |
359 | PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(wd)); | |
da32eb53 | 360 | wxPyEndBlockThreads(blocked); |
856bf319 RD |
361 | return tup; |
362 | } | |
363 | } | |
364 | ||
365 | DocDeclStr( | |
366 | wxControl*, GetMonthControl() const, | |
367 | "get the currently shown control for month"); | |
368 | ||
369 | DocDeclStr( | |
370 | wxControl*, GetYearControl() const, | |
371 | "get the currently shown control for year"); | |
f6bcfd97 BP |
372 | }; |
373 | ||
374 | ||
375 | //--------------------------------------------------------------------------- | |
e508a2b6 RD |
376 | |
377 | %init %{ | |
e508a2b6 RD |
378 | %} |
379 | ||
f6bcfd97 BP |
380 | //--------------------------------------------------------------------------- |
381 |