1 /////////////////////////////////////////////////////////////////////////////
 
   3 // Purpose:     SWIG definitions for the wxCalendarCtrl
 
   7 // Created:     23-May-2000
 
   9 // Copyright:   (c) 2000 by Total Control Software
 
  10 // Licence:     wxWindows license
 
  11 /////////////////////////////////////////////////////////////////////////////
 
  14 "Classes for an interactive Calendar control."
 
  17 %module(package="wx", docstring=DOCSTRING) calendar
 
  21 #include "wx/wxPython/wxPython.h"
 
  22 #include "wx/wxPython/pyclasses.h"
 
  24 #include <wx/calctrl.h>
 
  27 //----------------------------------------------------------------------
 
  30 %pythoncode { wx = _core }
 
  31 %pythoncode { __docfilter__ = wx.__DocFilter(globals()) }
 
  33 %include _calendar_rename.i
 
  35 //---------------------------------------------------------------------------
 
  42     wxCAL_NO_MONTH_CHANGE,
 
  43     wxCAL_SEQUENTIAL_MONTH_SELECTION,
 
  44     wxCAL_SHOW_SURROUNDING_WEEKS,
 
  48 enum wxCalendarHitTestResult
 
  50     wxCAL_HITTEST_NOWHERE,      // outside of anything
 
  51     wxCAL_HITTEST_HEADER,       // on the header (weekdays)
 
  52     wxCAL_HITTEST_DAY,          // on a day in the calendar
 
  53     wxCAL_HITTEST_INCMONTH,
 
  54     wxCAL_HITTEST_DECMONTH,
 
  55     wxCAL_HITTEST_SURROUNDING_WEEK
 
  58 // border types for a date
 
  59 enum wxCalendarDateBorder
 
  61     wxCAL_BORDER_NONE,          // no border (default)
 
  62     wxCAL_BORDER_SQUARE,        // a rectangular border
 
  63     wxCAL_BORDER_ROUND          // a round border
 
  66 //---------------------------------------------------------------------------
 
  68 DocStr(wxCalendarDateAttr,
 
  69 "A set of customization attributes for a calendar date, which can be
 
  70 used to control the look of the Calendar object.", "");
 
  72 class wxCalendarDateAttr
 
  75     DocStr(wxCalendarDateAttr,
 
  76             "Create a CalendarDateAttr.", "");
 
  77     wxCalendarDateAttr(const wxColour& colText = wxNullColour,
 
  78                        const wxColour& colBack = wxNullColour,
 
  79                        const wxColour& colBorder = wxNullColour,
 
  80                        const wxFont& font = wxNullFont,
 
  81                        wxCalendarDateBorder border = wxCAL_BORDER_NONE);
 
  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);
 
  93     bool HasTextColour() const;
 
  94     bool HasBackgroundColour() const;
 
  95     bool HasBorderColour() const;
 
  97     bool HasBorder() const;
 
  99     bool IsHoliday() const;
 
 101     wxColour GetTextColour() const;
 
 102     wxColour GetBackgroundColour() const;
 
 103     wxColour GetBorderColour() const;
 
 104     wxFont GetFont() const;
 
 105     wxCalendarDateBorder GetBorder() const;
 
 108 //---------------------------------------------------------------------------
 
 110 class wxCalendarCtrl;
 
 112 class wxCalendarEvent : public wxCommandEvent
 
 115     wxCalendarEvent(wxCalendarCtrl *cal, wxEventType type);
 
 117     const wxDateTime GetDate() const;
 
 118     void SetDate(const wxDateTime &date);
 
 119     void SetWeekDay(const wxDateTime::WeekDay wd);
 
 120     wxDateTime::WeekDay GetWeekDay() const;
 
 123     def PySetDate(self, date):
 
 124         """takes datetime.datetime or datetime.date object"""
 
 125         self.SetDate(_pydate2wxdate(date))
 
 128         """returns datetime.date object"""
 
 129         return _wxdate2pydate(self.GetDate())
 
 134 %constant wxEventType wxEVT_CALENDAR_DOUBLECLICKED;
 
 135 %constant wxEventType wxEVT_CALENDAR_SEL_CHANGED;
 
 136 %constant wxEventType wxEVT_CALENDAR_DAY_CHANGED;
 
 137 %constant wxEventType wxEVT_CALENDAR_MONTH_CHANGED;
 
 138 %constant wxEventType wxEVT_CALENDAR_YEAR_CHANGED;
 
 139 %constant wxEventType wxEVT_CALENDAR_WEEKDAY_CLICKED;
 
 143 EVT_CALENDAR =                 wx.PyEventBinder( wxEVT_CALENDAR_DOUBLECLICKED, 1)
 
 144 EVT_CALENDAR_SEL_CHANGED =     wx.PyEventBinder( wxEVT_CALENDAR_SEL_CHANGED, 1)
 
 145 EVT_CALENDAR_DAY =             wx.PyEventBinder( wxEVT_CALENDAR_DAY_CHANGED, 1)
 
 146 EVT_CALENDAR_MONTH =           wx.PyEventBinder( wxEVT_CALENDAR_MONTH_CHANGED, 1)
 
 147 EVT_CALENDAR_YEAR =            wx.PyEventBinder( wxEVT_CALENDAR_YEAR_CHANGED, 1)
 
 148 EVT_CALENDAR_WEEKDAY_CLICKED = wx.PyEventBinder( wxEVT_CALENDAR_WEEKDAY_CLICKED, 1)
 
 152 //---------------------------------------------------------------------------
 
 154 MAKE_CONST_WXSTRING(CalendarNameStr);
 
 157 DocStr(wxCalendarCtrl,
 
 158 "The calendar control allows the user to pick a date interactively.
 
 160 The CalendarCtrl displays a window containing several parts: the
 
 161 control to pick the month and the year at the top (either or both of
 
 162 them may be disabled) and a month area below them which shows all the
 
 163 days in the month. The user can move the current selection using the
 
 164 keyboard and select the date (generating EVT_CALENDAR event) by
 
 165 pressing <Return> or double clicking it.
 
 167 It has advanced possibilities for the customization of its
 
 168 display. All global settings (such as colours and fonts used) can, of
 
 169 course, be changed. But also, the display style for each day in the
 
 170 month can be set independently using CalendarDateAttr class.
 
 172 An item without custom attributes is drawn with the default colours
 
 173 and font and without border, but setting custom attributes with
 
 174 SetAttr allows to modify its appearance. Just create a custom
 
 175 attribute object and set it for the day you want to be displayed
 
 176 specially A day may be marked as being a holiday, (even if it is not
 
 177 recognized as one by wx.DateTime) by using the SetHoliday method.
 
 179 As the attributes are specified for each day, they may change when the
 
 180 month is changed, so you will often want to update them in an
 
 181 EVT_CALENDAR_MONTH event handler.", "
 
 185     ==============================   ============================
 
 186     CAL_SUNDAY_FIRST                 Show Sunday as the first day
 
 188     CAL_MONDAY_FIRST                 Show Monday as the first day
 
 190     CAL_SHOW_HOLIDAYS                Highlight holidays in the
 
 192     CAL_NO_YEAR_CHANGE               Disable the year changing
 
 193     CAL_NO_MONTH_CHANGE              Disable the month (and,
 
 194                                      implicitly, the year) changing
 
 195     CAL_SHOW_SURROUNDING_WEEKS       Show the neighbouring weeks in
 
 196                                      the previous and next months
 
 197     CAL_SEQUENTIAL_MONTH_SELECTION   Use alternative, more compact,
 
 198                                      style for the month and year
 
 200     ==============================   ============================
 
 202 The default calendar style is CAL_SHOW_HOLIDAYS.
 
 206     =============================  ==============================
 
 207     EVT_CALENDAR                   A day was double clicked in the
 
 209     EVT_CALENDAR_SEL_CHANGED       The selected date changed.
 
 210     EVT_CALENDAR_DAY               The selected day changed.
 
 211     EVT_CALENDAR_MONTH             The selected month changed.
 
 212     EVT_CALENDAR_YEAR              The selected year changed.
 
 213     EVT_CALENDAR_WEEKDAY_CLICKED   User clicked on the week day
 
 215     =============================  ==============================
 
 217 Note that changing the selected date will result in one of
 
 218 EVT_CALENDAR_DAY, MONTH or YEAR events and an EVT_CALENDAR_SEL_CHANGED
 
 224 MustHaveApp(wxCalendarCtrl);
 
 226 class wxCalendarCtrl : public wxControl
 
 229     %pythonAppend wxCalendarCtrl      "self._setOORInfo(self)"
 
 230     %pythonAppend wxCalendarCtrl()    ""
 
 233         wxCalendarCtrl(wxWindow *parent,
 
 235                        const wxDateTime& date = wxDefaultDateTime,
 
 236                        const wxPoint& pos = wxDefaultPosition,
 
 237                        const wxSize& size = wxDefaultSize,
 
 238                        long style = wxCAL_SHOW_HOLIDAYS | wxWANTS_CHARS,
 
 239                        const wxString& name = wxPyCalendarNameStr),
 
 240         "Create and show a calendar control.", "");
 
 244         "Precreate a CalendarCtrl for 2-phase creation.", "",
 
 248         bool , Create(wxWindow *parent,
 
 250                       const wxDateTime& date = wxDefaultDateTime,
 
 251                       const wxPoint& pos = wxDefaultPosition,
 
 252                       const wxSize& size = wxDefaultSize,
 
 253                       long style = wxCAL_SHOW_HOLIDAYS | wxWANTS_CHARS,
 
 254                       const wxString& name = wxPyCalendarNameStr),
 
 255         "Acutally create the GUI portion of the CalendarCtrl for 2-phase
 
 261         void, SetDate(const wxDateTime& date),
 
 262         "Sets the current date.", "");
 
 265         const wxDateTime&, GetDate() const,
 
 266         "Gets the currently selected date.", "");
 
 271         bool, SetLowerDateLimit(const wxDateTime& date = wxDefaultDateTime),
 
 272         "set the range in which selection can occur", "");
 
 275         bool, SetUpperDateLimit(const wxDateTime& date = wxDefaultDateTime),
 
 276         "set the range in which selection can occur", "");
 
 279         const wxDateTime&, GetLowerDateLimit() const,
 
 280         "get the range in which selection can occur", "");
 
 283         const wxDateTime&, GetUpperDateLimit() const,
 
 284         "get the range in which selection can occur", "");
 
 287         bool, SetDateRange(const wxDateTime& lowerdate = wxDefaultDateTime,
 
 288                            const wxDateTime& upperdate = wxDefaultDateTime),
 
 289         "set the range in which selection can occur", "");
 
 295         void, EnableYearChange(bool enable = true),
 
 296         "This function should be used instead of changing CAL_NO_YEAR_CHANGE
 
 297 style bit directly. It allows or disallows the user to change the year
 
 298 interactively.", "");
 
 301         void, EnableMonthChange(bool enable = true),
 
 302         "This function should be used instead of changing CAL_NO_MONTH_CHANGE
 
 303 style bit. It allows or disallows the user to change the month
 
 304 interactively. Note that if the month can not be changed, the year can
 
 305 not be changed either.", "");
 
 308         void, EnableHolidayDisplay(bool display = true),
 
 309         "This function should be used instead of changing CAL_SHOW_HOLIDAYS
 
 310 style bit directly. It enables or disables the special highlighting of
 
 316         void, SetHeaderColours(const wxColour& colFg, const wxColour& colBg),
 
 317         "Header colours are used for painting the weekdays at the top.", "");
 
 320         wxColour, GetHeaderColourFg() const,
 
 321         "Header colours are used for painting the weekdays at the top.", "");
 
 324         wxColour, GetHeaderColourBg() const,
 
 325         "Header colours are used for painting the weekdays at the top.", "");
 
 330         void, SetHighlightColours(const wxColour& colFg, const wxColour& colBg),
 
 331         "Highlight colour is used for the currently selected date.", "");
 
 334         wxColour, GetHighlightColourFg() const,
 
 335         "Highlight colour is used for the currently selected date.", "");
 
 338         wxColour, GetHighlightColourBg() const,
 
 339         "Highlight colour is used for the currently selected date.", "");
 
 344         void, SetHolidayColours(const wxColour& colFg, const wxColour& colBg),
 
 345         "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is
 
 349         wxColour, GetHolidayColourFg() const,
 
 350         "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is
 
 354         wxColour, GetHolidayColourBg() const,
 
 355         "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is
 
 361         wxCalendarDateAttr*, GetAttr(size_t day) const,
 
 362         "Returns the attribute for the given date (should be in the range
 
 363 1...31).  The returned value may be None", "");
 
 366         void, SetAttr(size_t day, wxCalendarDateAttr *attr),
 
 367         "Associates the attribute with the specified date (in the range
 
 368 1...31).  If the attribute passed is None, the items attribute is
 
 372         void, SetHoliday(size_t day),
 
 373         "Marks the specified day as being a holiday in the current month.", "");
 
 376         void, ResetAttr(size_t day),
 
 377         "Clears any attributes associated with the given day (in the range
 
 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.",
 
 388 The result codes are:
 
 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     ===================    ============================================
 
 397         PyObject* HitTest(const wxPoint& pos) {
 
 398             wxDateTime* date = new wxDateTime;
 
 399             wxDateTime::WeekDay wd;
 
 400             wxCalendarHitTestResult result = self->HitTest(pos, date, &wd);
 
 401             bool 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);
 
 412         wxControl*, GetMonthControl() const,
 
 413         "Get the currently shown control for month.", "");
 
 416         wxControl*, GetYearControl() const,
 
 417         "Get the currently shown control for year.", "");
 
 419     static wxVisualAttributes
 
 420     GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
 
 423     def PySetDate(self, date):
 
 424         """takes datetime.datetime or datetime.date object"""
 
 425         self.SetDate(_pydate2wxdate(date))
 
 428         """returns datetime.date object"""
 
 429         return _wxdate2pydate(self.GetDate())
 
 431     def PySetLowerDateLimit(self, date):
 
 432         """takes datetime.datetime or datetime.date object"""
 
 433         self.SetLowerDateLimit(_pydate2wxdate(date))
 
 435     def PySetUpperDateLimit(self, date):
 
 436         """takes datetime.datetime or datetime.date object"""
 
 437         self.SetUpperDateLimit(_pydate2wxdate(date))
 
 439     def PySetDateRange(self, lowerdate, upperdate):
 
 440         """takes datetime.datetime or datetime.date objects"""
 
 441         self.PySetLowerDateLimit(lowerdate)
 
 442         self.PySetUpperDateLimit(upperdate)
 
 444     def PyGetLowerDateLimit(self):
 
 445         """returns datetime.date object"""
 
 446         return _wxdate2pydate(self.GetLowerDateLimit())
 
 448     def PyGetUpperDateLimit(self):
 
 449         """returns datetime.date object"""
 
 450         return _wxdate2pydate(self.GetUpperDateLimit())
 
 455 def _pydate2wxdate(date):
 
 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)
 
 462 def _wxdate2pydate(date):
 
 464     assert isinstance(date, wx.DateTime)
 
 466         ymd = map(int, date.FormatISODate().split('-'))
 
 467         return datetime.date(*ymd)
 
 472 //---------------------------------------------------------------------------
 
 477 //---------------------------------------------------------------------------