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
This commit is contained in:
Robin Dunn
2003-01-10 00:04:55 +00:00
parent d45ca1a3fd
commit 026525162c
3 changed files with 93 additions and 19 deletions

View File

@@ -365,12 +365,25 @@ public:
PyTuple_SetItem(rv, 2, PyInt_FromLong(blue)); PyTuple_SetItem(rv, 2, PyInt_FromLong(blue));
return rv; return rv;
} }
bool __eq__(const wxColour& o) { return *self == o; } bool __eq__(PyObject* obj) {
bool __ne__(const wxColour& o) { return *self != o; } 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 %pragma(python) addtoclass = "asTuple = Get
def __str__(self): return str(self.asTuple()) 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() def __nonzero__(self): return self.Ok()
" "

View File

@@ -1408,7 +1408,7 @@ public:
} }
%pragma(python) addtoclass = " %pragma(python) addtoclass = "
def __str__(self): return str(self.asTuple()) 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 __len__(self): return len(self.asTuple())
def __getitem__(self, index): return self.asTuple()[index] def __getitem__(self, index): return self.asTuple()[index]
def __setitem__(self, index, val): def __setitem__(self, index, val):

View File

@@ -80,13 +80,26 @@ public:
return tup; return tup;
} }
bool __eq__(const wxSize& o) { return *self == o; } bool __eq__(PyObject* obj) {
bool __ne__(const wxSize& o) { return *self != o; } 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 = " %pragma(python) addtoclass = "
def __str__(self): return str(self.asTuple()) 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 __len__(self): return len(self.asTuple())
def __getitem__(self, index): return self.asTuple()[index] def __getitem__(self, index): return self.asTuple()[index]
def __setitem__(self, index, val): def __setitem__(self, index, val):
@@ -129,13 +142,25 @@ public:
return *self - p; return *self - p;
} }
bool __eq__(const wxRealPoint& o) { return *self == o; } bool __eq__(PyObject* obj) {
bool __ne__(const wxRealPoint& o) { return *self != o; } 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 = " %pragma(python) addtoclass = "
def __str__(self): return str(self.asTuple()) 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 __len__(self): return len(self.asTuple())
def __getitem__(self, index): return self.asTuple()[index] def __getitem__(self, index): return self.asTuple()[index]
def __setitem__(self, index, val): def __setitem__(self, index, val):
@@ -176,13 +201,25 @@ public:
return *self - p; return *self - p;
} }
bool __eq__(const wxPoint& o) { return *self == o; } bool __eq__(PyObject* obj) {
bool __ne__(const wxPoint& o) { return *self != o; } 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 = " %pragma(python) addtoclass = "
def __str__(self): return str(self.asTuple()) 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 __len__(self): return len(self.asTuple())
def __getitem__(self, index): return self.asTuple()[index] def __getitem__(self, index): return self.asTuple()[index]
def __setitem__(self, index, val): def __setitem__(self, index, val):
@@ -247,13 +284,25 @@ public:
return *self + rect; return *self + rect;
} }
bool __eq__(const wxRect& o) { return *self == o; } bool __eq__(PyObject* obj) {
bool __ne__(const wxRect& o) { return *self != o; } 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 = " %pragma(python) addtoclass = "
def __str__(self): return str(self.asTuple()) 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 __len__(self): return len(self.asTuple())
def __getitem__(self, index): return self.asTuple()[index] def __getitem__(self, index): return self.asTuple()[index]
def __setitem__(self, index, val): def __setitem__(self, index, val):
@@ -386,8 +435,20 @@ public:
//wxPoint2DDouble& operator/=(double n); //wxPoint2DDouble& operator/=(double n);
//wxPoint2DDouble& operator/=(int n); //wxPoint2DDouble& operator/=(int n);
bool __eq__(const wxPoint2DDouble& pt) { return (*self) == pt; } bool __eq__(PyObject* obj) {
bool __ne__(const wxPoint2DDouble& pt) { return (*self) != pt; } 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() { PyObject* asTuple() {
wxPyBeginBlockThreads(); wxPyBeginBlockThreads();
@@ -401,7 +462,7 @@ public:
%pragma(python) addtoclass = " %pragma(python) addtoclass = "
def __str__(self): return str(self.asTuple()) 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 __len__(self): return len(self.asTuple())
def __getitem__(self, index): return self.asTuple()[index] def __getitem__(self, index): return self.asTuple()[index]
def __setitem__(self, index, val): def __setitem__(self, index, val):