From 88cd49f777b967a575f43537c8dc318167c96f47 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Thu, 10 Apr 2003 19:38:11 +0000 Subject: [PATCH] Added __nonzero__ method to more classes that have a Ok or IsOk method. This allows code like "if obj: ..." to be the same as "if obj.Ok: ..." git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@20123 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- wxPython/src/fonts.i | 2 ++ wxPython/src/gdi.i | 12 ++++++++++++ wxPython/src/image.i | 2 ++ wxPython/src/misc2.i | 14 ++++++++++---- wxPython/src/printfw.i | 7 +++++++ wxPython/src/windows.i | 2 -- 6 files changed, 33 insertions(+), 6 deletions(-) diff --git a/wxPython/src/fonts.i b/wxPython/src/fonts.i index 1270262182..0318cccb2a 100644 --- a/wxPython/src/fonts.i +++ b/wxPython/src/fonts.i @@ -374,6 +374,7 @@ public: static wxFontEncoding GetDefaultEncoding(); static void SetDefaultEncoding(wxFontEncoding encoding); + %pragma(python) addtoclass = "def __nonzero__(self): return self.Ok()" }; @@ -962,6 +963,7 @@ public: // equivalent encodings, regardless the platform, including itself. static wxFontEncodingArray GetAllEquivalents(wxFontEncoding enc); + %pragma(python) addtoclass = "def __nonzero__(self): return self.IsOk()" }; diff --git a/wxPython/src/gdi.i b/wxPython/src/gdi.i index e92404a0e2..8048014a5d 100644 --- a/wxPython/src/gdi.i +++ b/wxPython/src/gdi.i @@ -101,6 +101,7 @@ public: void SetQuality(int q); #endif + %pragma(python) addtoclass = "def __nonzero__(self): return self.Ok()" }; @@ -229,6 +230,7 @@ public: #endif void CopyFromBitmap(const wxBitmap& bmp); + %pragma(python) addtoclass = "def __nonzero__(self): return self.Ok()" }; @@ -318,6 +320,7 @@ public: void SetDepth(int d); void SetSize(const wxSize& size); #endif + %pragma(python) addtoclass = "def __nonzero__(self): return self.Ok()" }; %name(wxStockCursor) %new wxCursor* wxPyStockCursor(int id); @@ -473,6 +476,8 @@ public: wxBitmap* GetStipple(); void SetStipple(wxBitmap& stipple); #endif + + %pragma(python) addtoclass = "def __nonzero__(self): return self.Ok()" }; @@ -546,6 +551,8 @@ public: void SetColour(wxColour &colour); void SetStipple(wxBitmap& bitmap); void SetStyle(int style); + + %pragma(python) addtoclass = "def __nonzero__(self): return self.Ok()" }; @@ -705,6 +712,8 @@ public: // See below for implementation } + %pragma(python) addtoclass = "def __nonzero__(self): return self.Ok()" + #ifdef __WXMSW__ long GetHDC(); #endif @@ -959,6 +968,7 @@ public: const wxString& GetFileName() const { return m_filename; } + %pragma(python) addtoclass = "def __nonzero__(self): return self.Ok()" }; // bool wxMakeMetaFilePlaceable(const wxString& filename, @@ -985,6 +995,8 @@ public: int GetPixel(byte red, byte green, byte blue); bool GetRGB(int pixel, byte* OUTPUT, byte* OUTPUT, byte* OUTPUT); bool Ok(); + + %pragma(python) addtoclass = "def __nonzero__(self): return self.Ok()" }; //--------------------------------------------------------------------------- diff --git a/wxPython/src/image.i b/wxPython/src/image.i index 7f125f11bc..0c2883883f 100644 --- a/wxPython/src/image.i +++ b/wxPython/src/image.i @@ -256,6 +256,8 @@ public: return bitmap; } } + + %pragma(python) addtoclass = "def __nonzero__(self): return self.Ok()" }; diff --git a/wxPython/src/misc2.i b/wxPython/src/misc2.i index 15edd72de2..e69f787949 100644 --- a/wxPython/src/misc2.i +++ b/wxPython/src/misc2.i @@ -379,6 +379,8 @@ public: void SetSize(const wxSize& size); void Show(int show = TRUE); void Hide(); + + %pragma(python) addtoclass = "def __nonzero__(self): return self.IsOk()" }; %inline %{ @@ -1050,6 +1052,8 @@ public: bool SetCapture(wxWindow* win, int pollingFreq = 0); bool ReleaseCapture(); + + %pragma(python) addtoclass = "def __nonzero__(self): return self.IsOk()" }; //---------------------------------------------------------------------- @@ -1083,11 +1087,13 @@ public: class wxWave : public wxObject { public: - wxWave(const wxString& fileName, bool isResource = FALSE); - ~wxWave(); + wxWave(const wxString& fileName, bool isResource = FALSE); + ~wxWave(); - bool IsOk() const; - bool Play(bool async = TRUE, bool looped = FALSE) const; + bool IsOk() const; + bool Play(bool async = TRUE, bool looped = FALSE) const; + + %pragma(python) addtoclass = "def __nonzero__(self): return self.IsOk()" }; %new wxWave* wxWaveData(const wxString& data); diff --git a/wxPython/src/printfw.i b/wxPython/src/printfw.i index d543e132a1..bdc2a3d933 100644 --- a/wxPython/src/printfw.i +++ b/wxPython/src/printfw.i @@ -107,6 +107,7 @@ public: void SetPrinterTranslation(long x, long y); void SetPrintMode(wxPrintMode printMode); + %pragma(python) addtoclass = "def __nonzero__(self): return self.Ok()" }; //---------------------------------------------------------------------- @@ -181,6 +182,8 @@ public: void SetPaperId(wxPaperSize id); void SetPaperSize(const wxSize& size); void SetPrintData(const wxPrintData& printData); + + %pragma(python) addtoclass = "def __nonzero__(self): return self.Ok()" }; @@ -231,6 +234,8 @@ public: void SetPrintToFile(bool flag); void SetSetupDialog(bool flag); void SetToPage(int page); + + %pragma(python) addtoclass = "def __nonzero__(self): return self.Ok()" }; @@ -386,6 +391,8 @@ public: void SetFrame(wxFrame *frame); void SetPrintout(wxPyPrintout *printout); void SetZoom(int percent); + + %pragma(python) addtoclass = "def __nonzero__(self): return self.Ok()" }; //---------------------------------------------------------------------- diff --git a/wxPython/src/windows.i b/wxPython/src/windows.i index 3ef5d30c54..de99bdd720 100644 --- a/wxPython/src/windows.i +++ b/wxPython/src/windows.i @@ -730,8 +730,6 @@ public: %name(RemoveItem) wxMenuItem *Remove(wxMenuItem *item); - - %addmethods { void Destroy() { delete self; } }