Skip to content

Remove dependencies on std:: library classes. #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/PythonQt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#include "PythonQtStdDecorators.h"
#include "PythonQtQFileImporter.h"
#include <pydebug.h>
#include <vector>


PythonQt* PythonQt::_self = NULL;
int PythonQt::_uniqueModuleCount = 0;
Expand Down Expand Up @@ -142,7 +142,7 @@ void PythonQt::init(int flags, const QByteArray& pythonQtModuleName)
Py_INCREF(obj);
PyModule_AddObject(pack2, names[i], obj);
} else {
std::cerr << "method not found " << names[i] << std::endl;
qWarning() << "method not found " << names[i];
}
}
}
Expand Down Expand Up @@ -180,39 +180,39 @@ PythonQt::PythonQt(int flags, const QByteArray& pythonQtModuleName)

// add our own python object types for qt object slots
if (PyType_Ready(&PythonQtSlotFunction_Type) < 0) {
std::cerr << "could not initialize PythonQtSlotFunction_Type" << ", in " << __FILE__ << ":" << __LINE__ << std::endl;
qWarning() << "could not initialize PythonQtSlotFunction_Type" << ", in " << __FILE__ << ":" << __LINE__;
}
Py_INCREF(&PythonQtSlotFunction_Type);

if (PyType_Ready(&PythonQtSignalFunction_Type) < 0) {
std::cerr << "could not initialize PythonQtSignalFunction_Type" << ", in " << __FILE__ << ":" << __LINE__ << std::endl;
qWarning() << "could not initialize PythonQtSignalFunction_Type" << ", in " << __FILE__ << ":" << __LINE__;
}
Py_INCREF(&PythonQtSignalFunction_Type);

// according to Python docs, set the type late here, since it can not safely be stored in the struct when declaring it
PythonQtClassWrapper_Type.tp_base = &PyType_Type;
// add our own python object types for classes
if (PyType_Ready(&PythonQtClassWrapper_Type) < 0) {
std::cerr << "could not initialize PythonQtClassWrapper_Type" << ", in " << __FILE__ << ":" << __LINE__ << std::endl;
qWarning() << "could not initialize PythonQtClassWrapper_Type" << ", in " << __FILE__ << ":" << __LINE__;
}
Py_INCREF(&PythonQtClassWrapper_Type);

// add our own python object types for CPP instances
if (PyType_Ready(&PythonQtInstanceWrapper_Type) < 0) {
PythonQt::handleError();
std::cerr << "could not initialize PythonQtInstanceWrapper_Type" << ", in " << __FILE__ << ":" << __LINE__ << std::endl;
qWarning() << "could not initialize PythonQtInstanceWrapper_Type" << ", in " << __FILE__ << ":" << __LINE__;
}
Py_INCREF(&PythonQtInstanceWrapper_Type);

// add our own python object types for redirection of stdout
if (PyType_Ready(&PythonQtStdOutRedirectType) < 0) {
std::cerr << "could not initialize PythonQtStdOutRedirectType" << ", in " << __FILE__ << ":" << __LINE__ << std::endl;
qWarning() << "could not initialize PythonQtStdOutRedirectType" << ", in " << __FILE__ << ":" << __LINE__;
}
Py_INCREF(&PythonQtStdOutRedirectType);

// add our own python object types for redirection of stdin
if (PyType_Ready(&PythonQtStdInRedirectType) < 0) {
std::cerr << "could not initialize PythonQtStdInRedirectType" << ", in " << __FILE__ << ":" << __LINE__ << std::endl;
qWarning() << "could not initialize PythonQtStdInRedirectType" << ", in " << __FILE__ << ":" << __LINE__;
}
Py_INCREF(&PythonQtStdInRedirectType);

Expand Down Expand Up @@ -246,7 +246,7 @@ void PythonQt::setRedirectStdInCallback(PythonQtInputChangedCB* callback, void *
{
if (!callback)
{
std::cerr << "PythonQt::setRedirectStdInCallback - callback parameter is NULL !" << std::endl;
qWarning() << "PythonQt::setRedirectStdInCallback - callback parameter is NULL !";
return;
}

Expand Down Expand Up @@ -1011,7 +1011,7 @@ QStringList PythonQt::introspectObject(PyObject* object, ObjectType type)
}
break;
default:
std::cerr << "PythonQt: introspection: unknown case" << ", in " << __FILE__ << ":" << __LINE__ << std::endl;
qWarning() << "PythonQt: introspection: unknown case" << ", in " << __FILE__ << ":" << __LINE__;
}
}
Py_DECREF(value);
Expand Down Expand Up @@ -1355,12 +1355,12 @@ int custom_system_exit_exception_handler()

