From f008adb5a77e094eaf6abf3fc0f36958e66896a5 Mon Sep 17 00:00:00 2001 From: tpearson Date: Sat, 25 Jun 2011 05:28:35 +0000 Subject: TQt4 port koffice This should enable compilation under both Qt3 and Qt4; fixes for any missed components will be forthcoming git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1238284 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- lib/kross/python/pythonscript.cpp | 94 +++++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 47 deletions(-) (limited to 'lib/kross/python/pythonscript.cpp') diff --git a/lib/kross/python/pythonscript.cpp b/lib/kross/python/pythonscript.cpp index 082b5440c..4bf37c749 100644 --- a/lib/kross/python/pythonscript.cpp +++ b/lib/kross/python/pythonscript.cpp @@ -51,12 +51,12 @@ namespace Kross { namespace Python { /** * A list of functionnames. */ - QStringList m_functions; + TQStringList m_functions; /** * A list of classnames. */ - QStringList m_classes; + TQStringList m_classes; }; }} @@ -88,18 +88,18 @@ void PythonScript::initialize() try { if(m_scriptcontainer->getCode().isNull()) - throw Kross::Api::Exception::Ptr( new Kross::Api::Exception(QString("Invalid scripting code for script '%1'").arg( m_scriptcontainer->getName() )) ); + throw Kross::Api::Exception::Ptr( new Kross::Api::Exception(TQString("Invalid scripting code for script '%1'").tqarg( m_scriptcontainer->getName() )) ); if(m_scriptcontainer->getName().isNull()) - throw Kross::Api::Exception::Ptr( new Kross::Api::Exception(QString("Name for the script is invalid!")) ); + throw Kross::Api::Exception::Ptr( new Kross::Api::Exception(TQString("Name for the script is invalid!")) ); PyObject* pymod = PyModule_New( (char*) m_scriptcontainer->getName().latin1() ); d->m_module = new Py::Module(pymod, true); if(! d->m_module) - throw Kross::Api::Exception::Ptr( new Kross::Api::Exception(QString("Failed to initialize local module context for script '%1'").arg( m_scriptcontainer->getName() )) ); + throw Kross::Api::Exception::Ptr( new Kross::Api::Exception(TQString("Failed to initialize local module context for script '%1'").tqarg( m_scriptcontainer->getName() )) ); #ifdef KROSS_PYTHON_SCRIPT_INIT_DEBUG - krossdebug( QString("PythonScript::initialize() module='%1' refcount='%2'").arg(d->m_module->as_string().c_str()).arg(d->m_module->reference_count()) ); + krossdebug( TQString("PythonScript::initialize() module='%1' refcount='%2'").tqarg(d->m_module->as_string().c_str()).tqarg(d->m_module->reference_count()) ); #endif // Set the "self" variable to point to the ScriptContainer @@ -108,11 +108,11 @@ void PythonScript::initialize() // python scripting code. Py::Dict moduledict = d->m_module->getDict(); moduledict["self"] = PythonExtension::toPyObject( m_scriptcontainer ); - //moduledict["parent"] = PythonExtension::toPyObject( m_manager ); + //moduledict["tqparent"] = PythonExtension::toPyObject( m_manager ); /* // Prepare the local context. - QString s = + TQString s = //"import sys\n" "if self.has(\"stdout\"):\n" " self.stdout = Redirect( self.get(\"stdout\") )\n" @@ -129,9 +129,9 @@ void PythonScript::initialize() // Compile the python script code. It will be later on request // executed. That way we cache the compiled code. PyObject* code = 0; - bool restricted = m_scriptcontainer->getOption("restricted", QVariant(false,0), true).toBool(); + bool restricted = m_scriptcontainer->getOption("restricted", TQVariant(false,0), true).toBool(); - krossdebug( QString("PythonScript::initialize() name=%1 restricted=%2").arg(m_scriptcontainer->getName()).arg(restricted) ); + krossdebug( TQString("PythonScript::initialize() name=%1 restricted=%2").tqarg(m_scriptcontainer->getName()).tqarg(restricted) ); if(restricted) { // Use the RestrictedPython module wrapped by the PythonSecurity class. @@ -159,8 +159,8 @@ void PythonScript::initialize() d->m_code = new Py::Object(code, true); } catch(Py::Exception& e) { - QString err = Py::value(e).as_string().c_str(); - Kross::Api::Exception::Ptr exception = toException( QString("Failed to compile python code: %1").arg(err) ); + TQString err = Py::value(e).as_string().c_str(); + Kross::Api::Exception::Ptr exception = toException( TQString("Failed to compile python code: %1").tqarg(err) ); e.clear(); // exception is handled. clear it now. throw exception; } @@ -170,7 +170,7 @@ void PythonScript::finalize() { #ifdef KROSS_PYTHON_SCRIPT_FINALIZE_DEBUG if(d->m_module) - krossdebug( QString("PythonScript::finalize() module='%1' refcount='%2'").arg(d->m_module->as_string().c_str()).arg(d->m_module->reference_count()) ); + krossdebug( TQString("PythonScript::finalize() module='%1' refcount='%2'").tqarg(d->m_module->as_string().c_str()).tqarg(d->m_module->reference_count()) ); #endif delete d->m_module; d->m_module = 0; @@ -179,10 +179,10 @@ void PythonScript::finalize() d->m_classes.clear(); } -Kross::Api::Exception::Ptr PythonScript::toException(const QString& error) +Kross::Api::Exception::Ptr PythonScript::toException(const TQString& error) { long lineno = -1; - QStringList errorlist; + TQStringList errorlist; PyObject *type, *value, *traceback; PyErr_Fetch(&type, &value, &traceback); @@ -203,9 +203,9 @@ Kross::Api::Exception::Ptr PythonScript::toException(const QString& error) errorlist.append( Py::Object(tblist[i]).as_string().c_str() ); } catch(Py::Exception& e) { - QString err = Py::value(e).as_string().c_str(); + TQString err = Py::value(e).as_string().c_str(); e.clear(); // exception is handled. clear it now. - krosswarning( QString("Kross::Python::PythonScript::toException() Failed to fetch a traceback: %1").arg(err) ); + krosswarning( TQString("Kross::Python::PythonScript::toException() Failed to fetch a traceback: %1").tqarg(err) ); } PyObject *next; @@ -226,7 +226,7 @@ Kross::Api::Exception::Ptr PythonScript::toException(const QString& error) //const char* filename = PyString_AsString(frame->f_code->co_filename); //const char* name = PyString_AsString(frame->f_code->co_name); - //errorlist.append( QString("%1#%2: \"%3\"").arg(filename).arg(lineno).arg(name) ); + //errorlist.append( TQString("%1#%2: \"%3\"").tqarg(filename).tqarg(lineno).tqarg(name) ); next = PyObject_GetAttrString(traceback, "tb_next"); Py_DECREF(traceback); @@ -254,13 +254,13 @@ Kross::Api::Exception::Ptr PythonScript::toException(const QString& error) return exception; } -const QStringList& PythonScript::getFunctionNames() +const TQStringList& PythonScript::getFunctionNames() { if(! d->m_module) initialize(); //TODO catch exception return d->m_functions; /* - QStringList list; + TQStringList list; Py::List l = d->m_module->getDict().keys(); int length = l.length(); for(Py::List::size_type i = 0; i < length; ++i) @@ -272,7 +272,7 @@ const QStringList& PythonScript::getFunctionNames() Kross::Api::Object::Ptr PythonScript::execute() { #ifdef KROSS_PYTHON_SCRIPT_EXEC_DEBUG - krossdebug( QString("PythonScript::execute()") ); + krossdebug( TQString("PythonScript::execute()") ); #endif try { @@ -285,7 +285,7 @@ Kross::Api::Object::Ptr PythonScript::execute() Py::Dict moduledict( d->m_module->getDict().ptr() ); // Initialize context before execution. - QString s = + TQString s = "import sys\n" //"if self.has(\"stdout\"):\n" //" sys.stdout = Redirect( self.get(\"stdout\") )\n" @@ -318,20 +318,20 @@ Kross::Api::Object::Ptr PythonScript::execute() Py::Object result(pyresult, true); #ifdef KROSS_PYTHON_SCRIPT_EXEC_DEBUG - krossdebug( QString("PythonScript::execute() result=%1").arg(result.as_string().c_str()) ); + krossdebug( TQString("PythonScript::execute() result=%1").tqarg(result.as_string().c_str()) ); #endif for(Py::Dict::iterator it = moduledict.begin(); it != moduledict.end(); ++it) { Py::Dict::value_type vt(*it); if(PyClass_Check( vt.second.ptr() )) { #ifdef KROSS_PYTHON_SCRIPT_EXEC_DEBUG - krossdebug( QString("PythonScript::execute() class '%1' added.").arg(vt.first.as_string().c_str()) ); + krossdebug( TQString("PythonScript::execute() class '%1' added.").tqarg(vt.first.as_string().c_str()) ); #endif d->m_classes.append( vt.first.as_string().c_str() ); } else if(vt.second.isCallable()) { #ifdef KROSS_PYTHON_SCRIPT_EXEC_DEBUG - krossdebug( QString("PythonScript::execute() function '%1' added.").arg(vt.first.as_string().c_str()) ); + krossdebug( TQString("PythonScript::execute() function '%1' added.").tqarg(vt.first.as_string().c_str()) ); #endif d->m_functions.append( vt.first.as_string().c_str() ); } @@ -345,15 +345,15 @@ Kross::Api::Object::Ptr PythonScript::execute() Py::Object errobj = Py::value(e); if(errobj.ptr() == Py_None) // at least string-exceptions have there errormessage in the type-object errobj = Py::type(e); - QString err = errobj.as_string().c_str(); + TQString err = errobj.as_string().c_str(); - Kross::Api::Exception::Ptr exception = toException( QString("Failed to execute python code: %1").arg(err) ); + Kross::Api::Exception::Ptr exception = toException( TQString("Failed to execute python code: %1").tqarg(err) ); e.clear(); // exception is handled. clear it now. setException( exception ); } catch(Py::Exception& e) { - QString err = Py::value(e).as_string().c_str(); - Kross::Api::Exception::Ptr exception = toException( QString("Failed to execute python code: %1").arg(err) ); + TQString err = Py::value(e).as_string().c_str(); + Kross::Api::Exception::Ptr exception = toException( TQString("Failed to execute python code: %1").tqarg(err) ); e.clear(); // exception is handled. clear it now. setException( exception ); } @@ -365,18 +365,18 @@ Kross::Api::Object::Ptr PythonScript::execute() return 0; // return nothing if exception got thrown. } -Kross::Api::Object::Ptr PythonScript::callFunction(const QString& name, Kross::Api::List::Ptr args) +Kross::Api::Object::Ptr PythonScript::callFunction(const TQString& name, Kross::Api::List::Ptr args) { #ifdef KROSS_PYTHON_SCRIPT_CALLFUNC_DEBUG - krossdebug( QString("PythonScript::callFunction(%1, %2)") - .arg(name) - .arg(args ? QString::number(args->count()) : QString("NULL")) ); + krossdebug( TQString("PythonScript::callFunction(%1, %2)") + .tqarg(name) + .tqarg(args ? TQString::number(args->count()) : TQString("NULL")) ); #endif if(hadException()) return 0; // abort if we had an unresolved exception. if(! d->m_module) { - setException( new Kross::Api::Exception(QString("Script not initialized.")) ); + setException( new Kross::Api::Exception(TQString("Script not initialized.")) ); return 0; } @@ -386,23 +386,23 @@ Kross::Api::Object::Ptr PythonScript::callFunction(const QString& name, Kross::A // Try to determinate the function we like to execute. PyObject* func = PyDict_GetItemString(moduledict.ptr(), name.latin1()); - if( (! d->m_functions.contains(name)) || (! func) ) - throw Kross::Api::Exception::Ptr( new Kross::Api::Exception(QString("No such function '%1'.").arg(name)) ); + if( (! d->m_functions.tqcontains(name)) || (! func) ) + throw Kross::Api::Exception::Ptr( new Kross::Api::Exception(TQString("No such function '%1'.").tqarg(name)) ); Py::Callable funcobject(func, true); // the funcobject takes care of freeing our func pyobject. // Check if the object is really a function and therefore callable. if(! funcobject.isCallable()) - throw Kross::Api::Exception::Ptr( new Kross::Api::Exception(QString("Function is not callable.")) ); + throw Kross::Api::Exception::Ptr( new Kross::Api::Exception(TQString("Function is not callable.")) ); // Call the function. Py::Object result = funcobject.apply(PythonExtension::toPyTuple(args)); return PythonExtension::toObject(result); } catch(Py::Exception& e) { - QString err = Py::value(e).as_string().c_str(); + TQString err = Py::value(e).as_string().c_str(); e.clear(); // exception is handled. clear it now. - setException( new Kross::Api::Exception(QString("Python Exception: %1").arg(err)) ); + setException( new Kross::Api::Exception(TQString("Python Exception: %1").tqarg(err)) ); } catch(Kross::Api::Exception::Ptr e) { setException(e); @@ -411,19 +411,19 @@ Kross::Api::Object::Ptr PythonScript::callFunction(const QString& name, Kross::A return 0; // return nothing if exception got thrown. } -const QStringList& PythonScript::getClassNames() +const TQStringList& PythonScript::getClassNames() { if(! d->m_module) initialize(); //TODO catch exception return d->m_classes; } -Kross::Api::Object::Ptr PythonScript::classInstance(const QString& name) +Kross::Api::Object::Ptr PythonScript::classInstance(const TQString& name) { if(hadException()) return 0; // abort if we had an unresolved exception. if(! d->m_module) { - setException( new Kross::Api::Exception(QString("Script not initialized.")) ); + setException( new Kross::Api::Exception(TQString("Script not initialized.")) ); return 0; } @@ -432,22 +432,22 @@ Kross::Api::Object::Ptr PythonScript::classInstance(const QString& name) // Try to determinate the class. PyObject* pyclass = PyDict_GetItemString(moduledict.ptr(), name.latin1()); - if( (! d->m_classes.contains(name)) || (! pyclass) ) - throw Kross::Api::Exception::Ptr( new Kross::Api::Exception(QString("No such class '%1'.").arg(name)) ); + if( (! d->m_classes.tqcontains(name)) || (! pyclass) ) + throw Kross::Api::Exception::Ptr( new Kross::Api::Exception(TQString("No such class '%1'.").tqarg(name)) ); PyObject *pyobj = PyInstance_New(pyclass, 0, 0);//aclarg, 0); if(! pyobj) - throw Kross::Api::Exception::Ptr( new Kross::Api::Exception(QString("Failed to create instance of class '%1'.").arg(name)) ); + throw Kross::Api::Exception::Ptr( new Kross::Api::Exception(TQString("Failed to create instance of class '%1'.").tqarg(name)) ); Py::Object classobject(pyobj, true); #ifdef KROSS_PYTHON_SCRIPT_CLASSINSTANCE_DEBUG - krossdebug( QString("PythonScript::classInstance() inst='%1'").arg(classobject.as_string().c_str()) ); + krossdebug( TQString("PythonScript::classInstance() inst='%1'").tqarg(classobject.as_string().c_str()) ); #endif return PythonExtension::toObject(classobject); } catch(Py::Exception& e) { - QString err = Py::value(e).as_string().c_str(); + TQString err = Py::value(e).as_string().c_str(); e.clear(); // exception is handled. clear it now. setException( Kross::Api::Exception::Ptr( new Kross::Api::Exception(err) ) ); } -- cgit v1.2.3