%module utils
%{
-#include "export.h"
+#include "helpers.h"
#include <wx/config.h>
#include <wx/fileconf.h>
#include <wx/datetime.h>
%}
+//---------------------------------------------------------------------------
+%{
+ // Put some wx default wxChar* values into wxStrings.
+ DECLARE_DEF_STRING2(DateFormatStr, wxT("%c"));
+ static const wxString wxPyEmptyString(wxT(""));
+
+%}
//---------------------------------------------------------------------------
%include typemaps.i
// Import some definitions of other classes, etc.
%import _defs.i
-%pragma(python) code = "import string"
+%pragma(python) code = "import wx"
//---------------------------------------------------------------------------
if (ret) {
PyTuple_SET_ITEM(ret, 0, PyInt_FromLong(flag));
#if wxUSE_UNICODE
- PyTuple_SET_ITEM(ret, 1, PyUnicode_FromUnicode(str.c_str(), str.Len()));
+ PyTuple_SET_ITEM(ret, 1, PyUnicode_FromWideChar(str.c_str(), str.Len()));
#else
PyTuple_SET_ITEM(ret, 1, PyString_FromStringAndSize(str.c_str(), str.Len()));
#endif
enum
{
- wxCONFIG_USE_LOCAL_FILE = 1,
- wxCONFIG_USE_GLOBAL_FILE = 2,
- wxCONFIG_USE_RELATIVE_PATH = 4
+ wxCONFIG_USE_LOCAL_FILE,
+ wxCONFIG_USE_GLOBAL_FILE,
+ wxCONFIG_USE_RELATIVE_PATH,
+ wxCONFIG_USE_NO_ESCAPE_CHARACTERS
};
//---------------------------------------------------------------------------
class wxConfigBase {
public:
-// wxConfigBase(const wxString& appName = wxEmptyString, **** An ABC
-// const wxString& vendorName = wxEmptyString,
-// const wxString& localFilename = wxEmptyString,
-// const wxString& globalFilename = wxEmptyString,
+// wxConfigBase(const wxString& appName = wxPyEmptyString, **** An ABC
+// const wxString& vendorName = wxPyEmptyString,
+// const wxString& localFilename = wxPyEmptyString,
+// const wxString& globalFilename = wxPyEmptyString,
// long style = 0);
~wxConfigBase();
bool IsExpandingEnvVars();
bool IsRecordingDefaults();
- wxString Read(const wxString& key, const wxString& defaultVal = wxEmptyString);
+ wxString Read(const wxString& key, const wxString& defaultVal = wxPyEmptyString);
%addmethods {
long ReadInt(const wxString& key, long defaultVal = 0) {
// This will be a wxRegConfig on Win32 and wxFileConfig otherwise.
class wxConfig : public wxConfigBase {
public:
- wxConfig(const wxString& appName = wxEmptyString,
- const wxString& vendorName = wxEmptyString,
- const wxString& localFilename = wxEmptyString,
- const wxString& globalFilename = wxEmptyString,
+ wxConfig(const wxString& appName = wxPyEmptyString,
+ const wxString& vendorName = wxPyEmptyString,
+ const wxString& localFilename = wxPyEmptyString,
+ const wxString& globalFilename = wxPyEmptyString,
long style = 0);
~wxConfig();
};
// Sometimes it's nice to explicitly have a wxFileConfig too.
class wxFileConfig : public wxConfigBase {
public:
- wxFileConfig(const wxString& appName = wxEmptyString,
- const wxString& vendorName = wxEmptyString,
- const wxString& localFilename = wxEmptyString,
- const wxString& globalFilename = wxEmptyString,
+ wxFileConfig(const wxString& appName = wxPyEmptyString,
+ const wxString& vendorName = wxPyEmptyString,
+ const wxString& localFilename = wxPyEmptyString,
+ const wxString& globalFilename = wxPyEmptyString,
long style = 0);
~wxFileConfig();
};
// return the wxDateTime object for the current time
static inline wxDateTime Now();
+ // return the wxDateTime object for the current time with millisecond
+ // precision (if available on this platform)
+ static wxDateTime UNow();
+
// return the wxDateTime object for today midnight: i.e. as Now() but
// with time set to 0
static inline wxDateTime Today();
// calendar calculations
// set to the given week day in the same week as this one
- wxDateTime& SetToWeekDayInSameWeek(WeekDay weekday);
- wxDateTime GetWeekDayInSameWeek(WeekDay weekday);
+ wxDateTime& SetToWeekDayInSameWeek(WeekDay weekday, WeekFlags flags = Monday_First);
+ wxDateTime GetWeekDayInSameWeek(WeekDay weekday, WeekFlags flags = Monday_First);
// set to the next week day following this one
wxDateTime& SetToNextWeekDay(WeekDay weekday);
// sets the date to the given day of the given week in the year,
// returns TRUE on success and FALSE if given date doesn't exist (e.g.
// numWeek is > 53)
- bool SetToTheWeek(wxDateTime_t numWeek, WeekDay weekday = Mon);
- wxDateTime GetWeek(wxDateTime_t numWeek, WeekDay weekday = Mon);
+ bool SetToTheWeek(wxDateTime_t numWeek, WeekDay weekday = Mon, WeekFlags flags = Monday_First);
+ wxDateTime GetWeek(wxDateTime_t numWeek, WeekDay weekday = Mon, WeekFlags flags = Monday_First);
// sets the date to the last day of the given (or current) month or the
// given (or current) year
wxDateTime __sub__TS(const wxTimeSpan& other) { return *self - other; }
wxDateTime __sub__DS(const wxDateSpan& other) { return *self - other; }
- int __cmp__(const wxDateTime& other) {
- if (*self < other) return -1;
- if (*self == other) return 0;
+ int __cmp__(const wxDateTime* other) {
+ if (! other) return -1;
+ if (*self < *other) return -1;
+ if (*self == *other) return 0;
return 1;
}
}
%pragma(python) addtoclass = "
def __add__(self, other):
- if string.find(other.this, 'wxTimeSpan') != -1:
+ if isinstance(other, wxTimeSpanPtr):
return self.__add__TS(other)
- if string.find(other.this, 'wxDateSpan') != -1:
+ if isinstance(other, wxDateSpanPtr):
return self.__add__DS(other)
raise TypeError, 'Invalid r.h.s. type for __add__'
def __sub__(self, other):
- if string.find(other.this, 'wxDateTime') != -1:
+ if isinstance(other, wxDateTimePtr):
return self.__sub__DT(other)
- if string.find(other.this, 'wxTimeSpan') != -1:
+ if isinstance(other, wxTimeSpanPtr):
return self.__sub__TS(other)
- if string.find(other.this, 'wxDateSpan') != -1:
+ if isinstance(other, wxDateSpanPtr):
return self.__sub__DS(other)
raise TypeError, 'Invalid r.h.s. type for __sub__'
"
// ------------------------------------------------------------------------
- // conversion to/from text: all conversions from text return the pointer to
- // the next character following the date specification (i.e. the one where
- // the scan had to stop) or NULL on failure.
+ // conversion from text: all conversions from text return -1 on failure,
+ // or the index in the string where the next character following the date
+ // specification (i.e. the one where the scan had to stop) is located.
+
+ %addmethods {
// parse a string in RFC 822 format (found e.g. in mail headers and
// having the form "Wed, 10 Feb 1999 19:07:07 +0100")
- const char *ParseRfc822Date(const wxChar* date);
+ int ParseRfc822Date(const wxString& date) {
+ const wxChar* rv;
+ const wxChar* _date = date;
+ rv = self->ParseRfc822Date(_date);
+ if (rv == NULL) return -1;
+ return rv - _date;
+ }
+
// parse a date/time in the given format (see strptime(3)), fill in
// the missing (in the string) fields with the values of dateDef (by
// default, they will not change if they had valid values or will
// default to Today() otherwise)
- const char *ParseFormat(const wxChar *date,
- const wxChar *format = "%c",
- const wxDateTime& dateDef = wxDefaultDateTime);
+ int ParseFormat(const wxString& date,
+ const wxString& format = wxPyDateFormatStr,
+ const wxDateTime& dateDef = wxDefaultDateTime) {
+ const wxChar* rv;
+ const wxChar* _date = date;
+ rv = self->ParseFormat(_date, format, dateDef);
+ if (rv == NULL) return -1;
+ return rv - _date;
+ }
// parse a string containing the date/time in "free" format, this
// function will try to make an educated guess at the string contents
- const char *ParseDateTime(const wxChar *datetime);
+ int ParseDateTime(const wxString& datetime) {
+ const wxChar* rv;
+ const wxChar* _datetime = datetime;
+ rv = self->ParseDateTime(_datetime);
+ if (rv == NULL) return -1;
+ return rv - _datetime;
+ }
+
// parse a string containing the date only in "free" format (less
// flexible than ParseDateTime)
- const char *ParseDate(const wxChar *date);
+ int ParseDate(const wxString& date) {
+ const wxChar* rv;
+ const wxChar* _date = date;
+ rv = self->ParseDate(_date);
+ if (rv == NULL) return -1;
+ return rv - _date;
+ }
// parse a string containing the time only in "free" format
- const char *ParseTime(const wxChar *time);
+ int ParseTime(const wxString& time) {
+ const wxChar* rv;
+ const wxChar* _time = time;
+ rv = self->ParseTime(_time);
+ if (rv == NULL) return -1;
+ return rv - _time;
+ }
+ }
+
// this function accepts strftime()-like format string (default
// argument corresponds to the preferred date and time representation
// for the current locale) and returns the string containing the
// resulting text representation
- wxString Format(const wxChar *format = "%c",
+ wxString Format(const wxString& format = wxPyDateFormatStr,
const wxDateTime::TimeZone& tz = LOCAL) const;
// preferred date representation for the current locale
wxTimeSpan __mul__(int n) { return *self * n; }
wxTimeSpan __rmul__(int n) { return n * *self; }
wxTimeSpan __neg__() { return self->Negate(); }
- int __cmp__(const wxTimeSpan& other) {
- if (*self < other) return -1;
- if (*self == other) return 0;
+ int __cmp__(const wxTimeSpan* other) {
+ if (! other) return -1;
+ if (*self < *other) return -1;
+ if (*self == *other) return 0;
return 1;
}
}
// resulting text representation. Notice that only some of format
// specifiers valid for wxDateTime are valid for wxTimeSpan: hours,
// minutes and seconds make sense, but not "PM/AM" string for example.
- wxString Format(const wxChar *format = "%c") const;
+ wxString Format(const wxString& format = wxPyDateFormatStr) const;
// // preferred date representation for the current locale
// wxString FormatDate() const;
//---------------------------------------------------------------------------
%init %{
- wxClassInfo::CleanUpClasses();
- wxClassInfo::InitializeClasses();
+ // These are no longer needed since utils is back in the core
+// wxClassInfo::CleanUpClasses();
+// wxClassInfo::InitializeClasses();
%}
//---------------------------------------------------------------------------