From 026525162c62f2cf067a786f8af95205b55f2981 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Fri, 10 Jan 2003 00:04:55 +0000 Subject: [PATCH] Fix various __eq__ and __ne__ operators to also allow comparisons to None. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@18650 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- wxPython/src/gdi.i | 19 ++++++++-- wxPython/src/grid.i | 2 +- wxPython/src/misc.i | 91 +++++++++++++++++++++++++++++++++++++-------- 3 files changed, 93 insertions(+), 19 deletions(-) diff --git a/wxPython/src/gdi.i b/wxPython/src/gdi.i index 5f131b73bf..a86d56c4c0 100644 --- a/wxPython/src/gdi.i +++ b/wxPython/src/gdi.i @@ -365,12 +365,25 @@ public: PyTuple_SetItem(rv, 2, PyInt_FromLong(blue)); return rv; } - bool __eq__(const wxColour& o) { return *self == o; } - bool __ne__(const wxColour& o) { return *self != o; } + bool __eq__(PyObject* obj) { + wxColour tmp; + wxColour* ptr = &tmp; + if (obj == Py_None) return FALSE; + if (! wxColour_helper(obj, &ptr)) return FALSE; + return *self == *ptr; + } + bool __ne__(PyObject* obj) { + wxColour tmp; + wxColour* ptr = &tmp; + if (obj == Py_None) return TRUE; + if (! wxColour_helper(obj, &ptr)) return TRUE; + return *self != *ptr; + } + } %pragma(python) addtoclass = "asTuple = Get def __str__(self): return str(self.asTuple()) - def __repr__(self): return str(self.asTuple()) + def __repr__(self): return 'wxColour: ' + str(self.asTuple()) def __nonzero__(self): return self.Ok() " diff --git a/wxPython/src/grid.i b/wxPython/src/grid.i index f30856d56b..6d241f2f14 100644 --- a/wxPython/src/grid.i +++ b/wxPython/src/grid.i @@ -1408,7 +1408,7 @@ public: } %pragma(python) addtoclass = " def __str__(self): return str(self.asTuple()) - def __repr__(self): return str(self.asTuple()) + def __repr__(self): return 'wxGridCellCoords'+str(self.asTuple()) def __len__(self): return len(self.asTuple()) def __getitem__(self, index): return self.asTuple()[index] def __setitem__(self, index, val): diff --git a/wxPython/src/misc.i b/wxPython/src/misc.i index 0f271d8ca1..bebf74f3af 100644 --- a/wxPython/src/misc.i +++ b/wxPython/src/misc.i @@ -80,13 +80,26 @@ public: return tup; } - bool __eq__(const wxSize& o) { return *self == o; } - bool __ne__(const wxSize& o) { return *self != o; } + bool __eq__(PyObject* obj) { + wxSize tmp; + wxSize* ptr = &tmp; + if (obj == Py_None) return FALSE; + if (! wxSize_helper(obj, &ptr)) return FALSE; + return *self == *ptr; + } + bool __ne__(PyObject* obj) { + wxSize tmp; + wxSize* ptr = &tmp; + if (obj == Py_None) return TRUE; + if (! wxSize_helper(obj, &ptr)) return TRUE; + return *self != *ptr; + } + } %pragma(python) addtoclass = " def __str__(self): return str(self.asTuple()) - def __repr__(self): return str(self.asTuple()) + def __repr__(self): return 'wxSize'+str(self.asTuple()) def __len__(self): return len(self.asTuple()) def __getitem__(self, index): return self.asTuple()[index] def __setitem__(self, index, val): @@ -129,13 +142,25 @@ public: return *self - p; } - bool __eq__(const wxRealPoint& o) { return *self == o; } - bool __ne__(const wxRealPoint& o) { return *self != o; } + bool __eq__(PyObject* obj) { + wxRealPoint tmp; + wxRealPoint* ptr = &tmp; + if (obj == Py_None) return FALSE; + if (! wxRealPoint_helper(obj, &ptr)) return FALSE; + return *self == *ptr; + } + bool __ne__(PyObject* obj) { + wxRealPoint tmp; + wxRealPoint* ptr = &tmp; + if (obj == Py_None) return TRUE; + if (! wxRealPoint_helper(obj, &ptr)) return TRUE; + return *self != *ptr; + } } %pragma(python) addtoclass = " def __str__(self): return str(self.asTuple()) - def __repr__(self): return str(self.asTuple()) + def __repr__(self): return 'wxRealPoint'+str(self.asTuple()) def __len__(self): return len(self.asTuple()) def __getitem__(self, index): return self.asTuple()[index] def __setitem__(self, index, val): @@ -176,13 +201,25 @@ public: return *self - p; } - bool __eq__(const wxPoint& o) { return *self == o; } - bool __ne__(const wxPoint& o) { return *self != o; } + bool __eq__(PyObject* obj) { + wxPoint tmp; + wxPoint* ptr = &tmp; + if (obj == Py_None) return FALSE; + if (! wxPoint_helper(obj, &ptr)) return FALSE; + return *self == *ptr; + } + bool __ne__(PyObject* obj) { + wxPoint tmp; + wxPoint* ptr = &tmp; + if (obj == Py_None) return TRUE; + if (! wxPoint_helper(obj, &ptr)) return TRUE; + return *self != *ptr; + } } %pragma(python) addtoclass = " def __str__(self): return str(self.asTuple()) - def __repr__(self): return str(self.asTuple()) + def __repr__(self): return 'wxPoint'+str(self.asTuple()) def __len__(self): return len(self.asTuple()) def __getitem__(self, index): return self.asTuple()[index] def __setitem__(self, index, val): @@ -247,13 +284,25 @@ public: return *self + rect; } - bool __eq__(const wxRect& o) { return *self == o; } - bool __ne__(const wxRect& o) { return *self != o; } + bool __eq__(PyObject* obj) { + wxRect tmp; + wxRect* ptr = &tmp; + if (obj == Py_None) return FALSE; + if (! wxRect_helper(obj, &ptr)) return FALSE; + return *self == *ptr; + } + bool __ne__(PyObject* obj) { + wxRect tmp; + wxRect* ptr = &tmp; + if (obj == Py_None) return TRUE; + if (! wxRect_helper(obj, &ptr)) return TRUE; + return *self != *ptr; + } } %pragma(python) addtoclass = " def __str__(self): return str(self.asTuple()) - def __repr__(self): return str(self.asTuple()) + def __repr__(self): return 'wxRect'+str(self.asTuple()) def __len__(self): return len(self.asTuple()) def __getitem__(self, index): return self.asTuple()[index] def __setitem__(self, index, val): @@ -386,8 +435,20 @@ public: //wxPoint2DDouble& operator/=(double n); //wxPoint2DDouble& operator/=(int n); - bool __eq__(const wxPoint2DDouble& pt) { return (*self) == pt; } - bool __ne__(const wxPoint2DDouble& pt) { return (*self) != pt; } + bool __eq__(PyObject* obj) { + wxPoint2DDouble tmp; + wxPoint2DDouble* ptr = &tmp; + if (obj == Py_None) return FALSE; + if (! wxPoint2DDouble_helper(obj, &ptr)) return FALSE; + return *self == *ptr; + } + bool __ne__(PyObject* obj) { + wxPoint2DDouble tmp; + wxPoint2DDouble* ptr = &tmp; + if (obj == Py_None) return TRUE; + if (! wxPoint2DDouble_helper(obj, &ptr)) return TRUE; + return *self != *ptr; + } PyObject* asTuple() { wxPyBeginBlockThreads(); @@ -401,7 +462,7 @@ public: %pragma(python) addtoclass = " def __str__(self): return str(self.asTuple()) - def __repr__(self): return str(self.asTuple()) + def __repr__(self): return 'wxPoint2DDouble'+str(self.asTuple()) def __len__(self): return len(self.asTuple()) def __getitem__(self, index): return self.asTuple()[index] def __setitem__(self, index, val):