]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/src/misc.i
wxUniversal fixes:
[wxWidgets.git] / wxPython / src / misc.i
index fd0aada052f29c637063a29a40955cdc9a0ac8c5..92f95b87da5c0080f28f925d04f5d422664a434c 100644 (file)
 
 
 //---------------------------------------------------------------------------
+%{
+    // Put some wx default wxChar* values into wxStrings.
+    static const wxString wxPyEmptyString(wxT(""));
+%}
+//---------------------------------------------------------------------------
+
+
+class wxObject {
+public:
+
+    %addmethods {
+        wxString GetClassName() {
+            return self->GetClassInfo()->GetClassName();
+        }
+
+        void Destroy() {
+            delete self;
+        }
+    }
+};
 
+//---------------------------------------------------------------------------
 
 class wxSize {
 public:
@@ -50,14 +71,31 @@ public:
 
     %addmethods {
         PyObject* asTuple() {
+            wxPyBeginBlockThreads();
             PyObject* tup = PyTuple_New(2);
             PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
             PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
+            wxPyEndBlockThreads();
             return tup;
         }
+
+        int __cmp__(const wxSize* sz) {
+            if (! sz) return 1;
+            if (*self == *sz) return 0;
+            return -1;
+        }
     }
-    %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())"
-    %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())"
+
+    %pragma(python) addtoclass = "
+    def __str__(self):                   return str(self.asTuple())
+    def __repr__(self):                  return str(self.asTuple())
+    def __len__(self):                   return len(self.asTuple())
+    def __getitem__(self, index):        return self.asTuple()[index]
+    def __setitem__(self, index, val):
+        if index == 0: self.width = val
+        elif index == 1: self.height = val
+        else: raise IndexError
+"
 
 };
 
@@ -76,9 +114,11 @@ public:
             self->y = y;
         }
         PyObject* asTuple() {
+            wxPyBeginBlockThreads();
             PyObject* tup = PyTuple_New(2);
             PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->x));
             PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->y));
+            wxPyEndBlockThreads();
             return tup;
         }
 
@@ -93,12 +133,21 @@ public:
         }
 
         int __cmp__(const wxRealPoint* p) {
-            if (! p) return 0;
-            return *self == *p;
+            if (! p) return 1;
+            if (*self == *p) return 0;
+            return -1;
         }
     }
-    %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())"
-    %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())"
+    %pragma(python) addtoclass = "
+    def __str__(self):                   return str(self.asTuple())
+    def __repr__(self):                  return str(self.asTuple())
+    def __len__(self):                   return len(self.asTuple())
+    def __getitem__(self, index):        return self.asTuple()[index]
+    def __setitem__(self, index, val):
+        if index == 0: self.width = val
+        elif index == 1: self.height = val
+        else: raise IndexError
+"
 };
 
 
@@ -115,9 +164,11 @@ public:
             self->y = y;
         }
         PyObject* asTuple() {
+            wxPyBeginBlockThreads();
             PyObject* tup = PyTuple_New(2);
             PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
             PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
+            wxPyEndBlockThreads();
             return tup;
         }
 
@@ -132,12 +183,21 @@ public:
         }
 
         int __cmp__(const wxPoint* p) {
-            if (! p) return 0;
-            return *self == *p;
+            if (! p) return 1;
+            if (*self == *p) return 0;
+            return -1;
         }
     }
-    %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())"
-    %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())"
+    %pragma(python) addtoclass = "
+    def __str__(self):                   return str(self.asTuple())
+    def __repr__(self):                  return str(self.asTuple())
+    def __len__(self):                   return len(self.asTuple())
+    def __getitem__(self, index):        return self.asTuple()[index]
+    def __setitem__(self, index, val):
+        if index == 0: self.x = val
+        elif index == 1: self.y = val
+        else: raise IndexError
+"
 };
 
 //---------------------------------------------------------------------------
@@ -178,11 +238,13 @@ public:
 
     %addmethods {
         PyObject* asTuple() {
+            wxPyBeginBlockThreads();
             PyObject* tup = PyTuple_New(4);
             PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
             PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
             PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width));
             PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height));
+            wxPyEndBlockThreads();
             return tup;
         }
 
@@ -192,14 +254,24 @@ public:
         }
 
         int __cmp__(const wxRect* rect) {
-            if (! rect) return 0;
-            return *self == *rect;
+            if (! rect) return 1;
+            if (*self == *rect) return 0;
+            return -1;
         }
     }
 
-    %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())"
-    %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())"
     %pragma(python) addtoclass = "