PyErr_Fetch(&exception, &value, &tb);
#ifdef PY3K
std::cout << std::endl;
//std::cout;
#else
if (Py_FlushLine())
PyErr_Clear();
#endif
fflush(stdout);
//fflush(stdout);
if (value == NULL || value == Py_None)
goto done;
if (PyExceptionInstance_Check(value)) {
Expand Down Expand Up @@ -1483,7 +1483,7 @@ void PythonQt::setModuleImportPath(PyObject* module, const QStringList& paths)
void PythonQt::stdOutRedirectCB(const QString& str)
{
if (!PythonQt::self()) {
std::cout << str.toLatin1().data() << std::endl;
qDebug() << str.toLatin1().data();
return;
}
Q_EMIT PythonQt::self()->pythonStdOut(str);
Expand All @@ -1492,7 +1492,7 @@ void PythonQt::stdOutRedirectCB(const QString& str)
void PythonQt::stdErrRedirectCB(const QString& str)
{
if (!PythonQt::self()) {
std::cerr << str.toLatin1().data() << std::endl;
qWarning() << str.toLatin1().data();
return;
}
Q_EMIT PythonQt::self()->pythonStdErr(str);
Expand Down
1 change: 0 additions & 1 deletion src/PythonQt.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
#include <QByteArray>
#include <QStringList>
#include <QtDebug>
#include <iostream>


class PythonQtClassInfo;
Expand Down
14 changes: 7 additions & 7 deletions src/PythonQtClassInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ bool PythonQtClassInfo::lookForPropertyAndCache(const char* memberName)
if (nameMapped) {
_cachedMembers.insert(memberName, newInfo);
}
#ifdef PYTHONQT_DEBUG
std::cout << "caching property " << memberName << " on " << _meta->className() << std::endl;
#endif
#ifdef PYTHONQT_DEBUG
qDebug() << "caching property " << memberName << " on " << _meta->className();
#endif
found = true;
}
return found;
Expand Down Expand Up @@ -281,13 +281,13 @@ bool PythonQtClassInfo::lookForEnumAndCache(const QMetaObject* meta, const char*
enumValuePtr.setNewRef(PythonQtPrivate::createEnumValueInstance(enumType, e.value(j)));
PythonQtMemberInfo newInfo(enumValuePtr);
_cachedMembers.insert(memberName, newInfo);
#ifdef PYTHONQT_DEBUG
std::cout << "caching enum " << memberName << " on " << meta->className() << std::endl;
#endif
#ifdef PYTHONQT_DEBUG
qDebug() << "caching enum " << memberName << " on " << meta->className();
#endif
found = true;
break;
} else {
std::cout << "enum " << e.name() << " not found on " << className() << std::endl;
qWarning() << "enum " << e.name() << " not found on " << className();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/PythonQtConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ PyObject* PythonQtConv::ConvertQtValueToPythonInternal(int type, const void* dat
wrap->_useQMetaTypeDestroy = true;
return (PyObject*)wrap;
}
std::cerr << "Unknown type that can not be converted to Python: " << type << ", in " << __FILE__ << ":" << __LINE__ << std::endl;
qWarning() << "Unknown type that can not be converted to Python: " << type << ", in " << __FILE__ << ":" << __LINE__;
}
}
Py_INCREF(Py_None);
Expand Down
9 changes: 4 additions & 5 deletions src/PythonQtConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

#include <QWidget>
#include <QList>
#include <vector>
#include <QVector>

typedef PyObject* PythonQtConvertMetaTypeToPythonCB(const void* inObject, int metaTypeId);
typedef bool PythonQtConvertPythonToMetaTypeCB(PyObject* inObject, void* outObject, int metaTypeId, bool strict);
Expand All @@ -62,8 +62,7 @@ PythonQtConv::registerMetaTypeToPythonConverter(typeId, PythonQtConvertListOfVal

#define PythonQtRegisterToolClassesTemplateConverter(innertype) \
PythonQtRegisterListTemplateConverter(QList, innertype); \
PythonQtRegisterListTemplateConverter(QVector, innertype); \
PythonQtRegisterListTemplateConverter(std::vector, innertype);
PythonQtRegisterListTemplateConverter(QVector, innertype);
// TODO: add QHash etc. here!

//! a static class that offers methods for type conversion
Expand Down Expand Up @@ -168,7 +167,7 @@ PyObject* PythonQtConvertListOfValueTypeToPythonList(const void* /*QList<T>* */
ListType* list = (ListType*)inList;
static const int innerType = PythonQtConv::getInnerTemplateMetaType(QByteArray(QMetaType::typeName(metaTypeId)));
if (innerType == QVariant::Invalid) {
std::cerr << "PythonQtConvertListOfValueTypeToPythonList: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl;
qWarning() << "PythonQtConvertListOfValueTypeToPythonList: unknown inner type " << QMetaType::typeName(metaTypeId);
}
PyObject* result = PyTuple_New(list->size());
int i = 0;
Expand All @@ -185,7 +184,7 @@ bool PythonQtConvertPythonListToListOfValueType(PyObject* obj, void* /*QList<T>*
ListType* list = (ListType*)outList;
static const int innerType = PythonQtConv::getInnerTemplateMetaType(QByteArray(QMetaType::typeName(metaTypeId)));
if (innerType == QVariant::Invalid) {
std::cerr << "PythonQtConvertPythonListToListOfValueType: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl;
qWarning() << "PythonQtConvertPythonListToListOfValueType: unknown inner type " << QMetaType::typeName(metaTypeId);
}
bool result = false;
if (PySequence_Check(obj)) {
Expand Down
4 changes: 2 additions & 2 deletions src/PythonQtInstanceWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ static PyObject *PythonQtInstanceWrapper_getattro(PyObject *obj,PyObject *name)
PyDict_SetItemString(dict, name.toLatin1().data(), o);
Py_DECREF(o);
} else {
std::cerr << "PythonQtInstanceWrapper: something is wrong, could not get attribute " << name.toLatin1().data();
qWarning() << "PythonQtInstanceWrapper: something is wrong, could not get attribute " << name.toLatin1().data();
}
}

Expand All @@ -370,7 +370,7 @@ static PyObject *PythonQtInstanceWrapper_getattro(PyObject *obj,PyObject *name)
PyDict_SetItemString(dict, name.data(), o);
Py_DECREF(o);
} else {
std::cerr << "PythonQtInstanceWrapper: dynamic property could not be read " << name.data();
qWarning() << "PythonQtInstanceWrapper: dynamic property could not be read " << name.data();
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/PythonQtMethodInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@

#include "PythonQtMethodInfo.h"
#include "PythonQtClassInfo.h"
#include <iostream>

#ifdef PYTHONQT_DEBUG
#include <QtDebug>
#endif

QHash<QByteArray, PythonQtMethodInfo*> PythonQtMethodInfo::_cachedSignatures;
QHash<QByteArray, QByteArray> PythonQtMethodInfo::_parameterNameAliases;
Expand All @@ -56,7 +59,7 @@ PythonQtMethodInfo::PythonQtMethodInfo(const QMetaMethod& meta, PythonQtClassInf
#endif
sig = sig.mid(sig.indexOf('('));
QByteArray fullSig = QByteArray(meta.typeName()) + " " + sig;
std::cout << "caching " << fullSig.data() << std::endl;
qDebug() << "caching " << fullSig.data();
#endif

ParameterInfo type;
Expand Down
5 changes: 0 additions & 5 deletions src/PythonQtSignal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@
#include "PythonQtConversion.h"
#include "PythonQtSlot.h"

#include <iostream>

#include <exception>
#include <stdexcept>

#include <QByteArray>

//-----------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/PythonQtSignalReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ PythonQtSignalReceiver::PythonQtSignalReceiver(QObject* obj):PythonQtSignalRecei
_destroyedSignal1Id = QObject::staticMetaObject.indexOfSignal("destroyed()");
_destroyedSignal2Id = QObject::staticMetaObject.indexOfSignal("destroyed(QObject*)");
if (_destroyedSignal1Id == -1 || _destroyedSignal2Id == -1) {
std::cerr << "PythonQt: could not find destroyed signal index, should never happen!" << std::endl;
qWarning() << "PythonQt: could not find destroyed signal index, should never happen!";
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/PythonQtSlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
#include "PythonQtClassInfo.h"
#include "PythonQtMisc.h"
#include "PythonQtConversion.h"
#include <iostream>

#include <exception>
#include <stdexcept>
Expand Down Expand Up @@ -301,7 +300,7 @@ PyObject *PythonQtSlotFunction_CallImpl(PythonQtClassInfo* classInfo, QObject* o
int argc = args?PyTuple_Size(args):0;

#ifdef PYTHONQT_DEBUG
std::cout << "called " << info->metaMethod()->typeName() << " " << info->metaMethod()->signature() << std::endl;
qDebug() << "called " << info->metaMethod()->typeName() << " " << info->metaMethod()->signature();
#endif

PyObject* r = NULL;
Expand Down
8 changes: 6 additions & 2 deletions src/gui/PythonQtScriptingConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ void PythonQtScriptingConsole::stdOut(const QString& s)
int idx;
while ((idx = _stdOut.indexOf('\n'))!=-1) {
consoleMessage(_stdOut.left(idx));
std::cout << _stdOut.left(idx).toLatin1().data() << std::endl;
#ifdef PYTHONQT_DEBUG
qDebug() << _stdOut.left(idx).toLatin1().data();
#endif
_stdOut = _stdOut.mid(idx+1);
}
}
Expand All @@ -97,7 +99,9 @@ void PythonQtScriptingConsole::stdErr(const QString& s)
int idx;
while ((idx = _stdErr.indexOf('\n'))!=-1) {
consoleMessage(_stdErr.left(idx));
std::cerr << _stdErr.left(idx).toLatin1().data() << std::endl;
#ifdef PYTHONQT_DEBUG
qWarning() << _stdErr.left(idx).toLatin1().data();
#endif
_stdErr = _stdErr.mid(idx+1);
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/PythonQtTestMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "PythonQt.h"
#include "PythonQtTests.h"
#include <QApplication>
#include <iostream>

int main( int argc, char **argv )
{
Expand Down