]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/src/helpers.cpp
reSWIGged
[wxWidgets.git] / wxPython / src / helpers.cpp
index 572ada736f85386376d76235b5dba91392773189..9c983e008bea51e44f7f97a1b29e0913336315f8 100644 (file)
@@ -191,21 +191,23 @@ void wxPyApp::ExitMainLoop() {
 
 
 #ifdef __WXDEBUG__
-void wxPyApp::OnAssert(const wxChar *file,
-                     int line,
-                     const wxChar *cond,
-                     const wxChar *msg) {
-
+void wxPyApp::OnAssertFailure(const wxChar *file,
+                              int line,
+                              const wxChar *func,
+                              const wxChar *cond,
+                              const wxChar *msg)
+{
     // if we're not fully initialized then just log the error
     if (! m_startupComplete) {
         wxString buf;
         buf.Alloc(4096);
         buf.Printf(wxT("%s(%d): assert \"%s\" failed"),
                    file, line, cond);
-        if (msg != NULL) {
-            buf += wxT(": ");
-            buf += msg;
-        }
+        if ( func && *func )
+            buf << wxT(" in ") << func << wxT("()");
+        if (msg != NULL) 
+            buf << wxT(": ") << msg;
+        
         wxLogDebug(buf);
         return;
     }
@@ -239,11 +241,12 @@ void wxPyApp::OnAssert(const wxChar *file,
         if (m_assertMode & wxPYAPP_ASSERT_EXCEPTION) {
             wxString buf;
             buf.Alloc(4096);
-            buf.Printf(wxT("C++ assertion \"%s\" failed in %s(%d)"), cond, file, line);
-            if (msg != NULL) {
-                buf += wxT(": ");
-                buf += msg;
-            }
+            buf.Printf(wxT("C++ assertion \"%s\" failed at %s(%d)"), cond, file, line);
+            if ( func && *func )
+                buf << wxT(" in ") << func << wxT("()");
+            if (msg != NULL) 
+                buf << wxT(": ") << msg;
+            
 
             // set the exception
             wxPyBlock_t blocked = wxPyBeginBlockThreads();
@@ -264,16 +267,16 @@ void wxPyApp::OnAssert(const wxChar *file,
             buf.Alloc(4096);
             buf.Printf(wxT("%s(%d): assert \"%s\" failed"),
                        file, line, cond);
-            if (msg != NULL) {
-                buf += wxT(": ");
-                buf += msg;
-            }
+            if ( func && *func )
+                buf << wxT(" in ") << func << wxT("()");
+            if (msg != NULL) 
+                buf << wxT(": ") << msg;
             wxLogDebug(buf);
         }
 
         // do the normal wx assert dialog?
         if (m_assertMode & wxPYAPP_ASSERT_DIALOG)
-            wxApp::OnAssert(file, line, cond, msg);
+            wxApp::OnAssertFailure(file, line, func, cond, msg);
     }
 }
 #endif
@@ -1875,7 +1878,7 @@ wxString* wxString_in_helper(PyObject* source) {
         str = PyObject_Str(source);
         if (PyErr_Occurred()) return NULL;
     }
-    char* tmpPtr; int tmpSize;
+    char* tmpPtr; Py_ssize_t tmpSize;
     PyString_AsStringAndSize(str, &tmpPtr, &tmpSize);
     target = new wxString(tmpPtr, tmpSize);
 
@@ -1918,7 +1921,7 @@ wxString Py2wxString(PyObject* source)
         str = PyObject_Str(source);
         if (PyErr_Occurred()) return wxEmptyString;    // TODO:  should we PyErr_Clear?
     }
-    char* tmpPtr; int tmpSize;
+    char* tmpPtr; Py_ssize_t tmpSize;
     PyString_AsStringAndSize(str, &tmpPtr, &tmpSize);
     target = wxString(tmpPtr, tmpSize);
 
@@ -2507,7 +2510,7 @@ bool wxColour_helper(PyObject* source, wxColour** obj) {
             return true;
         }
     }
-    // last chance: 3-tuple of integers is expected
+    // last chance: 3-tuple or 4-tuple of integers is expected
     else if (PySequence_Check(source) && PyObject_Length(source) == 3) {
         PyObject* o1 = PySequence_GetItem(source, 0);
         PyObject* o2 = PySequence_GetItem(source, 1);
@@ -2524,10 +2527,29 @@ bool wxColour_helper(PyObject* source, wxColour** obj) {
         Py_DECREF(o3);
         return true;
     }
+    else if (PySequence_Check(source) && PyObject_Length(source) == 4) {
+        PyObject* o1 = PySequence_GetItem(source, 0);
+        PyObject* o2 = PySequence_GetItem(source, 1);
+        PyObject* o3 = PySequence_GetItem(source, 2);
+        PyObject* o4 = PySequence_GetItem(source, 3);
+        if (!PyNumber_Check(o1) || !PyNumber_Check(o2) || !PyNumber_Check(o3) || !PyNumber_Check(o4)) {
+            Py_DECREF(o1);
+            Py_DECREF(o2);
+            Py_DECREF(o3);
+            Py_DECREF(o4);
+            goto error;
+        }
+        **obj = wxColour(PyInt_AsLong(o1), PyInt_AsLong(o2), PyInt_AsLong(o3), PyInt_AsLong(o4));
+        Py_DECREF(o1);
+        Py_DECREF(o2);
+        Py_DECREF(o3);
+        Py_DECREF(o4);
+        return true;
+    }
 
  error:
     PyErr_SetString(PyExc_TypeError,
-                    "Expected a wxColour object or a string containing a colour name or '#RRGGBB'.");
+                    "Expected a wxColour object, a string containing a colour name or '#RRGGBB', or a 3- or 4-tuple of integers.");
     return false;
 }
 
@@ -2750,6 +2772,62 @@ int wxPyImageHandler::GetImageCount( wxInputStream& stream ) {
 }
 
 
+//----------------------------------------------------------------------
+// Function to test if the Display (or whatever is the platform equivallent)
+// can be connected to.  This is accessable from wxPython as a staticmethod of
+// wx.App called DisplayAvailable().
+
+
+bool wxPyTestDisplayAvailable()
+{
+#ifdef __WXGTK__
+    Display* display;
+    display = XOpenDisplay(NULL);
+    if (display == NULL)
+        return false;
+    XCloseDisplay(display);
+    return true;
+#endif
+
+#ifdef __WXMAC__
+    // This is adapted from Python's Mac/Modules/MacOS.c in the
+    // MacOS_WMAvailable function.
+    bool rv;
+    ProcessSerialNumber psn;
+               
+    /*
+    ** This is a fairly innocuous call to make if we don't have a window
+    ** manager, or if we have no permission to talk to it. It will print
+    ** a message on stderr, but at least it won't abort the process.
+    ** It appears the function caches the result itself, and it's cheap, so
+    ** no need for us to cache.
+    */
+#ifdef kCGNullDirectDisplay
+    /* On 10.1 CGMainDisplayID() isn't available, and
+    ** kCGNullDirectDisplay isn't defined.
+    */
+    if (CGMainDisplayID() == 0) {
+        rv = false;
+    } else 
+#endif
+    {
+        // Also foreground the application on the first call as a side-effect.
+        if (GetCurrentProcess(&psn) < 0 || SetFrontProcess(&psn) < 0) {
+            rv = false;
+        } else {
+            rv = true;
+        }
+    }
+    return rv;
+#endif
+
+#ifdef __WXMSW__
+    // TODO...
+    return true;
+#endif
+}
+
+
 //----------------------------------------------------------------------
 //----------------------------------------------------------------------