]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/src/helpers.cpp
Corrections and additions to the wxODBC docs
[wxWidgets.git] / wxPython / src / helpers.cpp
index 32578bf5f6832591e77e785c8162a8b9cf01a2d9..b59f95f5fe6736cb431b99fa561ca8e865b1a935 100644 (file)
@@ -170,7 +170,7 @@ PyObject* __wxStart(PyObject* /* self */, PyObject* args)
     char** argv = new char*[argc+1];
     int x;
     for(x=0; x<argc; x++)
-        argv[x] = PyString_AsString(PyList_GetItem(sysargv, x));
+        argv[x] = copystring(PyString_AsString(PyList_GetItem(sysargv, x)));
     argv[argc] = NULL;
 
     wxPythonApp->argc = argc;
@@ -245,7 +245,17 @@ PyObject* __wxSetDictionary(PyObject* /* self */, PyObject* args)
 
 //---------------------------------------------------------------------------
 
-PyObject* wxPyConstructObject(void* ptr, const char* className) {
+PyObject* wxPyConstructObject(void* ptr,
+                                 const char* className,
+                                 int setThisOwn) {
+    PyObject* obj;
+    PyObject* arg;
+
+    if (!ptr) {
+        Py_INCREF(Py_None);
+        return Py_None;
+    }
+
     char    buff[64];               // should always be big enough...
     char    swigptr[64];
 
@@ -255,14 +265,24 @@ PyObject* wxPyConstructObject(void* ptr, const char* className) {
     sprintf(buff, "%sPtr", className);
     PyObject* classobj = PyDict_GetItemString(wxPython_dict, buff);
     if (! classobj) {
-        Py_INCREF(Py_None);
-        return Py_None;
-    }
-
-    PyObject* arg = Py_BuildValue("(s)", swigptr);
-    PyObject* obj = PyInstance_New(classobj, arg, NULL);
+        //Py_INCREF(Py_None);
+        //return Py_None;
+        char temp[128];
+        sprintf(temp,
+                "*** Unknown class name %s, tell Robin about it please ***",
+                buff);
+        obj = PyString_FromString(temp);
+        return obj;
+    }
+
+    arg = Py_BuildValue("(s)", swigptr);
+    obj = PyInstance_New(classobj, arg, NULL);
     Py_DECREF(arg);
 
+    if (setThisOwn) {
+        PyObject_SetAttrString(obj, "thisown", PyInt_FromLong(1));
+    }
+
     return obj;
 }
 
@@ -393,9 +413,9 @@ wxPyCallbackHelper::wxPyCallbackHelper(const wxPyCallbackHelper& other) {
 }
 
 
-void wxPyCallbackHelper::setSelf(PyObject* self, PyObject* _class, int incref) {
+void wxPyCallbackHelper::setSelf(PyObject* self, PyObject* klass, int incref) {
     m_self = self;
-    m_class = _class;
+    m_class = klass;
     m_incRef = incref;
     if (incref) {
         Py_INCREF(m_self);
@@ -456,7 +476,7 @@ PyObject* wxPyCallbackHelper::callCallbackObj(PyObject* argTuple) const {
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 // These classes can be derived from in Python and passed through the event
-// system without loosing anything.  They do this by keeping a reference to
+// system without losing anything.  They do this by keeping a reference to
 // themselves and some special case handling in wxPyCallback::EventThunker.
 
 
@@ -541,20 +561,26 @@ wxPyTimer::~wxPyTimer() {
 }
 
 void wxPyTimer::Notify() {
-    bool doSave = wxPyRestoreThread();
-
-    PyObject*   result;
-    PyObject*   args = Py_BuildValue("()");
+    if (!func || func == Py_None) {
+        wxTimer::Notify();
+    }
+    else {
+        bool doSave = wxPyRestoreThread();
+
+        PyObject*   result;
+        PyObject*   args = Py_BuildValue("()");
+
+        result = PyEval_CallObject(func, args);
+        Py_DECREF(args);
+        if (result) {
+            Py_DECREF(result);
+            PyErr_Clear();
+        } else {
+            PyErr_Print();
+        }
 
-    result = PyEval_CallObject(func, args);
-    Py_DECREF(args);
-    if (result) {
-        Py_DECREF(result);
-        PyErr_Clear();
-    } else {
-        PyErr_Print();
+        wxPySaveThread(doSave);
     }
-    wxPySaveThread(doSave);
 }