]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/src/helpers.cpp
reSWIGged
[wxWidgets.git] / wxPython / src / helpers.cpp
index 1a23c8f8d671ad2b77894cc29b48abb2dc4073b2..a1a20b66fa7113e7549e295c15205ce3c4559cec 100644 (file)
@@ -126,6 +126,8 @@ wxPyApp::wxPyApp() {
 
 
 wxPyApp::~wxPyApp() {
+    wxPythonApp = NULL;
+    wxApp::SetInstance(NULL);
 }
 
 
@@ -408,11 +410,11 @@ void wxPyApp::_BootstrapApp()
         if (sysargv != NULL && executable != NULL) {
             argc = PyList_Size(sysargv) + 1;
             argv = new char*[argc+1];
-            argv[0] = PyString_AsString(executable);
+            argv[0] = strdup(PyString_AsString(executable));
             int x;
             for(x=1; x<argc; x++) {
                 PyObject *pyArg = PyList_GetItem(sysargv, x-1);
-                argv[x] = PyString_AsString(pyArg);
+                argv[x] = strdup(PyString_AsString(pyArg));
             }
             argv[argc] = NULL;
         }
@@ -420,7 +422,7 @@ void wxPyApp::_BootstrapApp()
 
         // Initialize wxWidgets
         result = wxEntryStart(argc, argv);
-        delete [] argv;
+        // wxApp takes ownership of the argv array, don't delete it here
 
         blocked = wxPyBeginBlockThreads();
         if (! result)  {
@@ -440,7 +442,7 @@ void wxPyApp::_BootstrapApp()
         setlocale(LC_NUMERIC, "C");
 #endif
 
-        wxSystemOptions::SetOption(wxT("mac.textcontrol-use-mlte"), 1);
+//        wxSystemOptions::SetOption(wxT("mac.textcontrol-use-mlte"), 1);
         
         // The stock objects were all NULL when they were loaded into
         // SWIG generated proxies, so re-init those now...
@@ -449,6 +451,11 @@ void wxPyApp::_BootstrapApp()
         wxPyEndBlockThreads(blocked);
         haveInitialized = true;
     }
+    else {
+        this->argc = 0;
+        this->argv = NULL;
+    }
+    
 
     // It's now ok to generate exceptions for assertion errors.
     wxPythonApp->SetStartupComplete(true);
@@ -994,6 +1001,7 @@ void wxPyPtrTypeMap_Add(const char* commonName, const char* ptrName) {
 PyObject*  wxPyMake_wxObject(wxObject* source, bool setThisOwn, bool checkEvtHandler) {
     PyObject* target = NULL;
     bool      isEvtHandler = false;
+    bool      isSizer = false;
 
     if (source) {
         // If it's derived from wxEvtHandler then there may
@@ -1010,6 +1018,18 @@ PyObject*  wxPyMake_wxObject(wxObject* source, bool setThisOwn, bool checkEvtHan
             }
         }
 
+        // Also check for wxSizer
+        if (!target && wxIsKindOf(source, wxSizer)) {
+            isSizer = true;
+            wxSizer* sz = (wxSizer*)source;
+            wxPyOORClientData* data = (wxPyOORClientData*)sz->GetClientObject();
+            if (data) {
+                target = data->m_obj;
+                if (target)
+                    Py_INCREF(target);
+            }
+        }
+        
         if (! target) {
             // Otherwise make it the old fashioned way by making a new shadow
             // object and putting this pointer in it.  Look up the class
@@ -1027,6 +1047,8 @@ PyObject*  wxPyMake_wxObject(wxObject* source, bool setThisOwn, bool checkEvtHan
                 target = wxPyConstructObject((void*)source, name, setThisOwn);
                 if (target && isEvtHandler)
                     ((wxEvtHandler*)source)->SetClientObject(new wxPyOORClientData(target));
+                if (target && isSizer)
+                    ((wxSizer*)source)->SetClientObject(new wxPyOORClientData(target));
             } else {
                 wxString msg(wxT("wxPython class not found for "));
                 msg += source->GetClassInfo()->GetClassName();
@@ -1042,25 +1064,8 @@ PyObject*  wxPyMake_wxObject(wxObject* source, bool setThisOwn, bool checkEvtHan
 
 
 PyObject*  wxPyMake_wxSizer(wxSizer* source, bool setThisOwn) {
-    PyObject* target = NULL;
 
-    if (source && wxIsKindOf(source, wxSizer)) {
-        // If it's derived from wxSizer then there may already be a pointer to
-        // a Python object that we can use in the OOR data.
-        wxSizer* sz = (wxSizer*)source;
-        wxPyOORClientData* data = (wxPyOORClientData*)sz->GetClientObject();
-        if (data) {
-            target = data->m_obj;
-            if (target)
-                Py_INCREF(target);
-        }
-    }
-    if (! target) {
-        target = wxPyMake_wxObject(source, setThisOwn, false);
-        if (target != Py_None)
-            ((wxSizer*)source)->SetClientObject(new wxPyOORClientData(target));
-    }
-    return target;
+    return wxPyMake_wxObject(source, setThisOwn);
 }
 
 
@@ -1162,6 +1167,9 @@ void wxPyEndAllowThreads(PyThreadState* saved) {
 
 wxPyBlock_t wxPyBeginBlockThreads() {
 #ifdef WXP_WITH_THREAD
+    if (! Py_IsInitialized()) {
+        return (wxPyBlock_t)0;
+    }
 #if wxPyUSE_GIL_STATE
     PyGILState_STATE state = PyGILState_Ensure();
     return state;
@@ -1180,13 +1188,16 @@ wxPyBlock_t wxPyBeginBlockThreads() {
     return blocked;
 #endif
 #else
-    return false;
+    return (wxPyBlock_t)0;
 #endif
 }
 
 
 void wxPyEndBlockThreads(wxPyBlock_t blocked) {
 #ifdef WXP_WITH_THREAD
+    if (! Py_IsInitialized()) {
+        return;
+    }            
 #if wxPyUSE_GIL_STATE
     PyGILState_Release(blocked);
 #else