Hi,

the two attached patches implement the methode qt.setErrorHandler().
With setErrorHandler() you can replace the existing error handler,
who prints the error to stdout, with your own one.

For example:

...
setErrorHandler(errorHandler)
...

def errorHandler(exceptClass, exceptInstance):
    """
    Rewrite standard error handler of PyQt.
    """
    if isinstance(exceptInstance, CoreBizException):
        exceptInstance.show()
 
        # Do not use origional error handler.
        return 0
    else:
        # Use original error handler.
        return 1


-- 
Stefan Prestele            Linux Information Systems AG
Praktikant                 Fon +49 (0)89 99 34 12-0       Stefan-George-Ring 24
[EMAIL PROTECTED]    Fax +49 (0)89 99 34 12-99      D-81929 München
Linux is our Business. __________________________________ www.Linux-AG.com ____

Linux-Trainings bundesweit - aktuelle Termine unter www.linux-ag.com/training
diff -ur sip-2.3-org/siplib/qtlib.cpp sip-2.3/siplib/qtlib.cpp
--- sip-2.3-org/siplib/qtlib.cpp	Fri Nov  3 20:38:30 2000
+++ sip-2.3/siplib/qtlib.cpp	Thu Apr 12 13:32:50 2001
@@ -40,6 +40,10 @@
 static int setSlot(sipSlot *,PyObject *,char *);
 static int sameSigSlotName(char *,char *);
 
+static int StandardErrorHandlerCheck(PyObject *);
+// standard Error Handler
+//static PyObject *setErrorHandler(PyObject *self, PyObject *args);
+
 
 // sipProxy constructor.
 
@@ -354,10 +358,51 @@
 
         Py_DECREF(sa);
 
+    extern PyObject *sipStandardErrorHandler;
+
+    // check whether there is a python standard error handler and if yes
+    // call it
+    if (sipStandardErrorHandler)
+    {
+        return StandardErrorHandlerCheck(sipStandardErrorHandler);
+    }
+
 	return -1;
 }
 
 
+// Call the standard error handler function and return 
+
+static int StandardErrorHandlerCheck(PyObject *sipStandardErrorHandler)
+{
+    PyObject *exc, *excval, *tb;
+    PyErr_Fetch(&exc, &excval, &tb);
+
+    PyObject *ret = PyObject_CallFunction(sipStandardErrorHandler, 
+                                          "OO", exc, excval);
+
+    if (!PyInt_Check(ret) || PyInt_AsLong(ret) == 1)
+    {
+	    //PyErr_Format(PyExc_NameError,"Invalid signal %s",&sig[1]);
+
+        // Error auf die gewohnte Weise ausgeben
+        Py_XDECREF(ret);
+        PyErr_Restore(exc, excval, tb);
+        return -1;
+    }
+
+    // error was handled in the standard erro handler function
+    Py_XDECREF(ret);
+    Py_XDECREF(exc);
+    Py_XDECREF(excval);
+    Py_XDECREF(tb);
+
+    PyErr_Clear();
+
+    return 0;
+}
+
+
 // Send a signal to the slots (Qt or Python) in a Python list.
 
 static int emitToSlotList(sipPySigRx *rxlist,PyObject *sigargs)
diff -ur PyQt-2.3-org/qt/qtcmodule.cpp PyQt-2.3/qt/qtcmodule.cpp
--- PyQt-2.3-org/qt/qtcmodule.cpp	Sun Feb  4 01:05:52 2001
+++ PyQt-2.3/qt/qtcmodule.cpp	Thu Apr 12 14:04:07 2001
@@ -29,6 +29,10 @@
 // dealings in this Software without prior written authorization from the
 // copyright holder.
 
+
+# include <iostream>
+using namespace std;
+
 #include "sipqtDeclqt.h"
 
 #include "sipqtQt.h"
@@ -244,6 +248,11 @@
 #include "sipqtQWMatrix.h"
 #include "sipqtQWorkspace.h"
 
+
+
+char sipName_qt_setErrorHandler[] = "setErrorHandler";
+PyObject *sipStandardErrorHandler = NULL;
+
 char sipName_qt_cascade[] = "cascade";
 char sipName_qt_windowActivated[] = "windowActivated";
 char sipName_qt_windowList[] = "windowList";
@@ -6478,6 +6487,43 @@
 	return NULL;
 }
 
+
+//***********************************************************************
+
+static PyObject* sipDo_setErrorHandler(PyObject *x, PyObject *sipArgs)
+{
+    PyObject *func;
+
+    //cout << "qtcmodule.cpp: sipDo_setErrorHandler()" << endl;
+
+    if (!PyArg_ParseTuple(sipArgs, "O", &func))
+    {
+        //cout << "qtcmodule.cpp: Falscher Prameter Typ - gibt NULL zurueck\n";
+        // at this point has to be set an Exception!
+        return NULL;
+    }
+
+    // check if parameter is None
+    if (func == Py_None)
+    {
+        //cout << "qtcmodule.cpp: StandardErrorFunktion geloescht\n";
+        sipStandardErrorHandler = NULL;
+        return Py_None;
+    }
+    
+    if (PyCallable_Check(func))
+    {
+        sipStandardErrorHandler = func;
+        return Py_None;
+    }
+
+    //cout << "qtcmodule.cpp: nicht rufbares objekt uebergeben\n";
+    // at this has to be set an Exception!
+    return NULL;
+}
+
+//***********************************************************************
+
 static PyObject *sipDo_qVersion(PyObject *,PyObject *sipArgs)
 {
 	int sipArgsParsed = 0;
@@ -7612,6 +7658,9 @@
 	// Add the global functions to the dictionary.
 
 	static PyMethodDef globfuncs[] = {
+
+		{sipName_qt_setErrorHandler, sipDo_setErrorHandler, METH_VARARGS, NULL},
+
 		{sipName_qt_qDrawArrow, sipDo_qDrawArrow, METH_VARARGS, NULL},
 		{sipName_qt_qDrawItem, sipDo_qDrawItem, METH_VARARGS, NULL},
 		{sipName_qt_qItemRect, sipDo_qItemRect, METH_VARARGS, NULL},

Reply via email to