Adding qInstallMsgHandler() method support.
Reviewer: Marcelo Lira <marcelo.lira@openbossa.org>
Hugo Parente Lima <hugo.lima@openbossa.org>
This commit is contained in:
parent
928e0b2795
commit
54b69c3595
3 changed files with 86 additions and 0 deletions
|
|
@ -718,6 +718,38 @@
|
||||||
#include <pyside.h>
|
#include <pyside.h>
|
||||||
</inject-code>
|
</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"/>
|
<value-type name="QElapsedTimer" since="4.7"/>
|
||||||
|
|
||||||
<object-type name="QAbstractTableModel" polymorphic-id-expression="qobject_cast<QAbstractTableModel*>(%1)">
|
<object-type name="QAbstractTableModel" polymorphic-id-expression="qobject_cast<QAbstractTableModel*>(%1)">
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ PYSIDE_TEST(qfileinfo_test.py)
|
||||||
PYSIDE_TEST(qfile_test.py)
|
PYSIDE_TEST(qfile_test.py)
|
||||||
PYSIDE_TEST(qflags_test.py)
|
PYSIDE_TEST(qflags_test.py)
|
||||||
PYSIDE_TEST(qhandle_test.py)
|
PYSIDE_TEST(qhandle_test.py)
|
||||||
|
PYSIDE_TEST(qinstallmsghandler_test.py)
|
||||||
PYSIDE_TEST(qlinef_test.py)
|
PYSIDE_TEST(qlinef_test.py)
|
||||||
PYSIDE_TEST(qlocale_test.py)
|
PYSIDE_TEST(qlocale_test.py)
|
||||||
PYSIDE_TEST(qmetaobject_test.py)
|
PYSIDE_TEST(qmetaobject_test.py)
|
||||||
|
|
|
||||||
53
tests/QtCore/qinstallmsghandler_test.py
Normal file
53
tests/QtCore/qinstallmsghandler_test.py
Normal file
|
|
@ -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()
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue