]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/src/helpers.cpp
reSWIGged
[wxWidgets.git] / wxPython / src / helpers.cpp
index 9b7e3efb6d2ef738a5fc20f9e718f5dc58cb70ab..a1a20b66fa7113e7549e295c15205ce3c4559cec 100644 (file)
@@ -97,6 +97,7 @@ PyObject* wxPyPtrTypeMap = NULL;
 // This gets run when the DLL is loaded.  We just need to save a handle.
 //----------------------------------------------------------------------
 
 // This gets run when the DLL is loaded.  We just need to save a handle.
 //----------------------------------------------------------------------
 
+extern "C"
 BOOL WINAPI DllMain(
     HINSTANCE   hinstDLL,    // handle to DLL module
     DWORD       fdwReason,   // reason for calling function
 BOOL WINAPI DllMain(
     HINSTANCE   hinstDLL,    // handle to DLL module
     DWORD       fdwReason,   // reason for calling function
@@ -125,6 +126,8 @@ wxPyApp::wxPyApp() {
 
 
 wxPyApp::~wxPyApp() {
 
 
 wxPyApp::~wxPyApp() {
+    wxPythonApp = NULL;
+    wxApp::SetInstance(NULL);
 }
 
 
 }
 
 
@@ -400,14 +403,18 @@ void wxPyApp::_BootstrapApp()
         int    argc = 0;
         char** argv = NULL;
         blocked = wxPyBeginBlockThreads();
         int    argc = 0;
         char** argv = NULL;
         blocked = wxPyBeginBlockThreads();
+        
         PyObject* sysargv = PySys_GetObject("argv");
         PyObject* sysargv = PySys_GetObject("argv");
-        if (sysargv != NULL) {
-            argc = PyList_Size(sysargv);
+        PyObject* executable = PySys_GetObject("executable");
+        
+        if (sysargv != NULL && executable != NULL) {
+            argc = PyList_Size(sysargv) + 1;
             argv = new char*[argc+1];
             argv = new char*[argc+1];
+            argv[0] = strdup(PyString_AsString(executable));
             int x;
             int x;
-            for(x=0; x<argc; x++) {
-                PyObject *pyArg = PyList_GetItem(sysargv, x);
-                argv[x] = PyString_AsString(pyArg);
+            for(x=1; x<argc; x++) {
+                PyObject *pyArg = PyList_GetItem(sysargv, x-1);
+                argv[x] = strdup(PyString_AsString(pyArg));
             }
             argv[argc] = NULL;
         }
             }
             argv[argc] = NULL;
         }
@@ -415,7 +422,7 @@ void wxPyApp::_BootstrapApp()
 
         // Initialize wxWidgets
         result = wxEntryStart(argc, argv);
 
         // Initialize wxWidgets
         result = wxEntryStart(argc, argv);
-        delete [] argv;
+        // wxApp takes ownership of the argv array, don't delete it here
 
         blocked = wxPyBeginBlockThreads();
         if (! result)  {
 
         blocked = wxPyBeginBlockThreads();
         if (! result)  {
@@ -435,6 +442,8 @@ void wxPyApp::_BootstrapApp()
         setlocale(LC_NUMERIC, "C");
 #endif
 
         setlocale(LC_NUMERIC, "C");
 #endif
 
+//        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...
         wxPy_ReinitStockObjects(3);
         // The stock objects were all NULL when they were loaded into
         // SWIG generated proxies, so re-init those now...
         wxPy_ReinitStockObjects(3);
@@ -442,6 +451,11 @@ void wxPyApp::_BootstrapApp()
         wxPyEndBlockThreads(blocked);
         haveInitialized = true;
     }
         wxPyEndBlockThreads(blocked);
         haveInitialized = true;
     }
+    else {
+        this->argc = 0;
+        this->argv = NULL;
+    }
+    
 
     // It's now ok to generate exceptions for assertion errors.
     wxPythonApp->SetStartupComplete(true);
 
     // It's now ok to generate exceptions for assertion errors.
     wxPythonApp->SetStartupComplete(true);
@@ -544,8 +558,10 @@ void __wxPyPreStart(PyObject* moduleDict)
 #endif
 
 #ifdef WXP_WITH_THREAD
 #endif
 
 #ifdef WXP_WITH_THREAD
+#if wxPyUSE_GIL_STATE
+    PyEval_InitThreads();
+#else
     PyEval_InitThreads();
     PyEval_InitThreads();
-#if !wxPyUSE_GIL_STATE
     wxPyTStates = new wxPyThreadStateArray;
     wxPyTMutex = new wxMutex;
 
     wxPyTStates = new wxPyThreadStateArray;
     wxPyTMutex = new wxMutex;
 
@@ -985,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;
 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
 
     if (source) {
         // If it's derived from wxEvtHandler then there may
@@ -1001,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
         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
@@ -1018,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));
                 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();
             } else {
                 wxString msg(wxT("wxPython class not found for "));
                 msg += source->GetClassInfo()->GetClassName();
@@ -1033,25 +1064,8 @@ PyObject*  wxPyMake_wxObject(wxObject* source, bool setThisOwn, bool checkEvtHan
 
 
 PyObject*  wxPyMake_wxSizer(wxSizer* source, bool setThisOwn) {
 
 
 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);
 }
 
 
 }
 
 
@@ -1153,6 +1167,9 @@ void wxPyEndAllowThreads(PyThreadState* saved) {
 
 wxPyBlock_t wxPyBeginBlockThreads() {
 #ifdef WXP_WITH_THREAD
 
 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;
 #if wxPyUSE_GIL_STATE
     PyGILState_STATE state = PyGILState_Ensure();
     return state;
@@ -1171,13 +1188,16 @@ wxPyBlock_t wxPyBeginBlockThreads() {
     return blocked;
 #endif
 #else
     return blocked;
 #endif
 #else
-    return false;
+    return (wxPyBlock_t)0;
 #endif
 }
 
 
 void wxPyEndBlockThreads(wxPyBlock_t blocked) {
 #ifdef WXP_WITH_THREAD
 #endif
 }
 
 
 void wxPyEndBlockThreads(wxPyBlock_t blocked) {
 #ifdef WXP_WITH_THREAD
+    if (! Py_IsInitialized()) {
+        return;
+    }            
 #if wxPyUSE_GIL_STATE
     PyGILState_Release(blocked);
 #else
 #if wxPyUSE_GIL_STATE
     PyGILState_Release(blocked);
 #else