From 2b3a3838ee4342134590eb5551f4969038cfe20b Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Mon, 21 Oct 2002 21:04:49 +0000 Subject: [PATCH] Added Python == and != operators for some basic classes git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@17595 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- wxPython/src/gdi.i | 10 +++++++--- wxPython/src/misc.i | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/wxPython/src/gdi.i b/wxPython/src/gdi.i index b5cee56b36..9ce6542ab6 100644 --- a/wxPython/src/gdi.i +++ b/wxPython/src/gdi.i @@ -356,10 +356,14 @@ public: PyTuple_SetItem(rv, 2, PyInt_FromLong(self->Blue())); return rv; } + bool __eq__(const wxColour& o) { return *self == o; } + bool __ne__(const wxColour& o) { return *self != o; } } - %pragma(python) addtoclass = "asTuple = Get" - %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())" - %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())" + %pragma(python) addtoclass = "asTuple = Get + def __str__(self): return str(self.asTuple()) + def __repr__(self): return str(self.asTuple()) + def __nonzero__(self): return self.asTuple() != (0,0,0) +" }; diff --git a/wxPython/src/misc.i b/wxPython/src/misc.i index 482f489f3b..004869c4f0 100644 --- a/wxPython/src/misc.i +++ b/wxPython/src/misc.i @@ -84,6 +84,9 @@ public: if (*self == *sz) return 0; return -1; } + + bool __eq__(const wxSize& o) { return *self == o; } + bool __ne__(const wxSize& o) { return *self != o; } } %pragma(python) addtoclass = " @@ -95,6 +98,7 @@ public: if index == 0: self.width = val elif index == 1: self.height = val else: raise IndexError + def __nonzero__(self): return self.asTuple() != (0,0) " }; @@ -137,6 +141,9 @@ public: if (*self == *p) return 0; return -1; } + + bool __eq__(const wxRealPoint& o) { return *self == o; } + bool __ne__(const wxRealPoint& o) { return *self != o; } } %pragma(python) addtoclass = " def __str__(self): return str(self.asTuple()) @@ -147,6 +154,7 @@ public: if index == 0: self.width = val elif index == 1: self.height = val else: raise IndexError + def __nonzero__(self): return self.asTuple() != (0.0, 0.0) " }; @@ -187,6 +195,9 @@ public: if (*self == *p) return 0; return -1; } + + bool __eq__(const wxPoint& o) { return *self == o; } + bool __ne__(const wxPoint& o) { return *self != o; } } %pragma(python) addtoclass = " def __str__(self): return str(self.asTuple()) @@ -197,6 +208,7 @@ public: if index == 0: self.x = val elif index == 1: self.y = val else: raise IndexError + def __nonzero__(self): return self.asTuple() != (0,0) " }; @@ -260,6 +272,9 @@ public: if (*self == *rect) return 0; return -1; } + + bool __eq__(const wxRect& o) { return *self == o; } + bool __ne__(const wxRect& o) { return *self != o; } } %pragma(python) addtoclass = " @@ -273,6 +288,7 @@ public: elif index == 2: self.width = val elif index == 3: self.height = val else: raise IndexError + def __nonzero__(self): return self.asTuple() != (0,0,0,0) # override the __getattr__ made by SWIG def __getattr__(self, name):