]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/src/helpers.cpp
reSWIGed
[wxWidgets.git] / wxPython / src / helpers.cpp
index edb5a9179120fb161ad01dbdbba9c04fbf445327..e85e1fac536ef300a022637a085faab193cd469a 100644 (file)
@@ -378,58 +378,67 @@ void wxPyApp::SetMacHelpMenuTitleName(const wxString& val) {
 // that should be present in the derived (Python) class.
 void wxPyApp::_BootstrapApp()
 {
-    bool        result;
+    static      bool haveInitialized = false;
+    bool        result, blocked;
     PyObject*   retval = NULL;
     PyObject*   pyint  = NULL;
 
-
-    // Get any command-line args passed to this program from the sys module
-    int    argc = 0;
-    char** argv = NULL;
-    bool blocked = wxPyBeginBlockThreads();
-    PyObject* sysargv = PySys_GetObject("argv");
-    if (sysargv != NULL) {
-        argc = PyList_Size(sysargv);
-        argv = new char*[argc+1];
-        int x;
-        for(x=0; x<argc; x++) {
-            PyObject *pyArg = PyList_GetItem(sysargv, x);
-            argv[x] = PyString_AsString(pyArg);
+    
+    // Only initialize wxWidgets once
+    if (! haveInitialized) {
+        
+        // Get any command-line args passed to this program from the sys module
+        int    argc = 0;
+        char** argv = NULL;
+        blocked = wxPyBeginBlockThreads();
+        PyObject* sysargv = PySys_GetObject("argv");
+        if (sysargv != NULL) {
+            argc = PyList_Size(sysargv);
+            argv = new char*[argc+1];
+            int x;
+            for(x=0; x<argc; x++) {
+                PyObject *pyArg = PyList_GetItem(sysargv, x);
+                argv[x] = PyString_AsString(pyArg);
+            }
+            argv[argc] = NULL;
         }
-        argv[argc] = NULL;
-    }
-    wxPyEndBlockThreads(blocked);
+        wxPyEndBlockThreads(blocked);
 
-    // Initialize wxWidgets
-    result = wxEntryStart(argc, argv);
-    delete [] argv;
+        // Initialize wxWidgets
+        result = wxEntryStart(argc, argv);
+        delete [] argv;
 
-    blocked = wxPyBeginBlockThreads();
-    if (! result)  {
-        PyErr_SetString(PyExc_SystemError,
-                        "wxEntryStart failed, unable to initialize wxWidgets!"
+        blocked = wxPyBeginBlockThreads();
+        if (! result)  {
+            PyErr_SetString(PyExc_SystemError,
+                            "wxEntryStart failed, unable to initialize wxWidgets!"
 #ifdef __WXGTK__
-                        "  (Is DISPLAY set properly?)"
+                            "  (Is DISPLAY set properly?)"
 #endif
-            );
-        goto error;
-    }
+                );
+            goto error;
+        }
 
-    // On wxGTK the locale will be changed to match the system settings, but
-    // Python needs to have LC_NUMERIC set to "C" in order for the floating
-    // point conversions and such to work right.
+        // On wxGTK the locale will be changed to match the system settings, but
+        // Python needs to have LC_NUMERIC set to "C" in order for the floating
+        // point conversions and such to work right.
 #ifdef __WXGTK__
-    setlocale(LC_NUMERIC, "C");
+        setlocale(LC_NUMERIC, "C");
 #endif
     
-    // 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);
 
+        wxPyEndBlockThreads(blocked);
+        haveInitialized = true;
+    }
+    
     // It's now ok to generate exceptions for assertion errors.
     wxPythonApp->SetStartupComplete(True);
 
     // Call the Python wxApp's OnInit function
+    blocked = wxPyBeginBlockThreads();
     if (wxPyCBH_findCallback(m_myInst, "OnInit")) {
 
         PyObject* method = m_myInst.GetLastFound();
@@ -519,7 +528,10 @@ void __wxPyPreStart(PyObject* moduleDict)
 {
 
 #ifdef __WXMSW__
-//    wxCrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);
+//     wxCrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF
+//                     | _CRTDBG_CHECK_ALWAYS_DF
+//                     | _CRTDBG_DELAY_FREE_MEM_DF                             
+//         );
 #endif
 
 #ifdef WXP_WITH_THREAD
@@ -825,7 +837,6 @@ void wxPy_ReinitStockObjects(int pass)
     REINITOBJ(wxTheColourDatabase, wxColourDatabase);
 
 
-    REINITOBJ(wxTheClipboard, wxClipboard);
     REINITOBJ2(wxDefaultValidator, wxValidator);
     REINITOBJ2(wxNullImage, wxImage);
     REINITOBJ2(wxNullAcceleratorTable, wxAcceleratorTable);
@@ -954,7 +965,7 @@ void wxPyPtrTypeMap_Add(const char* commonName, const char* ptrName) {
 
 
 
-PyObject*  wxPyMake_wxObject(wxObject* source, bool checkEvtHandler) {
+PyObject*  wxPyMake_wxObject(wxObject* source, bool setThisOwn, bool checkEvtHandler) {
     PyObject* target = NULL;
     bool      isEvtHandler = False;
 
@@ -987,7 +998,7 @@ PyObject*  wxPyMake_wxObject(wxObject* source, bool checkEvtHandler) {
                 exists = wxPyCheckSwigType(name);
             }
             if (info) {
-                target = wxPyConstructObject((void*)source, name, False);
+                target = wxPyConstructObject((void*)source, name, setThisOwn);
                 if (target && isEvtHandler)
                     ((wxEvtHandler*)source)->SetClientObject(new wxPyOORClientData(target));
             } else {
@@ -1004,7 +1015,7 @@ PyObject*  wxPyMake_wxObject(wxObject* source, bool checkEvtHandler) {
 }
 
 
-PyObject*  wxPyMake_wxSizer(wxSizer* source) {
+PyObject*  wxPyMake_wxSizer(wxSizer* source, bool setThisOwn) {
     PyObject* target = NULL;
 
     if (source && wxIsKindOf(source, wxSizer)) {
@@ -1019,7 +1030,7 @@ PyObject*  wxPyMake_wxSizer(wxSizer* source) {
         }
     }
     if (! target) {
-        target = wxPyMake_wxObject(source, False);
+        target = wxPyMake_wxObject(source, setThisOwn, False);
         if (target != Py_None)
             ((wxSizer*)source)->SetClientObject(new wxPyOORClientData(target));
     }
@@ -1324,7 +1335,7 @@ wxPyCBInputStream::wxPyCBInputStream(PyObject *r, PyObject *s, PyObject *t, bool
 
 
 wxPyCBInputStream::~wxPyCBInputStream() {
-    bool blocked;
+    bool blocked=false;
     if (m_block) blocked = wxPyBeginBlockThreads();
     Py_XDECREF(m_read);
     Py_XDECREF(m_seek);
@@ -1334,7 +1345,7 @@ wxPyCBInputStream::~wxPyCBInputStream() {
 
 
 wxPyCBInputStream* wxPyCBInputStream::create(PyObject *py, bool block) {
-    bool blocked;
+    bool blocked=false;
     if (block) blocked = wxPyBeginBlockThreads();
 
     PyObject* read = getMethod(py, "read");
@@ -1842,7 +1853,7 @@ PyObject* wxPy_ConvertList(wxListBase* listbase) {
     pyList = PyList_New(0);
     while (node) {
         wxObj = node->GetData();
-        pyObj = wxPyMake_wxObject(wxObj);
+        pyObj = wxPyMake_wxObject(wxObj,false);
         PyList_Append(pyList, pyObj);
         node = node->GetNext();
     }