summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRenato Filho <renato.filho@openbossa.org>2010-08-26 15:23:23 -0300
committerRenato Filho <renato.filho@openbossa.org>2010-08-26 16:21:41 -0300
commita2f3e249bc0543b522c7d0e516dd07326e3ea7de (patch)
treee9dc91414290d52138632821e0bcc2231cd8950b
parent268bf7735b787d2310e18b3aed262bd27b9d24c6 (diff)
downloadshiboken-a2f3e249bc0543b522c7d0e516dd07326e3ea7de.tar.gz
shiboken-a2f3e249bc0543b522c7d0e516dd07326e3ea7de.tar.xz
shiboken-a2f3e249bc0543b522c7d0e516dd07326e3ea7de.zip
Fixed slot singature parse function to keep compatibility with QSignal.
Fixes bug #319 Reviewer: Luciano Wolf <luciano.wolf@openbossa.org> Hugo Parente Lima <hugo.pl@gmail.com>
-rw-r--r--libpyside/qsignal.cpp11
-rw-r--r--libpyside/qslot.cpp20
-rw-r--r--tests/signals/CMakeLists.txt1
-rw-r--r--tests/signals/bug_319.py35
4 files changed, 46 insertions, 21 deletions
diff --git a/libpyside/qsignal.cpp b/libpyside/qsignal.cpp
index 6c542034..a4fda063 100644
--- a/libpyside/qsignal.cpp
+++ b/libpyside/qsignal.cpp
@@ -48,6 +48,8 @@ namespace PySide
extern "C"
{
+char* get_type_name(PyObject*);
+
typedef struct {
PyObject_HEAD
bool initialized;
@@ -68,7 +70,6 @@ static PyObject* signal_instance_get_item(PyObject*, PyObject*);
//aux
static char* signal_build_signature(const char*, const char*);
-static char* signal_get_type_name(PyObject*);
static void signal_append_signature(SignalData*, char*);
static void signal_instance_initialize(PyObject*, PyObject*, SignalData*, PyObject *, int);
static char* signal_parse_signature(PyObject*);
@@ -244,7 +245,7 @@ void signalUpdateSource(PyObject* source)
}
}
-char* signal_get_type_name(PyObject* type)
+char* get_type_name(PyObject* type)
{
if (PyType_Check(type)) {
char *typeName = NULL;
@@ -255,7 +256,7 @@ char* signal_get_type_name(PyObject* type)
} else {
// Translate python types to Qt names
PyTypeObject *objType = reinterpret_cast<PyTypeObject*>(type);
- if (objType == &PyString_Type)
+ if ((objType == &PyString_Type) || (objType == &PyUnicode_Type))
typeName = strdup("QString");
else if (objType == &PyInt_Type)
typeName = strdup("int");
@@ -284,11 +285,11 @@ char* signal_parse_signature(PyObject *args)
{
char *signature = 0;
if (args && (PyString_Check(args) || (!PySequence_Check(args) && (args != Py_None))))
- return signal_get_type_name(args);
+ return get_type_name(args);
for(Py_ssize_t i = 0, i_max = PySequence_Size(args); i < i_max; i++) {
Shiboken::AutoDecRef arg(PySequence_ITEM(args, i));
- char* typeName = signal_get_type_name(arg);
+ char* typeName = get_type_name(arg);
if (typeName) {
if (signature) {
signature = reinterpret_cast<char*>(realloc(signature, (strlen(signature) + 1 + strlen(typeName)) * sizeof(char*)));
diff --git a/libpyside/qslot.cpp b/libpyside/qslot.cpp
index e74838cf..c471cbb3 100644
--- a/libpyside/qslot.cpp
+++ b/libpyside/qslot.cpp
@@ -53,8 +53,8 @@ extern "C"
static int slot_init(PyObject*, PyObject*, PyObject*);
static PyObject* slot_call(PyObject*, PyObject*, PyObject*);
-//aux
-static char* slot_get_type_name(PyObject*);
+//external qsignal.cpp
+extern char* get_type_name(PyObject*);
// Class Definition -----------------------------------------------
@@ -120,18 +120,6 @@ void init_slot(PyObject *module)
} // extern "C"
-char* slot_get_type_name(PyObject *type)
-{
- if (PyType_Check(type)) {
- //tp_name return the full name
- Shiboken::AutoDecRef typeName(PyObject_GetAttrString(type, "__name__"));
- return strdup(PyString_AS_STRING(typeName.object()));
- } else if (PyString_Check(type)) {
- return strdup(PyString_AS_STRING(type));
- }
- return 0;
-}
-
int slot_init(PyObject *self, PyObject *args, PyObject *kw)
{
static PyObject *emptyTuple = 0;
@@ -148,7 +136,7 @@ int slot_init(PyObject *self, PyObject *args, PyObject *kw)
SlotData *data = reinterpret_cast<SlotData*>(self);
for(Py_ssize_t i = 0, i_max = PyTuple_Size(args); i < i_max; i++) {
PyObject *argType = PyTuple_GET_ITEM(args, i);
- char *typeName = slot_get_type_name(argType);
+ char *typeName = get_type_name(argType);
if (typeName) {
if (data->args) {
data->args = reinterpret_cast<char*>(realloc(data->args, (strlen(data->args) + 1 + strlen(typeName)) * sizeof(char*)));
@@ -165,7 +153,7 @@ int slot_init(PyObject *self, PyObject *args, PyObject *kw)
data->slotName = strdup(argName);
if (argResult)
- data->resultType = slot_get_type_name(argResult);
+ data->resultType = get_type_name(argResult);
else
data->resultType = strdup("void");
diff --git a/tests/signals/CMakeLists.txt b/tests/signals/CMakeLists.txt
index a69aa061..5849dc55 100644
--- a/tests/signals/CMakeLists.txt
+++ b/tests/signals/CMakeLists.txt
@@ -1,5 +1,6 @@
PYSIDE_TEST(args_dont_match_test.py)
PYSIDE_TEST(bug_311.py)
+PYSIDE_TEST(bug_319.py)
PYSIDE_TEST(decorators_test.py)
PYSIDE_TEST(invalid_callback_test.py)
PYSIDE_TEST(lambda_gui_test.py)
diff --git a/tests/signals/bug_319.py b/tests/signals/bug_319.py
new file mode 100644
index 00000000..692b1bff
--- /dev/null
+++ b/tests/signals/bug_319.py
@@ -0,0 +1,35 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import unittest
+from PySide import QtCore
+from helper import UsesQCoreApplication
+
+class Listener(QtCore.QObject):
+ def __init__(self):
+ QtCore.QObject.__init__(self, None)
+ self._phrase = []
+
+ @QtCore.Slot(tuple)
+ def listen(self, words):
+ for w in words:
+ self._phrase.append(w)
+
+class Communicate(QtCore.QObject):
+ # create a new signal on the fly and name it 'speak'
+ speak = QtCore.Signal(tuple)
+
+class SignaltoSignalTest(UsesQCoreApplication):
+ def testBug(self):
+ someone = Communicate()
+ someone2 = Listener()
+ # connect signal and slot
+ someone.speak.connect(someone2.listen)
+ # emit 'speak' signal
+ talk = ("one","two","three")
+ someone.speak.emit(talk)
+ self.assertEqual(someone2._phrase, list(talk))
+
+if __name__ == '__main__':
+ unittest.main()
+