+    def __str__(self):                   return str(self.asTuple())
+    def __repr__(self):                  return str(self.asTuple())
+    def __len__(self):                   return len(self.asTuple())
+    def __getitem__(self, index):        return self.asTuple()[index]
+    def __setitem__(self, index, val):
+        if index == 0: self.x = val
+        elif index == 1: self.y = val
+        elif index == 2: self.width = val
+        elif index == 3: self.height = val
+        else: raise IndexError
+
     # override the __getattr__ made by SWIG
     def __getattr__(self, name):
         d = {
@@ -252,13 +324,13 @@ public:
         dest = reg1.GetBox();
 
         if (dest != wxRect(0,0,0,0)) {
-            bool doSave = wxPyRestoreThread();
+            wxPyBeginBlockThreads();
             wxRect* newRect = new wxRect(dest);
             obj = wxPyConstructObject((void*)newRect, "wxRect");
             PyObject* one = PyInt_FromLong(1);
             PyObject_SetAttrString(obj, "thisown", one);
             Py_DECREF(one);
-            wxPySaveThread(doSave);
+            wxPyEndBlockThreads();
             return obj;
         }
         Py_INCREF(Py_None);
@@ -274,9 +346,9 @@ long wxNewId();
 void wxRegisterId(long id);
 %name(NewId) long wxNewId();
 %name(RegisterId) void wxRegisterId(long id);
+long wxGetCurrentId();
 
 void wxBell();
-void wxDisplaySize(int *OUTPUT, int *OUTPUT);
 void wxEndBusyCursor();
 
 long wxGetElapsedTime(bool resetTimer = TRUE);
@@ -286,7 +358,7 @@ long wxGetFreeMemory();
 void wxGetMousePosition(int* OUTPUT, int* OUTPUT);
 bool wxIsBusy();
 wxString wxNow();
-bool wxShell(const wxString& command = wxPyEmptyStr);
+bool wxShell(const wxString& command = wxPyEmptyString);
 void wxStartTimer();
 int wxGetOsVersion(int *OUTPUT, int *OUTPUT);
 wxString wxGetOsDescription();
@@ -294,11 +366,13 @@ wxString wxGetOsDescription();
 void wxSleep(int secs);
 void wxUsleep(unsigned long milliseconds);
 bool wxYield();
+bool wxYieldIfNeeded();
 void wxEnableTopLevelWindows(bool enable);
 
 %inline %{
-    char* wxGetResource(char *section, char *entry, char *file = NULL) {
-        char * retval;
+    wxString wxGetResource(const wxString& section, const wxString& entry,
+                           const wxString& file = wxPyEmptyString) {
+        wxChar * retval;
         wxGetResource(section, entry, &retval, file);
         return retval;
     }
@@ -313,7 +387,11 @@ wxString wxGetFullHostName();
 wxString wxGetUserId();
 wxString wxGetUserName();
 wxString wxGetHomeDir();
+wxString wxGetUserHome(const wxString& user = wxPyEmptyString);
+
 
+// When wxApp gets the virtual method magic then enable this.
+// bool wxHandleFatalExceptions(bool doIt = TRUE);
 
 //----------------------------------------------------------------------
 
@@ -330,7 +408,7 @@ enum wxRelationship { wxUnconstrained = 0,
                       wxAbsolute };
 
 
-class wxIndividualLayoutConstraint {
+class wxIndividualLayoutConstraint : public wxObject {
 public:
 //    wxIndividualLayoutConstraint();
 //    ~wxIndividualLayoutConstraint();
@@ -348,7 +426,7 @@ public:
 };
 
 
-class wxLayoutConstraints {
+class wxLayoutConstraints : public wxObject {
 public:
     wxLayoutConstraints();
 
@@ -365,71 +443,6 @@ public:
 }
 
 
-//---------------------------------------------------------------------------
-// Regions, etc.
-
-enum wxRegionContain {
-       wxOutRegion, wxPartRegion, wxInRegion
-};
-
-
-class wxRegion {
-public:
-    wxRegion(long x=0, long y=0, long width=0, long height=0);
-    ~wxRegion();
-
-    void Clear();
-    wxRegionContain Contains(long x, long y);
-    %name(ContainsPoint)wxRegionContain Contains(const wxPoint& pt);
-    %name(ContainsRect)wxRegionContain Contains(const wxRect& rect);
-    %name(ContainsRectDim)wxRegionContain Contains(long x, long y, long w, long h);
-
-    wxRect GetBox();
-
-    bool Intersect(long x, long y, long width, long height);
-    %name(IntersectRect)bool Intersect(const wxRect& rect);
-    %name(IntersectRegion)bool Intersect(const wxRegion& region);
-
-    bool IsEmpty();
-
-    bool Union(long x, long y, long width, long height);
-    %name(UnionRect)bool Union(const wxRect& rect);
-    %name(UnionRegion)bool Union(const wxRegion& region);
-
-    bool Subtract(long x, long y, long width, long height);
-    %name(SubtractRect)bool Subtract(const wxRect& rect);
-    %name(SubtractRegion)bool Subtract(const wxRegion& region);
-
-    bool Xor(long x, long y, long width, long height);
-    %name(XorRect)bool Xor(const wxRect& rect);
-    %name(XorRegion)bool Xor(const wxRegion& region);
-};
-
-
-
-class wxRegionIterator {
-public:
-    wxRegionIterator(const wxRegion& region);
-    ~wxRegionIterator();
-
-    long GetX();
-    long GetY();
-    long GetW();
-    long GetWidth();
-    long GetH();
-    long GetHeight();
-    wxRect GetRect();
-    bool HaveRects();
-    void Reset();
-
-    %addmethods {
-        void Next() {
-            (*self) ++;
-        }
-    };
-};
-
-
 
 //---------------------------------------------------------------------------
 // Accelerator Entry and Table
@@ -446,7 +459,7 @@ public:
 };
 
 
-class wxAcceleratorTable {
+class wxAcceleratorTable : public wxObject {
 public:
     // Can also accept a list of 3-tuples
     wxAcceleratorTable(int LCOUNT, wxAcceleratorEntry* choices);
@@ -469,12 +482,13 @@ extern wxAcceleratorTable wxNullAcceleratorTable;
 
 //---------------------------------------------------------------------------
 
-class wxBusyInfo {
+class wxBusyInfo : public wxObject {
 public:
     wxBusyInfo(const wxString& message);
     ~wxBusyInfo();
 };
 
+
 //---------------------------------------------------------------------------