~ubuntu-branches/ubuntu/oneiric/pyside/oneiric

« back to all changes in this revision

Viewing changes to libpyside/pyside.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Didier Raboud
  • Date: 2010-10-19 22:52:14 UTC
  • mfrom: (1.1.4 upstream)
  • mto: (13.1.1 sid)
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20101019225214-0s9fbpz12x3962qa
Tags: upstream-0.4.2
ImportĀ upstreamĀ versionĀ 0.4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include "pyside.h"
25
25
#include "signalmanager.h"
26
26
#include "qproperty.h"
 
27
#include "qsignal.h"
 
28
#include <basewrapper.h>
 
29
#include <conversions.h>
 
30
#include <algorithm>
 
31
#include <cctype>
 
32
#include <QStack>
27
33
 
28
34
extern "C" void init_signal(PyObject* module);
29
35
extern "C" void init_slot(PyObject* module);
30
36
extern "C" void init_qproperty(PyObject* module);
31
37
 
 
38
static QStack<PySide::CleanupFunction> cleanupFunctionList;
 
39
 
32
40
namespace PySide
33
41
{
34
42
 
41
49
    SignalManager::instance();
42
50
}
43
51
 
 
52
bool fillQtProperties(PyObject* qObj, const QMetaObject* metaObj, PyObject* kwds, const char** blackList, unsigned int blackListSize)
 
53
{
 
54
 
 
55
    PyObject *key, *value;
 
56
    Py_ssize_t pos = 0;
 
57
 
 
58
    while (PyDict_Next(kwds, &pos, &key, &value)) {
 
59
        if (!blackListSize || !std::binary_search(blackList, blackList + blackListSize, std::string(PyString_AS_STRING(key)))) {
 
60
            QByteArray propName(PyString_AS_STRING(key));
 
61
            if (metaObj->indexOfProperty(propName) != -1) {
 
62
                propName[0] = std::toupper(propName[0]);
 
63
                propName.prepend("set");
 
64
 
 
65
                Shiboken::AutoDecRef propSetter(PyObject_GetAttrString(qObj, propName.constData()));
 
66
                if (!propSetter.isNull()) {
 
67
                    Shiboken::AutoDecRef args(PyTuple_Pack(1, value));
 
68
                    Shiboken::AutoDecRef retval(PyObject_CallObject(propSetter, args));
 
69
                } else {
 
70
                    PyObject* attr = PyObject_GenericGetAttr(qObj, key);
 
71
                    if (isQPropertyType(attr))
 
72
                        PySide::qproperty_set(attr, qObj, value);
 
73
                }
 
74
            } else {
 
75
                propName.append("()");
 
76
                if (metaObj->indexOfSignal(propName) != -1) {
 
77
                    propName.prepend('2');
 
78
                    PySide::signal_connect(qObj, propName, value);
 
79
                } else {
 
80
                    PyErr_Format(PyExc_AttributeError, "'%s' is not a Qt property or a signal", propName.constData());
 
81
                    return false;
 
82
                };
 
83
            }
 
84
        }
 
85
    }
 
86
    return true;
 
87
}
 
88
 
 
89
void registerCleanupFunction(CleanupFunction func)
 
90
{
 
91
    cleanupFunctionList.push(func);
 
92
}
 
93
 
 
94
void runCleanupFunctions()
 
95
{
 
96
    while (!cleanupFunctionList.isEmpty()) {
 
97
        CleanupFunction f = cleanupFunctionList.pop();
 
98
        f();
 
99
    }
 
100
}
 
101
 
44
102
} //namespace PySide
45
103