#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;
}
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();
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
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);
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);
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);
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;
}
}
+//----------------------------------------------------------------------
+// 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
+}
+
+
//----------------------------------------------------------------------
//----------------------------------------------------------------------