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 //---------------------------------------------------------------------------
 
  40     wxCAL_NO_MONTH_CHANGE,
 
  41     wxCAL_SEQUENTIAL_MONTH_SELECTION,
 
  42     wxCAL_SHOW_SURROUNDING_WEEKS,
 
  46 enum wxCalendarHitTestResult
 
  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
 
  56 // border types for a date
 
  57 enum wxCalendarDateBorder
 
  59     wxCAL_BORDER_NONE,          // no border (default)
 
  60     wxCAL_BORDER_SQUARE,        // a rectangular border
 
  61     wxCAL_BORDER_ROUND          // a round border
 
  64 //---------------------------------------------------------------------------
 
  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.", "");
 
  70 class wxCalendarDateAttr
 
  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);
 
  81     ~wxCalendarDateAttr();
 
  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;
 
 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`");
 
 114 //---------------------------------------------------------------------------
 
 116 class wxCalendarCtrl;
 
 118 class wxCalendarEvent : public wxDateEvent
 
 121     wxCalendarEvent(wxCalendarCtrl *cal, wxEventType type);
 
 123     void SetWeekDay(const wxDateTime::WeekDay wd);
 
 124     wxDateTime::WeekDay GetWeekDay() const;
 
 127     def PySetDate(self, date):
 
 128         """takes datetime.datetime or datetime.date object"""
 
 129         self.SetDate(_pydate2wxdate(date))
 
 132         """returns datetime.date object"""
 
 133         return _wxdate2pydate(self.GetDate())
 
 136     %property(WeekDay, GetWeekDay, SetWeekDay, doc="See `GetWeekDay` and `SetWeekDay`");
 
 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;
 
 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)
 
 158 //---------------------------------------------------------------------------
 
 160 MAKE_CONST_WXSTRING(CalendarNameStr);
 
 163 DocStr(wxCalendarCtrl,
 
 164 "The calendar control allows the user to pick a date interactively.
 
 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.
 
 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.
 
 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.
 
 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.", "
 
 191     ==============================   ============================
 
 192     CAL_SUNDAY_FIRST                 Show Sunday as the first day
 
 194     CAL_MONDAY_FIRST                 Show Monday as the first day
 
 196     CAL_SHOW_HOLIDAYS                Highlight holidays in the
 
 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
 
 206     ==============================   ============================
 
 208 The default calendar style is CAL_SHOW_HOLIDAYS.
 
 212     =============================  ==============================
 
 213     EVT_CALENDAR                   A day was double clicked in the
 
 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
 
 221     =============================  ==============================
 
 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
 
 230 MustHaveApp(wxCalendarCtrl);
 
 232 class wxCalendarCtrl : public wxControl
 
 235     %pythonAppend wxCalendarCtrl      "self._setOORInfo(self)"
 
 236     %pythonAppend wxCalendarCtrl()    ""
 
 239         wxCalendarCtrl(wxWindow *parent,
 
 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.", "");
 
 250         "Precreate a CalendarCtrl for 2-phase creation.", "",
 
 254         bool , Create(wxWindow *parent,
 
 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
 
 267         void, SetDate(const wxDateTime& date),
 
 268         "Sets the current date.", "");
 
 271         const wxDateTime, GetDate() const,
 
 272         "Gets the currently selected date.", "");
 
 277         bool, SetLowerDateLimit(const wxDateTime& date = wxDefaultDateTime),
 
 278         "set the range in which selection can occur", "");
 
 281         bool, SetUpperDateLimit(const wxDateTime& date = wxDefaultDateTime),
 
 282         "set the range in which selection can occur", "");
 
 285         const wxDateTime, GetLowerDateLimit() const,
 
 286         "get the range in which selection can occur", "");
 
 289         const wxDateTime, GetUpperDateLimit() const,
 
 290         "get the range in which selection can occur", "");
 
 293         bool, SetDateRange(const wxDateTime& lowerdate = wxDefaultDateTime,
 
 294                            const wxDateTime& upperdate = wxDefaultDateTime),
 
 295         "set the range in which selection can occur", "");
 
 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.", "");
 
 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.", "");
 
 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
 
 322         void, SetHeaderColours(const wxColour& colFg, const wxColour& colBg),
 
 323         "Header colours are used for painting the weekdays at the top.", "");
 
 326         wxColour, GetHeaderColourFg() const,
 
 327         "Header colours are used for painting the weekdays at the top.", "");
 
 330         wxColour, GetHeaderColourBg() const,
 
 331         "Header colours are used for painting the weekdays at the top.", "");
 
 336         void, SetHighlightColours(const wxColour& colFg, const wxColour& colBg),
 
 337         "Highlight colour is used for the currently selected date.", "");
 
 340         wxColour, GetHighlightColourFg() const,
 
 341         "Highlight colour is used for the currently selected date.", "");
 
 344         wxColour, GetHighlightColourBg() const,
 
 345         "Highlight colour is used for the currently selected date.", "");
 
 350         void, SetHolidayColours(const wxColour& colFg, const wxColour& colBg),
 
 351         "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is
 
 355         wxColour, GetHolidayColourFg() const,
 
 356         "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is
 
 360         wxColour, GetHolidayColourBg() const,
 
 361         "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is
 
 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", "");
 
 371     %disownarg(wxCalendarDateAttr *attr);
 
 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
 
 377     %cleardisown(wxCalendarDateAttr *attr);
 
 380         void, SetHoliday(size_t day),
 
 381         "Marks the specified day as being a holiday in the current month.", "");
 
 384         void, ResetAttr(size_t day),
 
 385         "Clears any attributes associated with the given day (in the range
 
 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.",
 
 396 The result codes are:
 
 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     ===================    ============================================
 
 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);
 
 420         wxControl*, GetMonthControl() const,
 
 421         "Get the currently shown control for month.", "");
 
 424         wxControl*, GetYearControl() const,
 
 425         "Get the currently shown control for year.", "");
 
 427     static wxVisualAttributes
 
 428     GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
 
 431     def PySetDate(self, date):
 
 432         """takes datetime.datetime or datetime.date object"""
 
 433         self.SetDate(_pydate2wxdate(date))
 
 436         """returns datetime.date object"""
 
 437         return _wxdate2pydate(self.GetDate())
 
 439     def PySetLowerDateLimit(self, date):
 
 440         """takes datetime.datetime or datetime.date object"""
 
 441         self.SetLowerDateLimit(_pydate2wxdate(date))
 
 443     def PySetUpperDateLimit(self, date):
 
 444         """takes datetime.datetime or datetime.date object"""
 
 445         self.SetUpperDateLimit(_pydate2wxdate(date))
 
 447     def PySetDateRange(self, lowerdate, upperdate):
 
 448         """takes datetime.datetime or datetime.date objects"""
 
 449         self.PySetLowerDateLimit(lowerdate)
 
 450         self.PySetUpperDateLimit(upperdate)
 
 452     def PyGetLowerDateLimit(self):
 
 453         """returns datetime.date object"""
 
 454         return _wxdate2pydate(self.GetLowerDateLimit())
 
 456     def PyGetUpperDateLimit(self):
 
 457         """returns datetime.date object"""
 
 458         return _wxdate2pydate(self.GetUpperDateLimit())
 
 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`");
 
 475 def _pydate2wxdate(date):
 
 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)
 
 482 def _wxdate2pydate(date):
 
 484     assert isinstance(date, wx.DateTime)
 
 486         ymd = map(int, date.FormatISODate().split('-'))
 
 487         return datetime.date(*ymd)
 
 492 //---------------------------------------------------------------------------
 
 497 //---------------------------------------------------------------------------