Fixed the equality and inequality operators for some of the basic
data types (wx.Point, wx.Size, wx.Colour, etc.) to no longer raise a TypeError if the compared object is not compatible, but to just return a boolean as expected. For example:: wx.Colour(64,0,64) == 123 ==> False git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38493 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -106,14 +106,32 @@ COLORREF is returned. On X, an allocated pixel value is returned. -1
|
|||||||
is returned if the pixel is invalid (on X, unallocated).", "");
|
is returned if the pixel is invalid (on X, unallocated).", "");
|
||||||
|
|
||||||
|
|
||||||
DocDeclStr(
|
%extend {
|
||||||
bool , operator==(const wxColour& colour) const,
|
KeepGIL(__eq__);
|
||||||
"Compare colours for equality", "");
|
DocStr(__eq__, "Compare colours for equality.", "");
|
||||||
|
bool __eq__(PyObject* other) {
|
||||||
|
wxColour temp, *obj = &temp;
|
||||||
|
if ( other == Py_None ) return false;
|
||||||
|
if ( ! wxColour_helper(other, &obj) ) {
|
||||||
|
PyErr_Clear();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return self->operator==(*obj);
|
||||||
|
}
|
||||||
|
|
||||||
DocDeclStr(
|
|
||||||
bool , operator!=(const wxColour& colour) const,
|
|
||||||
"Compare colours for inequality", "");
|
|
||||||
|
|
||||||
|
KeepGIL(__ne__);
|
||||||
|
DocStr(__ne__, "Compare colours for inequality.", "");
|
||||||
|
bool __ne__(PyObject* other) {
|
||||||
|
wxColour temp, *obj = &temp;
|
||||||
|
if ( other == Py_None ) return true;
|
||||||
|
if ( ! wxColour_helper(other, &obj)) {
|
||||||
|
PyErr_Clear();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return self->operator!=(*obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
%extend {
|
%extend {
|
||||||
|
@@ -69,6 +69,14 @@
|
|||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
|
|
||||||
|
// This macro can be used to disable the releasing of the GIL when calling the
|
||||||
|
// C++ function.
|
||||||
|
%define KeepGIL(name)
|
||||||
|
%exception name {
|
||||||
|
$action
|
||||||
|
if (PyErr_Occurred()) SWIG_fail;
|
||||||
|
}
|
||||||
|
%enddef
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
// some type definitions to simplify things for SWIG
|
// some type definitions to simplify things for SWIG
|
||||||
|
@@ -80,13 +80,34 @@ public:
|
|||||||
void SetRow(int row);
|
void SetRow(int row);
|
||||||
void SetCol(int col);
|
void SetCol(int col);
|
||||||
|
|
||||||
// %extend {
|
|
||||||
// bool __eq__(const wxGBPosition* other) { return other ? (*self == *other) : false; }
|
|
||||||
// bool __ne__(const wxGBPosition* other) { return other ? (*self != *other) : true; }
|
|
||||||
// }
|
|
||||||
|
|
||||||
bool operator==(const wxGBPosition& other);
|
%extend {
|
||||||
bool operator!=(const wxGBPosition& other);
|
KeepGIL(__eq__);
|
||||||
|
DocStr(__eq__, "Compare GBPosition for equality.", "");
|
||||||
|
bool __eq__(PyObject* other) {
|
||||||
|
wxGBPosition temp, *obj = &temp;
|
||||||
|
if ( other == Py_None ) return false;
|
||||||
|
if ( ! wxGBPosition_helper(other, &obj) ) {
|
||||||
|
PyErr_Clear();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return self->operator==(*obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
KeepGIL(__ne__);
|
||||||
|
DocStr(__ne__, "Compare GBPosition for inequality.", "");
|
||||||
|
bool __ne__(PyObject* other) {
|
||||||
|
wxGBPosition temp, *obj = &temp;
|
||||||
|
if ( other == Py_None ) return true;
|
||||||
|
if ( ! wxGBPosition_helper(other, &obj)) {
|
||||||
|
PyErr_Clear();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return self->operator!=(*obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
%extend {
|
%extend {
|
||||||
void Set(int row=0, int col=0) {
|
void Set(int row=0, int col=0) {
|
||||||
@@ -151,12 +172,33 @@ cell in each direction.", "");
|
|||||||
void SetRowspan(int rowspan);
|
void SetRowspan(int rowspan);
|
||||||
void SetColspan(int colspan);
|
void SetColspan(int colspan);
|
||||||
|
|
||||||
// %extend {
|
|
||||||
// bool __eq__(const wxGBSpan* other) { return other ? (*self == *other) : false; }
|
%extend {
|
||||||
// bool __ne__(const wxGBSpan* other) { return other ? (*self != *other) : true; }
|
KeepGIL(__eq__);
|
||||||
// }
|
DocStr(__eq__, "Compare wxGBSpan for equality.", "");
|
||||||
bool operator==(const wxGBSpan& other);
|
bool __eq__(PyObject* other) {
|
||||||
bool operator!=(const wxGBSpan& other);
|
wxGBSpan temp, *obj = &temp;
|
||||||
|
if ( other == Py_None ) return false;
|
||||||
|
if ( ! wxGBSpan_helper(other, &obj) ) {
|
||||||
|
PyErr_Clear();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return self->operator==(*obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
KeepGIL(__ne__);
|
||||||
|
DocStr(__ne__, "Compare GBSpan for inequality.", "");
|
||||||
|
bool __ne__(PyObject* other) {
|
||||||
|
wxGBSpan temp, *obj = &temp;
|
||||||
|
if ( other == Py_None ) return true;
|
||||||
|
if ( ! wxGBSpan_helper(other, &obj)) {
|
||||||
|
PyErr_Clear();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return self->operator!=(*obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
%extend {
|
%extend {
|
||||||
|
@@ -130,19 +130,33 @@ public:
|
|||||||
|
|
||||||
~wxSize();
|
~wxSize();
|
||||||
|
|
||||||
// None/NULL is now handled properly by the typemap, so these are not needed.
|
|
||||||
// %extend {
|
|
||||||
// bool __eq__(const wxSize* other) { return other ? (*self == *other) : false; }
|
|
||||||
// bool __ne__(const wxSize* other) { return other ? (*self != *other) : true; }
|
|
||||||
// }
|
|
||||||
|
|
||||||
DocDeclStr(
|
%extend {
|
||||||
bool, operator==(const wxSize& sz),
|
KeepGIL(__eq__);
|
||||||
"Test for equality of wx.Size objects.", "");
|
DocStr(__eq__, "Test for equality of wx.Size objects.", "");
|
||||||
|
bool __eq__(PyObject* other) {
|
||||||
|
wxSize temp, *obj = &temp;
|
||||||
|
if ( other == Py_None ) return false;
|
||||||
|
if ( ! wxSize_helper(other, &obj) ) {
|
||||||
|
PyErr_Clear();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return self->operator==(*obj);
|
||||||
|
}
|
||||||
|
|
||||||
DocDeclStr(
|
|
||||||
bool, operator!=(const wxSize& sz),
|
KeepGIL(__ne__);
|
||||||
"Test for inequality.", "");
|
DocStr(__ne__, "Test for inequality of wx.Size objects.", "");
|
||||||
|
bool __ne__(PyObject* other) {
|
||||||
|
wxSize temp, *obj = &temp;
|
||||||
|
if ( other == Py_None ) return true;
|
||||||
|
if ( ! wxSize_helper(other, &obj)) {
|
||||||
|
PyErr_Clear();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return self->operator!=(*obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
DocDeclStr(
|
DocDeclStr(
|
||||||
wxSize, operator+(const wxSize& sz),
|
wxSize, operator+(const wxSize& sz),
|
||||||
@@ -235,13 +249,32 @@ public:
|
|||||||
|
|
||||||
~wxRealPoint();
|
~wxRealPoint();
|
||||||
|
|
||||||
DocDeclStr(
|
%extend {
|
||||||
bool, operator==(const wxRealPoint& pt),
|
KeepGIL(__eq__);
|
||||||
"Test for equality of wx.RealPoint objects.", "");
|
DocStr(__eq__, "Test for equality of wx.RealPoint objects.", "");
|
||||||
|
bool __eq__(PyObject* other) {
|
||||||
|
wxRealPoint temp, *obj = &temp;
|
||||||
|
if ( other == Py_None ) return false;
|
||||||
|
if ( ! wxRealPoint_helper(other, &obj) ) {
|
||||||
|
PyErr_Clear();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return self->operator==(*obj);
|
||||||
|
}
|
||||||
|
|
||||||
DocDeclStr(
|
|
||||||
bool, operator!=(const wxRealPoint& pt),
|
KeepGIL(__ne__);
|
||||||
"Test for inequality of wx.RealPoint objects.", "");
|
DocStr(__ne__, "Test for inequality of wx.RealPoint objects.", "");
|
||||||
|
bool __ne__(PyObject* other) {
|
||||||
|
wxRealPoint temp, *obj = &temp;
|
||||||
|
if ( other == Py_None ) return true;
|
||||||
|
if ( ! wxRealPoint_helper(other, &obj)) {
|
||||||
|
PyErr_Clear();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return self->operator!=(*obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
DocDeclStr(
|
DocDeclStr(
|
||||||
@@ -311,14 +344,32 @@ public:
|
|||||||
~wxPoint();
|
~wxPoint();
|
||||||
|
|
||||||
|
|
||||||
DocDeclStr(
|
%extend {
|
||||||
bool, operator==(const wxPoint& pt),
|
KeepGIL(__eq__);
|
||||||
"Test for equality of wx.Point objects.", "");
|
DocStr(__eq__, "Test for equality of wx.Point objects.", "");
|
||||||
|
bool __eq__(PyObject* other) {
|
||||||
|
wxPoint temp, *obj = &temp;
|
||||||
|
if ( other == Py_None ) return false;
|
||||||
|
if ( ! wxPoint_helper(other, &obj) ) {
|
||||||
|
PyErr_Clear();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return self->operator==(*obj);
|
||||||
|
}
|
||||||
|
|
||||||
DocDeclStr(
|
|
||||||
bool, operator!=(const wxPoint& pt),
|
|
||||||
"Test for inequality of wx.Point objects.", "");
|
|
||||||
|
|
||||||
|
KeepGIL(__ne__);
|
||||||
|
DocStr(__ne__, "Test for inequality of wx.Point objects.", "");
|
||||||
|
bool __ne__(PyObject* other) {
|
||||||
|
wxPoint temp, *obj = &temp;
|
||||||
|
if ( other == Py_None ) return true;
|
||||||
|
if ( ! wxPoint_helper(other, &obj)) {
|
||||||
|
PyErr_Clear();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return self->operator!=(*obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// %nokwargs operator+;
|
// %nokwargs operator+;
|
||||||
@@ -560,13 +611,32 @@ bottom, otherwise it is moved to the left or top respectively.", "",
|
|||||||
wxRect&, operator+=(const wxRect& rect),
|
wxRect&, operator+=(const wxRect& rect),
|
||||||
"Add the properties of rect to this rectangle, updating this rectangle.", "");
|
"Add the properties of rect to this rectangle, updating this rectangle.", "");
|
||||||
|
|
||||||
DocDeclStr(
|
%extend {
|
||||||
bool, operator==(const wxRect& rect) const,
|
KeepGIL(__eq__);
|
||||||
"Test for equality.", "");
|
DocStr(__eq__, "Test for equality of wx.Rect objects.", "");
|
||||||
|
bool __eq__(PyObject* other) {
|
||||||
|
wxRect temp, *obj = &temp;
|
||||||
|
if ( other == Py_None ) return false;
|
||||||
|
if ( ! wxRect_helper(other, &obj) ) {
|
||||||
|
PyErr_Clear();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return self->operator==(*obj);
|
||||||
|
}
|
||||||
|
|
||||||
DocDeclStr(
|
|
||||||
bool, operator!=(const wxRect& rect) const,
|
KeepGIL(__ne__);
|
||||||
"Test for inequality.", "");
|
DocStr(__ne__, "Test for inequality of wx.Rect objects.", "");
|
||||||
|
bool __ne__(PyObject* other) {
|
||||||
|
wxRect temp, *obj = &temp;
|
||||||
|
if ( other == Py_None ) return true;
|
||||||
|
if ( ! wxRect_helper(other, &obj)) {
|
||||||
|
PyErr_Clear();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return self->operator!=(*obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
DocStr( Inside, "Return True if the point is (not strcitly) inside the rect.", "");
|
DocStr( Inside, "Return True if the point is (not strcitly) inside the rect.", "");
|
||||||
@@ -713,13 +783,32 @@ public:
|
|||||||
wxPoint2D& operator*=(const wxPoint2D& pt);
|
wxPoint2D& operator*=(const wxPoint2D& pt);
|
||||||
wxPoint2D& operator/=(const wxPoint2D& pt);
|
wxPoint2D& operator/=(const wxPoint2D& pt);
|
||||||
|
|
||||||
DocDeclStr(
|
%extend {
|
||||||
bool, operator==(const wxPoint2D& pt) const,
|
KeepGIL(__eq__);
|
||||||
"Test for equality", "");
|
DocStr(__eq__, "Test for equality of wx.Point2D objects.", "");
|
||||||
|
bool __eq__(PyObject* other) {
|
||||||
|
wxPoint2D temp, *obj = &temp;
|
||||||
|
if ( other == Py_None ) return false;
|
||||||
|
if ( ! wxPoint2D_helper(other, &obj) ) {
|
||||||
|
PyErr_Clear();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return self->operator==(*obj);
|
||||||
|
}
|
||||||
|
|
||||||
DocDeclStr(
|
|
||||||
bool, operator!=(const wxPoint2D& pt) const,
|
KeepGIL(__ne__);
|
||||||
"Test for inequality", "");
|
DocStr(__ne__, "Test for inequality of wx.Point2D objects.", "");
|
||||||
|
bool __ne__(PyObject* other) {
|
||||||
|
wxPoint2D temp, *obj = &temp;
|
||||||
|
if ( other == Py_None ) return true;
|
||||||
|
if ( ! wxPoint2D_helper(other, &obj)) {
|
||||||
|
PyErr_Clear();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return self->operator!=(*obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
%Rename(x, double, m_x);
|
%Rename(x, double, m_x);
|
||||||
%Rename(y, double, m_y);
|
%Rename(y, double, m_y);
|
||||||
|
@@ -1534,8 +1534,33 @@ public:
|
|||||||
void SetCol( int n );
|
void SetCol( int n );
|
||||||
void Set( int row, int col );
|
void Set( int row, int col );
|
||||||
|
|
||||||
bool operator==( const wxGridCellCoords& other ) const;
|
%extend {
|
||||||
bool operator!=( const wxGridCellCoords& other ) const;
|
KeepGIL(__eq__);
|
||||||
|
DocStr(__eq__, "Test for equality of GridCellCoords objects.", "");
|
||||||
|
bool __eq__(PyObject* other) {
|
||||||
|
wxGridCellCoords temp, *obj = &temp;
|
||||||
|
if ( other == Py_None ) return false;
|
||||||
|
if ( ! wxGridCellCoords_helper(other, &obj) ) {
|
||||||
|
PyErr_Clear();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return self->operator==(*obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
KeepGIL(__ne__);
|
||||||
|
DocStr(__ne__, "Test for inequality of GridCellCoords objects.", "");
|
||||||
|
bool __ne__(PyObject* other) {
|
||||||
|
wxGridCellCoords temp, *obj = &temp;
|
||||||
|
if ( other == Py_None ) return true;
|
||||||
|
if ( ! wxGridCellCoords_helper(other, &obj)) {
|
||||||
|
PyErr_Clear();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return self->operator!=(*obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
%extend {
|
%extend {
|
||||||
PyObject* Get() {
|
PyObject* Get() {
|
||||||
|
Reference in New Issue
Block a user