aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--PySide/QtCore/typesystem_core.xml32
-rw-r--r--tests/QtCore/CMakeLists.txt1
-rw-r--r--tests/QtCore/qinstallmsghandler_test.py53
3 files changed, 86 insertions, 0 deletions
diff --git a/PySide/QtCore/typesystem_core.xml b/PySide/QtCore/typesystem_core.xml
index 8b1bab61d..337697304 100644
--- a/PySide/QtCore/typesystem_core.xml
+++ b/PySide/QtCore/typesystem_core.xml
@@ -718,6 +718,38 @@
#include <pyside.h>
</inject-code>
+ <inject-code class="native" position="beginning">
+ // Define a global variable to handle qInstallMsgHandler callback
+ static PyObject* qtmsghandler = 0;
+
+ void
+ msghandlercallback(QtMsgType type, const char* msg)
+ {
+ Shiboken::AutoDecRef arglist(Shiboken::makeTuple(type, msg));
+ Shiboken::AutoDecRef ret(PyObject_CallObject(qtmsghandler, arglist));
+ }
+ </inject-code>
+ <add-function signature="qInstallMsgHandler(PyObject)" return-type="PyObject">
+ <inject-code class="target" position="beginning">
+ if (%PYARG_1 == Py_None) {
+ qInstallMsgHandler(0);
+ %PYARG_0 = qtmsghandler ? qtmsghandler : Py_None;
+ qtmsghandler = 0;
+ } else if (!PyCallable_Check(%PYARG_1)) {
+ PyErr_SetString(PyExc_TypeError, "parameter must be callable");
+ } else {
+ %PYARG_0 = qtmsghandler ? qtmsghandler : Py_None;
+ Py_INCREF(%PYARG_1);
+ qtmsghandler = %PYARG_1;
+ qInstallMsgHandler(msghandlercallback);
+ }
+
+ if (%PYARG_0 == Py_None)
+ Py_INCREF(%PYARG_0);
+
+ </inject-code>
+ </add-function>
+
<value-type name="QElapsedTimer" since="4.7"/>
<object-type name="QAbstractTableModel" polymorphic-id-expression="qobject_cast&lt;QAbstractTableModel*&gt;(%1)">
diff --git a/tests/QtCore/CMakeLists.txt b/tests/QtCore/CMakeLists.txt
index 35fa7b97d..b5f59d474 100644
--- a/tests/QtCore/CMakeLists.txt
+++ b/tests/QtCore/CMakeLists.txt
@@ -22,6 +22,7 @@ PYSIDE_TEST(qfileinfo_test.py)
PYSIDE_TEST(qfile_test.py)
PYSIDE_TEST(qflags_test.py)
PYSIDE_TEST(qhandle_test.py)
+PYSIDE_TEST(qinstallmsghandler_test.py)
PYSIDE_TEST(qlinef_test.py)
PYSIDE_TEST(qlocale_test.py)
PYSIDE_TEST(qmetaobject_test.py)
diff --git a/tests/QtCore/qinstallmsghandler_test.py b/tests/QtCore/qinstallmsghandler_test.py
new file mode 100644
index 000000000..d76c6ceec
--- /dev/null
+++ b/tests/QtCore/qinstallmsghandler_test.py
@@ -0,0 +1,53 @@
+
+'''Test cases for qInstallMsgHandler'''
+
+import unittest
+import sys
+
+from PySide.QtCore import *
+
+param = []
+
+def handler(msgt, msg):
+ global param
+ param = [msgt, msg]
+
+def handleruseless(msgt, msg):
+ pass
+
+class QInstallMsgHandlerTest(unittest.TestCase):
+
+ def tearDown(self):
+ # Ensure that next test will have a clear environment
+ qInstallMsgHandler(None)
+
+ def testNone(self):
+ ret = qInstallMsgHandler(None)
+ self.assertEqual(ret, None)
+
+ def testRet(self):
+ ret = qInstallMsgHandler(None)
+ self.assertEqual(ret, None)
+ refcount = sys.getrefcount(handleruseless)
+ retNone = qInstallMsgHandler(handleruseless)
+ self.assertEqual(sys.getrefcount(handleruseless), refcount + 1)
+ rethandler = qInstallMsgHandler(None)
+ self.assertEqual(rethandler, handleruseless)
+ del rethandler
+ self.assertEqual(sys.getrefcount(handleruseless), refcount)
+
+ def testHandler(self):
+ rethandler = qInstallMsgHandler(handler)
+ qDebug("Test Debug")
+ self.assertEqual(param[0], QtDebugMsg)
+ self.assertEqual(param[1], "Test Debug")
+ qWarning("Test Warning")
+ self.assertEqual(param[0], QtWarningMsg)
+ self.assertEqual(param[1], "Test Warning")
+ qCritical("Test Critical")
+ self.assertEqual(param[0], QtCriticalMsg)
+ self.assertEqual(param[1], "Test Critical")
+
+if __name__ == '__main__':
+ unittest.main()
+