X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f6bcfd974ef26faf6f91a62cac09827e09463fd1..32485259c1342115488d219776dfebeb3d4d81b1:/wxPython/src/calendar.i?ds=sidebyside diff --git a/wxPython/src/calendar.i b/wxPython/src/calendar.i index 73fc6bd66a..803632db52 100644 --- a/wxPython/src/calendar.i +++ b/wxPython/src/calendar.i @@ -10,28 +10,27 @@ // Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// -%module calendar +%define DOCSTRING +"Classes for an interactive Calendar control." +%enddef + +%module(package="wx", docstring=DOCSTRING) calendar %{ -#include "helpers.h" +#include "wx/wxPython/wxPython.h" +#include "wx/wxPython/pyclasses.h" + #include %} //---------------------------------------------------------------------- -%include typemaps.i -%include my_typemaps.i - -// Import some definitions of other classes, etc. -%import _defs.i %import misc.i -%import windows.i -%import controls.i -%import events.i -%import utils.i +%pythoncode { wx = _core } +%pythoncode { __docfilter__ = wx.__DocFilter(globals()) } -%pragma(python) code = "import wx" +%include _calendar_rename.i //--------------------------------------------------------------------------- @@ -41,6 +40,8 @@ enum { wxCAL_SHOW_HOLIDAYS, wxCAL_NO_YEAR_CHANGE, wxCAL_NO_MONTH_CHANGE, + wxCAL_SEQUENTIAL_MONTH_SELECTION, + wxCAL_SHOW_SURROUNDING_WEEKS, }; @@ -48,7 +49,10 @@ enum wxCalendarHitTestResult { wxCAL_HITTEST_NOWHERE, // outside of anything wxCAL_HITTEST_HEADER, // on the header (weekdays) - wxCAL_HITTEST_DAY // on a day in the calendar + wxCAL_HITTEST_DAY, // on a day in the calendar + wxCAL_HITTEST_INCMONTH, + wxCAL_HITTEST_DECMONTH, + wxCAL_HITTEST_SURROUNDING_WEEK }; // border types for a date @@ -61,21 +65,22 @@ enum wxCalendarDateBorder //--------------------------------------------------------------------------- +DocStr(wxCalendarDateAttr, +"A set of customization attributes for a calendar date, which can be +used to control the look of the Calendar object.", ""); class wxCalendarDateAttr { public: - // ctors - wxCalendarDateAttr(const wxColour& colText, + DocStr(wxCalendarDateAttr, + "Create a CalendarDateAttr.", ""); + wxCalendarDateAttr(const wxColour& colText = wxNullColour, const wxColour& colBack = wxNullColour, const wxColour& colBorder = wxNullColour, const wxFont& font = wxNullFont, wxCalendarDateBorder border = wxCAL_BORDER_NONE); - %name(wxCalendarDateAttrBorder) - wxCalendarDateAttr(wxCalendarDateBorder border, - const wxColour& colBorder = wxNullColour); - + // setters void SetTextColour(const wxColour& colText); void SetBackgroundColour(const wxColour& colBack); @@ -93,10 +98,10 @@ public: bool IsHoliday() const; - const wxColour& GetTextColour() const; - const wxColour& GetBackgroundColour() const; - const wxColour& GetBorderColour() const; - const wxFont& GetFont() const; + wxColour GetTextColour() const; + wxColour GetBackgroundColour() const; + wxColour GetBorderColour() const; + wxFont GetFont() const; wxCalendarDateBorder GetBorder() const; }; @@ -104,128 +109,368 @@ public: class wxCalendarCtrl; -class wxCalendarEvent : public wxCommandEvent +class wxCalendarEvent : public wxDateEvent { public: wxCalendarEvent(wxCalendarCtrl *cal, wxEventType type); - const wxDateTime& GetDate() const; + void SetWeekDay(const wxDateTime::WeekDay wd); wxDateTime::WeekDay GetWeekDay() const; -}; + %pythoncode { + def PySetDate(self, date): + """takes datetime.datetime or datetime.date object""" + self.SetDate(_pydate2wxdate(date)) -enum { - wxEVT_CALENDAR_DOUBLECLICKED, - wxEVT_CALENDAR_SEL_CHANGED, - wxEVT_CALENDAR_DAY_CHANGED, - wxEVT_CALENDAR_MONTH_CHANGED, - wxEVT_CALENDAR_YEAR_CHANGED, - wxEVT_CALENDAR_WEEKDAY_CLICKED, + def PyGetDate(self): + """returns datetime.date object""" + return _wxdate2pydate(self.GetDate()) + } }; -%pragma(python) code = " -def EVT_CALENDAR(win, id, fn): - win.Connect(id, -1, wxEVT_CALENDAR_DOUBLECLICKED, fn) - -def EVT_CALENDAR_SEL_CHANGED(win, id, fn): - win.Connect(id, -1, wxEVT_CALENDAR_SEL_CHANGED, fn) - -def EVT_CALENDAR_DAY(win, id, fn): - win.Connect(id, -1, wxEVT_CALENDAR_DAY_CHANGED, fn) -def EVT_CALENDAR_MONTH(win, id, fn): - win.Connect(id, -1, wxEVT_CALENDAR_MONTH_CHANGED, fn) +%constant wxEventType wxEVT_CALENDAR_DOUBLECLICKED; +%constant wxEventType wxEVT_CALENDAR_SEL_CHANGED; +%constant wxEventType wxEVT_CALENDAR_DAY_CHANGED; +%constant wxEventType wxEVT_CALENDAR_MONTH_CHANGED; +%constant wxEventType wxEVT_CALENDAR_YEAR_CHANGED; +%constant wxEventType wxEVT_CALENDAR_WEEKDAY_CLICKED; -def EVT_CALENDAR_YEAR(win, id, fn): - win.Connect(id, -1, wxEVT_CALENDAR_YEAR_CHANGED, fn) -def EVT_CALENDAR_WEEKDAY_CLICKED(win, id, fn): - win.Connect(id, -1, wxEVT_CALENDAR_WEEKDAY_CLICKED, fn) +%pythoncode { +EVT_CALENDAR = wx.PyEventBinder( wxEVT_CALENDAR_DOUBLECLICKED, 1) +EVT_CALENDAR_SEL_CHANGED = wx.PyEventBinder( wxEVT_CALENDAR_SEL_CHANGED, 1) +EVT_CALENDAR_DAY = wx.PyEventBinder( wxEVT_CALENDAR_DAY_CHANGED, 1) +EVT_CALENDAR_MONTH = wx.PyEventBinder( wxEVT_CALENDAR_MONTH_CHANGED, 1) +EVT_CALENDAR_YEAR = wx.PyEventBinder( wxEVT_CALENDAR_YEAR_CHANGED, 1) +EVT_CALENDAR_WEEKDAY_CLICKED = wx.PyEventBinder( wxEVT_CALENDAR_WEEKDAY_CLICKED, 1) +} -" //--------------------------------------------------------------------------- +MAKE_CONST_WXSTRING(CalendarNameStr); + + +DocStr(wxCalendarCtrl, +"The calendar control allows the user to pick a date interactively. + +The CalendarCtrl displays a window containing several parts: the +control to pick the month and the year at the top (either or both of +them may be disabled) and a month area below them which shows all the +days in the month. The user can move the current selection using the +keyboard and select the date (generating EVT_CALENDAR event) by +pressing or double clicking it. + +It has advanced possibilities for the customization of its +display. All global settings (such as colours and fonts used) can, of +course, be changed. But also, the display style for each day in the +month can be set independently using CalendarDateAttr class. + +An item without custom attributes is drawn with the default colours +and font and without border, but setting custom attributes with +SetAttr allows to modify its appearance. Just create a custom +attribute object and set it for the day you want to be displayed +specially A day may be marked as being a holiday, (even if it is not +recognized as one by `wx.DateTime`) by using the SetHoliday method. + +As the attributes are specified for each day, they may change when the +month is changed, so you will often want to update them in an +EVT_CALENDAR_MONTH event handler.", " + +Window Styles +------------- + ============================== ============================ + CAL_SUNDAY_FIRST Show Sunday as the first day + in the week + CAL_MONDAY_FIRST Show Monday as the first day + in the week + CAL_SHOW_HOLIDAYS Highlight holidays in the + calendar + CAL_NO_YEAR_CHANGE Disable the year changing + CAL_NO_MONTH_CHANGE Disable the month (and, + implicitly, the year) changing + CAL_SHOW_SURROUNDING_WEEKS Show the neighbouring weeks in + the previous and next months + CAL_SEQUENTIAL_MONTH_SELECTION Use alternative, more compact, + style for the month and year + selection controls. + ============================== ============================ + +The default calendar style is CAL_SHOW_HOLIDAYS. + +Events +------- + ============================= ============================== + EVT_CALENDAR A day was double clicked in the + calendar. + EVT_CALENDAR_SEL_CHANGED The selected date changed. + EVT_CALENDAR_DAY The selected day changed. + EVT_CALENDAR_MONTH The selected month changed. + EVT_CALENDAR_YEAR The selected year changed. + EVT_CALENDAR_WEEKDAY_CLICKED User clicked on the week day + header + ============================= ============================== + +Note that changing the selected date will result in one of +EVT_CALENDAR_DAY, MONTH or YEAR events and an EVT_CALENDAR_SEL_CHANGED +event. + +"); + + +MustHaveApp(wxCalendarCtrl); + class wxCalendarCtrl : public wxControl { public: - // construction - wxCalendarCtrl(wxWindow *parent, - wxWindowID id, - const wxDateTime& date = wxDefaultDateTime, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxCAL_SHOW_HOLIDAYS, - const char* name = "calendar"); - - // set/get the current date - // ------------------------ - - void SetDate(const wxDateTime& date); - const wxDateTime& GetDate() const; - - // calendar mode - // ------------- - - // some calendar styles can't be changed after the control creation by - // just using SetWindowStyle() and Refresh() and the functions below - // should be used instead for them - - // corresponds to wxCAL_NO_YEAR_CHANGE bit - void EnableYearChange(bool enable = TRUE); - - // corresponds to wxCAL_NO_MONTH_CHANGE bit - void EnableMonthChange(bool enable = TRUE); - - // corresponds to wxCAL_SHOW_HOLIDAYS bit - void EnableHolidayDisplay(bool display = TRUE); - - // customization - // ------------- - - // header colours are used for painting the weekdays at the top - void SetHeaderColours(const wxColour& colFg, const wxColour& colBg); - const wxColour& GetHeaderColourFg() const; - const wxColour& GetHeaderColourBg() const; - - // highlight colour is used for the currently selected date - void SetHighlightColours(const wxColour& colFg, const wxColour& colBg); - const wxColour& GetHighlightColourFg() const; - const wxColour& GetHighlightColourBg() const; - - // holiday colour is used for the holidays (if style & wxCAL_SHOW_HOLIDAYS) - void SetHolidayColours(const wxColour& colFg, const wxColour& colBg); - const wxColour& GetHolidayColourFg() const; - const wxColour& GetHolidayColourBg() const; - - // an item without custom attributes is drawn with the default colours and - // font and without border, setting custom attributes allows to modify this - // - // the day parameter should be in 1..31 range, for days 29, 30, 31 the - // corresponding attribute is just unused if there is no such day in the - // current month - - wxCalendarDateAttr *GetAttr(size_t day) const; - void SetAttr(size_t day, wxCalendarDateAttr *attr); - - void SetHoliday(size_t day); - - void ResetAttr(size_t day); - - // returns one of wxCAL_HITTEST_XXX constants and fills either date or wd - // with the corresponding value (none for NOWHERE, the date for DAY and wd - // for HEADER) - wxCalendarHitTestResult HitTest(const wxPoint& pos, - wxDateTime *date = NULL, - wxDateTime::WeekDay *wd = NULL); - + %pythonAppend wxCalendarCtrl "self._setOORInfo(self)" + %pythonAppend wxCalendarCtrl() "" + + DocCtorStr( + wxCalendarCtrl(wxWindow *parent, + wxWindowID id=-1, + const wxDateTime& date = wxDefaultDateTime, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxCAL_SHOW_HOLIDAYS | wxWANTS_CHARS, + const wxString& name = wxPyCalendarNameStr), + "Create and show a calendar control.", ""); + + DocCtorStrName( + wxCalendarCtrl(), + "Precreate a CalendarCtrl for 2-phase creation.", "", + PreCalendarCtrl); + + DocDeclStr( + bool , Create(wxWindow *parent, + wxWindowID id, + const wxDateTime& date = wxDefaultDateTime, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxCAL_SHOW_HOLIDAYS | wxWANTS_CHARS, + const wxString& name = wxPyCalendarNameStr), + "Acutally create the GUI portion of the CalendarCtrl for 2-phase +creation.", ""); + + + + DocDeclStr( + void, SetDate(const wxDateTime& date), + "Sets the current date.", ""); + + DocDeclStr( + const wxDateTime&, GetDate() const, + "Gets the currently selected date.", ""); + + + + DocDeclStr( + bool, SetLowerDateLimit(const wxDateTime& date = wxDefaultDateTime), + "set the range in which selection can occur", ""); + + DocDeclStr( + bool, SetUpperDateLimit(const wxDateTime& date = wxDefaultDateTime), + "set the range in which selection can occur", ""); + + DocDeclStr( + const wxDateTime&, GetLowerDateLimit() const, + "get the range in which selection can occur", ""); + + DocDeclStr( + const wxDateTime&, GetUpperDateLimit() const, + "get the range in which selection can occur", ""); + + DocDeclStr( + bool, SetDateRange(const wxDateTime& lowerdate = wxDefaultDateTime, + const wxDateTime& upperdate = wxDefaultDateTime), + "set the range in which selection can occur", ""); + + + + + DocDeclStr( + void, EnableYearChange(bool enable = true), + "This function should be used instead of changing CAL_NO_YEAR_CHANGE +style bit directly. It allows or disallows the user to change the year +interactively.", ""); + + DocDeclStr( + void, EnableMonthChange(bool enable = true), + "This function should be used instead of changing CAL_NO_MONTH_CHANGE +style bit. It allows or disallows the user to change the month +interactively. Note that if the month can not be changed, the year can +not be changed either.", ""); + + DocDeclStr( + void, EnableHolidayDisplay(bool display = true), + "This function should be used instead of changing CAL_SHOW_HOLIDAYS +style bit directly. It enables or disables the special highlighting of +the holidays.", ""); + + + + DocDeclStr( + void, SetHeaderColours(const wxColour& colFg, const wxColour& colBg), + "Header colours are used for painting the weekdays at the top.", ""); + + DocDeclStr( + wxColour, GetHeaderColourFg() const, + "Header colours are used for painting the weekdays at the top.", ""); + + DocDeclStr( + wxColour, GetHeaderColourBg() const, + "Header colours are used for painting the weekdays at the top.", ""); + + + + DocDeclStr( + void, SetHighlightColours(const wxColour& colFg, const wxColour& colBg), + "Highlight colour is used for the currently selected date.", ""); + + DocDeclStr( + wxColour, GetHighlightColourFg() const, + "Highlight colour is used for the currently selected date.", ""); + + DocDeclStr( + wxColour, GetHighlightColourBg() const, + "Highlight colour is used for the currently selected date.", ""); + + + + DocDeclStr( + void, SetHolidayColours(const wxColour& colFg, const wxColour& colBg), + "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is +used).", ""); + + DocDeclStr( + wxColour, GetHolidayColourFg() const, + "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is +used).", ""); + + DocDeclStr( + wxColour, GetHolidayColourBg() const, + "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is +used).", ""); + + + + DocDeclStr( + wxCalendarDateAttr*, GetAttr(size_t day) const, + "Returns the attribute for the given date (should be in the range +1...31). The returned value may be None", ""); + + DocDeclStr( + void, SetAttr(size_t day, wxCalendarDateAttr *attr), + "Associates the attribute with the specified date (in the range +1...31). If the attribute passed is None, the items attribute is +cleared.", ""); + + DocDeclStr( + void, SetHoliday(size_t day), + "Marks the specified day as being a holiday in the current month.", ""); + + DocDeclStr( + void, ResetAttr(size_t day), + "Clears any attributes associated with the given day (in the range +1...31).", ""); + + + + DocAStr(HitTest, + "HitTest(Point pos) -> (result, date, weekday)", +"Returns 3-tuple with information about the given position on the +calendar control. The first value of the tuple is a result code and +determines the validity of the remaining two values.", +" +The result codes are: + + =================== ============================================ + CAL_HITTEST_NOWHERE hit outside of anything + CAL_HITTEST_HEADER hit on the header, weekday is valid + CAL_HITTEST_DAY hit on a day in the calendar, date is set. + =================== ============================================ +"); + %extend { + PyObject* HitTest(const wxPoint& pos) { + wxDateTime* date = new wxDateTime; + wxDateTime::WeekDay wd; + wxCalendarHitTestResult result = self->HitTest(pos, date, &wd); + wxPyBlock_t blocked = wxPyBeginBlockThreads(); + PyObject* tup = PyTuple_New(3); + PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(result)); + PyTuple_SET_ITEM(tup, 1, wxPyConstructObject(date, wxT("wxDateTime"), 1)); + PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(wd)); + wxPyEndBlockThreads(blocked); + return tup; + } + } + + DocDeclStr( + wxControl*, GetMonthControl() const, + "Get the currently shown control for month.", ""); + + DocDeclStr( + wxControl*, GetYearControl() const, + "Get the currently shown control for year.", ""); + + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + + %pythoncode { + def PySetDate(self, date): + """takes datetime.datetime or datetime.date object""" + self.SetDate(_pydate2wxdate(date)) + + def PyGetDate(self): + """returns datetime.date object""" + return _wxdate2pydate(self.GetDate()) + + def PySetLowerDateLimit(self, date): + """takes datetime.datetime or datetime.date object""" + self.SetLowerDateLimit(_pydate2wxdate(date)) + + def PySetUpperDateLimit(self, date): + """takes datetime.datetime or datetime.date object""" + self.SetUpperDateLimit(_pydate2wxdate(date)) + + def PySetDateRange(self, lowerdate, upperdate): + """takes datetime.datetime or datetime.date objects""" + self.PySetLowerDateLimit(lowerdate) + self.PySetUpperDateLimit(upperdate) + + def PyGetLowerDateLimit(self): + """returns datetime.date object""" + return _wxdate2pydate(self.GetLowerDateLimit()) + + def PyGetUpperDateLimit(self): + """returns datetime.date object""" + return _wxdate2pydate(self.GetUpperDateLimit()) + } }; - -//--------------------------------------------------------------------------- +%pythoncode { +def _pydate2wxdate(date): + import datetime + assert isinstance(date, (datetime.datetime, datetime.date)) + tt = date.timetuple() + dmy = (tt[2], tt[1]-1, tt[0]) + return wx.DateTimeFromDMY(*dmy) + +def _wxdate2pydate(date): + import datetime + assert isinstance(date, wx.DateTime) + if date.IsValid(): + ymd = map(int, date.FormatISODate().split('-')) + return datetime.date(*ymd) + else: + return None +} + //--------------------------------------------------------------------------- -%pragma(python) include="_calextras.py"; +%init %{ +%} //---------------------------------------------------------------------------