From d72e16bf3cd9b3e7f46ba4418f6016c354ce5150 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 29 Jan 2003 03:20:50 +0000 Subject: [PATCH] Make wxColour, wxPoint, wxSize, and etc. picklable. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@18995 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- wxPython/src/gdi.i | 9 ++++++--- wxPython/src/misc.i | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/wxPython/src/gdi.i b/wxPython/src/gdi.i index f2bab26f0d..ac05b0df6e 100644 --- a/wxPython/src/gdi.i +++ b/wxPython/src/gdi.i @@ -382,9 +382,12 @@ public: } %pragma(python) addtoclass = "asTuple = Get - def __str__(self): return str(self.asTuple()) - def __repr__(self): return 'wxColour: ' + str(self.asTuple()) - def __nonzero__(self): return self.Ok() + def __str__(self): return str(self.asTuple()) + def __repr__(self): return 'wxColour: ' + str(self.asTuple()) + def __nonzero__(self): return self.Ok() + def __getinitargs__(self): return () + def __getstate__(self): return self.asTuple() + def __setstate__(self, state): self.Set(*state) " }; diff --git a/wxPython/src/misc.i b/wxPython/src/misc.i index bebf74f3af..df97206532 100644 --- a/wxPython/src/misc.i +++ b/wxPython/src/misc.i @@ -106,7 +106,10 @@ public: if index == 0: self.width = val elif index == 1: self.height = val else: raise IndexError - def __nonzero__(self): return self.asTuple() != (0,0) + def __nonzero__(self): return self.asTuple() != (0,0) + def __getinitargs__(self): return () + def __getstate__(self): return self.asTuple() + def __setstate__(self, state): self.Set(*state) " }; @@ -168,6 +171,9 @@ public: elif index == 1: self.height = val else: raise IndexError def __nonzero__(self): return self.asTuple() != (0.0, 0.0) + def __getinitargs__(self): return () + def __getstate__(self): return self.asTuple() + def __setstate__(self, state): self.Set(*state) " }; @@ -227,6 +233,9 @@ public: elif index == 1: self.y = val else: raise IndexError def __nonzero__(self): return self.asTuple() != (0,0) + def __getinitargs__(self): return () + def __getstate__(self): return self.asTuple() + def __setstate__(self, state): self.Set(*state) " }; @@ -234,7 +243,7 @@ public: class wxRect { public: - wxRect(int x=0, int y=0, int w=0, int h=0); + wxRect(int x=0, int y=0, int width=0, int height=0); // TODO: do this one too... wxRect(const wxPoint& pos, const wxSize& size); ~wxRect(); @@ -269,6 +278,13 @@ public: int x, y, width, height; %addmethods { + void Set(int x=0, int y=0, int width=0, int height=0) { + self->x = x; + self->y = y; + self->width = width; + self->height = height; + } + PyObject* asTuple() { wxPyBeginBlockThreads(); PyObject* tup = PyTuple_New(4); @@ -311,7 +327,10 @@ 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) + def __nonzero__(self): return self.asTuple() != (0,0,0,0) + def __getinitargs__(self): return () + def __getstate__(self): return self.asTuple() + def __setstate__(self, state): self.Set(*state) # override the __getattr__ made by SWIG def __getattr__(self, name): @@ -421,6 +440,11 @@ public: double GetCrossProduct( const wxPoint2DDouble &vec ) const; %addmethods { + void Set( double x=0 , double y=0 ) { + self->m_x = x; + self->m_y = y; + } + // the reflection of this point wxPoint2DDouble __neg__() { return -(*self); } @@ -469,7 +493,10 @@ public: if index == 0: self.m_x = val elif index == 1: self.m_yt = val else: raise IndexError - def __nonzero__(self): return self.asTuple() != (0.0, 0.0) + def __nonzero__(self): return self.asTuple() != (0.0, 0.0) + def __getinitargs__(self): return () + def __getstate__(self): return self.asTuple() + def __setstate__(self, state): self.Set(*state) " };