diff options
| author | 2010-07-04 00:49:11 +0000 | |
|---|---|---|
| committer | 2010-07-04 00:49:11 +0000 | |
| commit | 2637bc9cc68dc26b395634b276f416d96a83809c (patch) | |
| tree | 041c3c6bfdb124a99ca04ddbf9fb874ca5fe8091 /src/modules/pythoncore | |
| parent | Fix crash in toolbar customization (diff) | |
| download | KVIrc-2637bc9cc68dc26b395634b276f416d96a83809c.tar.gz KVIrc-2637bc9cc68dc26b395634b276f416d96a83809c.tar.bz2 KVIrc-2637bc9cc68dc26b395634b276f416d96a83809c.zip | |
Improve a bit the python interpreter: allow for passing arguments in python.begin. Add documentation for python.begin and python.end
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@4587 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src/modules/pythoncore')
| -rw-r--r-- | src/modules/pythoncore/libkvipythoncore.cpp | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/src/modules/pythoncore/libkvipythoncore.cpp b/src/modules/pythoncore/libkvipythoncore.cpp index 03b29abf7..aef979c02 100644 --- a/src/modules/pythoncore/libkvipythoncore.cpp +++ b/src/modules/pythoncore/libkvipythoncore.cpp @@ -80,6 +80,22 @@ bool KviPythonInterpreter::init() PyInterpreterState * mainInterpreterState = mainThreadState->interp; // create a thread state object for this thread m_pThreadState = PyThreadState_New(mainInterpreterState); + // swap in the current thread state + PyThreadState_Swap(m_pThreadState); + // and hook in the kvirc error handling routines + QString szPreCode = QString( \ + "import kvirc\n" \ + "import sys\n" \ + "class kvirc_stderr_grabber:\n" \ + "\tdef write(self,s):\n" \ + "\t\tkvirc.error(s)\n" \ + "sys.stderr=kvirc_stderr_grabber()\n" + ); + // evaluate that + PyRun_SimpleString(szPreCode.toUtf8().data()); + // swap out our thread state for now + PyThreadState_Swap(NULL); + // free the lock PyEval_ReleaseLock(); return true; @@ -103,7 +119,7 @@ void KviPythonInterpreter::done() bool KviPythonInterpreter::execute( const QString &szCode, - QStringList &, //args + QStringList &lArgs, //args QString &szRetVal, QString &szError, QStringList &) //lWarnings @@ -121,6 +137,10 @@ bool KviPythonInterpreter::execute( PyEval_AcquireLock(); // swap in my thread state PyThreadState_Swap(m_pThreadState); + + + +#if 0 // now it's done in the initialization function of the interpreter //prepend some helping functions QString szPreCode= QString("import kvirc\n" \ "import sys\n" \ @@ -130,6 +150,24 @@ bool KviPythonInterpreter::execute( "sys.stderr=kvirc_stderr_grabber()\n" ); PyRun_SimpleString(szPreCode.toUtf8().data()); +#endif + + QString szVarCode = "aArgs = ["; + + bool bFirst = true; + foreach(QString szArg,lArgs) + { + if(!bFirst) + szVarCode += ","; + else + bFirst = false; + + szVarCode += QString::fromAscii("\"%1\"").arg(szArg); + } + + szVarCode += "]"; + + PyRun_SimpleString(szVarCode.toUtf8().data()); // execute some python code retVal = PyRun_SimpleString(szCode.toUtf8().data()); @@ -148,7 +186,7 @@ bool KviPythonInterpreter::execute( if(retVal) return false; - else return true; + return true; } static KviPointerHashTable<QString,KviPythonInterpreter> * g_pInterpreters = 0; |
