diff options
| author | 2009-07-30 17:02:41 +0000 | |
|---|---|---|
| committer | 2009-07-30 17:02:41 +0000 | |
| commit | 79db13f4bb5a4010e0d435a38b3d08001f1c1905 (patch) | |
| tree | 61f0a68dbfbaef9c57d0aed730c49b84b2ae8e35 | |
| parent | updated spanish translation files, thanks goes to Armando Camarero (diff) | |
| download | KVIrc-79db13f4bb5a4010e0d435a38b3d08001f1c1905.tar.gz KVIrc-79db13f4bb5a4010e0d435a38b3d08001f1c1905.tar.bz2 KVIrc-79db13f4bb5a4010e0d435a38b3d08001f1c1905.zip | |
first testing implementation of python support: this IS NOT intended to work yet!
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@3391 17fca916-40b9-46aa-a4ea-0a15b648b75c
| -rw-r--r-- | src/modules/CMakeLists.txt | 8 | ||||
| -rw-r--r-- | src/modules/python/CMakeLists.txt | 12 | ||||
| -rw-r--r-- | src/modules/python/libkvipython.cpp | 173 | ||||
| -rw-r--r-- | src/modules/pythoncore/CMakeLists.txt | 32 | ||||
| -rw-r--r-- | src/modules/pythoncore/kvircmodule.cpp | 204 | ||||
| -rw-r--r-- | src/modules/pythoncore/kvircmodule.h | 116 | ||||
| -rw-r--r-- | src/modules/pythoncore/libkvipythoncore.cpp | 121 | ||||
| -rw-r--r-- | src/modules/pythoncore/pythoncoreinterface.h | 52 |
8 files changed, 716 insertions, 2 deletions
diff --git a/src/modules/CMakeLists.txt b/src/modules/CMakeLists.txt index 84f925fd9..e05491b09 100644 --- a/src/modules/CMakeLists.txt +++ b/src/modules/CMakeLists.txt @@ -31,7 +31,7 @@ SUBDIRS( mask math mediaplayer mircimport my notifier objects options - perlcore popupeditor proxydb + perlcore popupeditor proxydb pythoncore raweditor regchan reguser rijndael rot13 serverdb setup sharedfile sharedfileswindow snd socketspy spaste str system texticons term theme tip tmphighlight toolbar toolbareditor torrent trayicon @@ -45,4 +45,8 @@ SUBDIRS( IF(COMPILE_PERL_SUPPORT) SUBDIRS(perl) -ENDIF()
\ No newline at end of file +ENDIF() + +IF(COMPILE_PYTHON_SUPPORT) + SUBDIRS(python) +ENDIF() diff --git a/src/modules/python/CMakeLists.txt b/src/modules/python/CMakeLists.txt new file mode 100644 index 000000000..e9c44a622 --- /dev/null +++ b/src/modules/python/CMakeLists.txt @@ -0,0 +1,12 @@ +# CMakeLists for src/modules/python + +SET(kvipython_SRCS + libkvipython.cpp +) + +# After this call, files will be moc'ed to moc_kvi_*.cpp +QT4_WRAP_CPP(kvipython_MOC_SRCS ${kvipython_MOC_HDRS}) + +SET(kvi_module_name kvipython) + +INCLUDE(${CMAKE_SOURCE_DIR}/cmake/module.rules.txt) diff --git a/src/modules/python/libkvipython.cpp b/src/modules/python/libkvipython.cpp new file mode 100644 index 000000000..ee1d68ea8 --- /dev/null +++ b/src/modules/python/libkvipython.cpp @@ -0,0 +1,173 @@ +//============================================================================= +// +// File : libkvipython.cpp +// Creation date : Fri Nov 07 00:18:31 2008 GMT by Elvio Basello +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2008 Elvio Basello (hellvis69 at netsons dot org) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= + +#include "kvi_settings.h" +#include "kvi_module.h" +#include "kvi_modulemanager.h" +//#include "kvi_fileutils.h" +#include "kvi_locale.h" +//#include "kvi_app.h" +//#include "kvi_options.h" +//#include "kvi_out.h" + +#ifdef COMPILE_PYTHON_SUPPORT + #include "../pythoncore/pythoncoreinterface.h" + #include <Python.h> + + #define KVS_CHECK_PYTHONCORE(_m,_c) \ + g_pPythonCoreModule = g_pModuleManager->getModule("pythoncore"); \ + if(!g_pPythonCoreModule) \ + { \ + if(!_c->switches()->find('q',"quiet")) \ + { \ + _c->warning(__tr2qs_ctx("The pythoncore module can't be loaded: python support not available","python")); \ + _c->warning(__tr2qs_ctx("To see more details about loading failure try /pythoncore.load","python")); \ + return true; \ + } \ + } + + #define KVS_CHECK_MODULE_STATE(_m,_c) KVS_CHECK_PYTHONCORE(_m,_c) + + static KviModule * g_pPythonCoreModule = 0; + +#else // COMPILE_PYTHON_SUPPORT + + #define KVS_CHECK_PYTHONCORE(_m,_c) + + #define KVS_CHECK_MODULE_STATE(_m,_c) \ + if(!_c->switches()->find('q',"quiet")) \ + _c->warning(__tr2qs_ctx("This KVIrc executable has been compiled without python scripting support","python")); \ + return true; + + static KviModule * g_pPythonCoreModule = 0; +#endif // COMPILE_PYTHON_SUPPORT + +static bool python_kvs_cmd_begin(KviKvsModuleCommandCall * c) +{ + // This command is somewhat special in the fact that has a dedicated + // parsing routine in the KVS core parser. + // The parser sets the python code as the first parameter of our call, + // the remaining params are the arguments + + QString szCode; + KviKvsVariantList vList; + KVSM_PARAMETERS_BEGIN(c) + KVSM_PARAMETER("code",KVS_PT_STRING,0,szCode) + KVSM_PARAMETER("args",KVS_PT_VARIANTLIST,KVS_PF_OPTIONAL,vList) + KVSM_PARAMETERS_END(c) + + KVS_CHECK_MODULE_STATE(m,c) + +#ifdef COMPILE_PYTHON_SUPPORT + debug("Python module begin"); + + // FIXME Test: this prints the sentence on the stdout, like Qt's debug() + if(PyRun_SimpleString("print 'Test string'\n") < 0) + c->warning("Non funza"); + +#endif // COMPILE_PYTHON_SUPPORT + + return true; +} + +static bool python_kvs_cmd_destroy(KviKvsModuleCommandCall * c) +{ + QString szContext; + KVSM_PARAMETERS_BEGIN(c) + KVSM_PARAMETER("context",KVS_PT_NONEMPTYSTRING,0,szContext) + KVSM_PARAMETERS_END(c) + + KVS_CHECK_MODULE_STATE(m,c) + +#ifdef COMPILE_PYTHON_SUPPORT +/* +#ifdef COMPILE_PERL_SUPPORT + KviPerlCoreCtrlCommand_destroy ex; + ex.uSize = sizeof(KviPerlCoreCtrlCommand_destroy); + ex.szContext = szContext; + + if(!g_pPerlCoreModule->ctrl(KVI_PERLCORECTRLCOMMAND_DESTROY,&ex)) + { + if(!c->switches()->find('q',"quiet")) + c->warning(__tr2qs_ctx("The perlcore module failed to execute the code: something is wrong with the perl support","perl")); + } +#endif //COMPILE_PERL_SUPPORT +*/ +#endif // COMPILE_PYTHON_SUPPORT + + return true; +} + +/* + @doc: python.isAvailable + @type: + function + @title: + $python.isAvailable + @short: + Check if python scripting support is available + @syntax: + $python.isAvailable + @description: + Returns 1 if the python scripting support is available and 0 otherwise. +*/ +static bool python_kvs_fnc_isAvailable(KviKvsModuleFunctionCall * c) +{ +#ifdef COMPILE_PYTHON_SUPPORT + g_pPythonCoreModule = g_pModuleManager->getModule("pythoncore"); + c->returnValue()->setBoolean(g_pPythonCoreModule ? true : false); +#else + c->returnValue()->setBoolean(false); +#endif + return true; +} + +static bool python_module_init(KviModule * m) +{ + // register the command anyway + KVSM_REGISTER_SIMPLE_COMMAND(m,"begin",python_kvs_cmd_begin); + KVSM_REGISTER_SIMPLE_COMMAND(m,"destroy",python_kvs_cmd_destroy); + + KVSM_REGISTER_FUNCTION(m,"isAvailable",python_kvs_fnc_isAvailable); +#ifdef COMPILE_PYTHON_SUPPORT + g_pPythonCoreModule = g_pModuleManager->getModule("pythoncore"); +#endif + return true; +} + +static bool python_module_cleanup(KviModule * m) +{ + return true; +} + +KVIRC_MODULE( + "Python", // module name + "4.0.0", // module version + "Copyright (C) 2008 Elvio Basello (hellvis69 at netsons dot org", // author & (C) + "Python Scripting Engine", + python_module_init, + 0, + 0, + python_module_cleanup +) diff --git a/src/modules/pythoncore/CMakeLists.txt b/src/modules/pythoncore/CMakeLists.txt new file mode 100644 index 000000000..2d0036d27 --- /dev/null +++ b/src/modules/pythoncore/CMakeLists.txt @@ -0,0 +1,32 @@ +# CMakeLists for src/modules/pythoncore + +SET(kvipythoncore_MOC_HDRS + pythoncoreinterface.h +) + +SET(kvipythoncore_SRCS + libkvipythoncore.cpp + kvircmodule.cpp +) + +# After this call, files will be moc'ed to moc_kvi_*.cpp +QT4_WRAP_CPP(kvipythoncore_MOC_SRCS ${kvipythoncore_MOC_HDRS}) + +SET(kvi_module_name kvipythoncore) + +IF(COMPILE_PYTHON_SUPPORT) + EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE}-config --cflags + OUTPUT_VARIABLE PYTHON_COMPILE_FLAGS + ) + + # Remove new line characters + STRING(REGEX REPLACE "(\r?\n)+$" "" PYTHON_COMPILE_FLAGS "${PYTHON_COMPILE_FLAGS}") + # Remove leading and trailing spaces (string strip) + STRING(REGEX REPLACE "(^( )+|( )+$)" "" PYTHON_COMPILE_FLAGS "${PYTHON_COMPILE_FLAGS}") +ENDIF() + +INCLUDE(${CMAKE_SOURCE_DIR}/cmake/module.rules.txt) + +IF(COMPILE_PYTHON_SUPPORT) + SET_TARGET_PROPERTIES(${kvi_module_name} PROPERTIES COMPILE_FLAGS "${PYTHON_COMPILE_FLAGS}") +ENDIF() diff --git a/src/modules/pythoncore/kvircmodule.cpp b/src/modules/pythoncore/kvircmodule.cpp new file mode 100644 index 000000000..da22310f9 --- /dev/null +++ b/src/modules/pythoncore/kvircmodule.cpp @@ -0,0 +1,204 @@ +//============================================================================= +// +// File : kvircmodule.cpp +// Creation date : Wed Nov 19 19:11:29 2008 GMT by Elvio Basello +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2008 Elvio Basello (hellvis69 at netsons dot org) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= + +#include "kvi_settings.h" + +#ifdef COMPILE_PYTHON_SUPPORT + +#include <Python.h> + +#define KVIRC_MODULE + +#include "kvircmodule.h" +#include "kvi_window.h" +#include "kvi_userinput.h" +#include "kvi_kvs_runtimecontext.h" +#include "kvi_kvs_script.h" + + +static KviKvsRunTimeContext * g_pCurrentKvsContext = 0; +static KviStr g_szLastReturnValue(""); + +/* +static int PyKVIrc_Echo(const char * pcCmd) +{ + return system(pcCmd); +} +*/ + +static PyObject * PyKVIrc_echo(PyObject * pSelf, PyObject * pArgs) +{ + const char * pcText; + int iColorSet; + const char * pcWinId; + + if(!PyArg_ParseTuple(pArgs,"s|is",&pcText,&iColorSet,&pcWinId)) + return 0; + + if(g_pCurrentKvsContext && pcText) + { + KviWindow * pWnd; + if(pcWinId) + { + pWnd = g_pApp->findWindow(pcWinId); + if(!pWnd) + pWnd = g_pCurrentKvsContext->window(); + } else { + pWnd = g_pCurrentKvsContext->window(); + } + pWnd->outputNoFmt(iColorSet,QString::fromUtf8(pcText)); + } + + //sts = PyKVIrc_System(command); + //return Py_BuildValue("i", sts); + return Py_BuildValue("i",1); +} + +static PyObject * PyKVIrc_say(PyObject * pSelf, PyObject * pArgs) +{ + const char * pcText; + const char * pcWinId; + + if(!PyArg_ParseTuple(pArgs,"s|s",&pcText,&pcWinId)) + return 0; + + if(g_pCurrentKvsContext && pcText) + { + KviWindow * pWnd; + if(pcWinId) + { + pWnd = g_pApp->findWindow(pcWinId); + if(!pWnd) + pWnd = g_pCurrentKvsContext->window(); + } else { + pWnd = g_pCurrentKvsContext->window(); + } + QString szTmp = QString::fromUtf8(pcText); + KviUserInput::parse(szTmp,pWnd); + } + + return Py_BuildValue("i",1); +} + +static PyObject * PyKVIrc_warning(PyObject * pSelf, PyObject * pArgs) +{ +} + +static PyObject * PyKVIrc_getLocal(PyObject * pSelf, PyObject * pArgs) +{ +} + +static PyObject * PyKVIrc_setLocal(PyObject * pSelf, PyObject * pArgs) +{ +} + +static PyObject * PyKVIrc_getGlobal(PyObject * pSelf, PyObject * pArgs) +{ +} + +static PyObject * PyKVIrc_setGlobal(PyObject * pSelf, PyObject * pArgs) +{ +} + +static PyObject * PyKVIrc_eval(PyObject * pSelf, PyObject * pArgs) +{ + const char * pcCode; + char * pcRetVal; + + if(!PyArg_ParseTuple(pArgs,"s",&pcCode)) + return 0; + + if(g_pCurrentKvsContext && pcCode) + { + KviKvsVariant ret; + if(KviKvsScript::run(QString::fromUtf8(pcCode),g_pCurrentKvsContext->window(),0,&ret)) + { + QString szTmp; + ret.asString(szTmp); + g_szLastReturnValue = szTmp; + } else { + g_szLastReturnValue = ""; + } + pcRetVal = g_szLastReturnValue.ptr(); + } else { + pcRetVal = ""; + } + + return Py_BuildValue("s",pcRetVal); +} + +static PyObject * PyKVIrc_internalWarning(PyObject * pSelf, PyObject * pArgs) +{ +} + +static PyMethodDef KVIrcMethods[] = { + { "KVIrc::echo", PyKVIrc_echo, METH_VARARGS, + "Outputs a text to a KVIrc window" }, + { "KVIrc::say", PyKVIrc_say, METH_VARARGS, + "Types text in a window" }, + { "KVIrc::warning", PyKVIrc_warning, METH_VARARGS, + "Prints a warning message" }, + { "KVIrc::getLocal", PyKVIrc_getLocal, METH_VARARGS, + "Gets a local variable" }, + { "KVIrc::setLocal", PyKVIrc_setLocal, METH_VARARGS, + "Sets a local variable" }, + { "KVIrc::getGlobal", PyKVIrc_getGlobal, METH_VARARGS, + "Gets a global variable" }, + { "KVIrc::setGlobal", PyKVIrc_setGlobal, METH_VARARGS, + "Sets a global variable" }, + { "KVIrc::eval", PyKVIrc_eval, METH_VARARGS, + "Change the behaviour of a set of commands" }, + { "KVIrc::internalWarning", PyKVIrc_internalWarning, METH_VARARGS, + "" }, + { NULL, NULL, 0, NULL } +}; + +PyMODINIT_FUNC python_init() +{ + static void * PyKVIrc_API[PyKVIrc_API_NUM]; + PyObject * pModule; + PyObject * pC_API_Object; + + pModule = Py_InitModule("kvirc",KVIrcMethods); + if(!pModule) return; + + // Initialize the C API pointer array + PyKVIrc_API[0] = (void *)PyKVIrc_echo; + PyKVIrc_API[1] = (void *)PyKVIrc_say; + PyKVIrc_API[2] = (void *)PyKVIrc_warning; + PyKVIrc_API[3] = (void *)PyKVIrc_getLocal; + PyKVIrc_API[4] = (void *)PyKVIrc_setLocal; + PyKVIrc_API[5] = (void *)PyKVIrc_getGlobal; + PyKVIrc_API[6] = (void *)PyKVIrc_setGlobal; + PyKVIrc_API[7] = (void *)PyKVIrc_eval; + PyKVIrc_API[8] = (void *)PyKVIrc_internalWarning; + + // Create a CObject containing the API pointer array's address + pC_API_Object = PyCObject_FromVoidPtr((void *)PyKVIrc_API,NULL); + + if(pC_API_Object) + PyModule_AddObject(pModule,"_C_API",pC_API_Object); +} + +#endif diff --git a/src/modules/pythoncore/kvircmodule.h b/src/modules/pythoncore/kvircmodule.h new file mode 100644 index 000000000..74363cb33 --- /dev/null +++ b/src/modules/pythoncore/kvircmodule.h @@ -0,0 +1,116 @@ +#ifndef Py_KVIRCMODULE_H +#define Py_KVIRCMODULE_H +//============================================================================= +// +// File : kvircmodule.h +// Creation date : Wed Nov 19 19:11:29 2008 GMT by Elvio Basello +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2008 Elvio Basello (hellvis69 at netsons dot org) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= + +/** +* \file kvircmodule.h +* \author Elvio Basello +* \brief KVIrc module for Python +* +* This python module defines some functions to interact with KVIrc and run its +* builtin functions. It's useful when writing Python scripts inside KVIrc. +*/ + +#include "kvi_settings.h" + +#ifdef COMPILE_PYTHON_SUPPORT + +#include <Python.h> + +// Prototype +PyMODINIT_FUNC python_init(); + +#ifdef __cplusplus +extern "C" { +#endif + + // Total number of C API pointers + #define PyKVIrc_API_NUM 9 + + #ifdef KVIRC_MODULE + // This section is used when compiling kvircmodule.cpp + static PyObject * PyKVIrc_echo(PyObject * pSelf, PyObject * pArgs); + static PyObject * PyKVIrc_say(PyObject * pSelf, PyObject * pArgs); + static PyObject * PyKVIrc_warning(PyObject * pSelf, PyObject * pArgs); + static PyObject * PyKVIrc_getLocal(PyObject * pSelf, PyObject * pArgs); + static PyObject * PyKVIrc_setLocal(PyObject * pSelf, PyObject * pArgs); + static PyObject * PyKVIrc_getGlobal(PyObject * pSelf, PyObject * pArgs); + static PyObject * PyKVIrc_setGlobal(PyObject * pSelf, PyObject * pArgs); + static PyObject * PyKVIrc_eval(PyObject * pSelf, PyObject * pArgs); + static PyObject * PyKVIrc_internalWarning(PyObject * pSelf, PyObject * pArgs); + #else + // This section is used in modules that use kvircmodule's API + static void ** PyKVIrc_API; + + #define PyKVIrc_echo \ + (*(int (*)(const char * pcCmd)) PyKVIrc_API[0]) + #define PyKVIrc_say \ + (*(int (*)(const char * pcCmd)) PyKVIrc_API[1]) + #define PyKVIrc_warning \ + (*(int (*)(const char * pcCmd)) PyKVIrc_API[2]) + #define PyKVIrc_getLocal \ + (*(int (*)(const char * pcCmd)) PyKVIrc_API[3]) + #define PyKVIrc_setLocal \ + (*(int (*)(const char * pcCmd)) PyKVIrc_API[4]) + #define PyKVIrc_getGlobal \ + (*(int (*)(const char * pcCmd)) PyKVIrc_API[5]) + #define PyKVIrc_setGlobal \ + (*(int (*)(const char * pcCmd)) PyKVIrc_API[6]) + #define PyKVIrc_eval \ + (*(int (*)(const char * pcCmd)) PyKVIrc_API[7]) + #define PyKVIrc_internalWarning \ + (*(int (*)(const char * pcCmd)) PyKVIrc_API[8]) + + /** + * \brief Returns 0 on success, -1 otherwise + * + * In case on unsuccess, it sets the exception + * \return int + */ + static int import_kvirc() + { + PyObject * pModule = PyImport_ImportModule("kvirc"); + if(pModule) + { + PyObject * pC_API_Object = PyObject_GetAttrString(pModule,"_C_API"); + + if(!pC_API_Object) return -1; + + if(PyCObject_Check(pC_API_Object)) + PyKVIrc_API = (void **)PyCObject_AsVoidPtr(pC_API_Object); + + Py_DECREF(pC_API_Object); + } + return 0; + } + #endif // KVIRC_MODULE + +#ifdef __cplusplus +} +#endif + +#endif // COMPILE_PYTHON_SUPPORT + +#endif // Py_KVIRCMODULE_H diff --git a/src/modules/pythoncore/libkvipythoncore.cpp b/src/modules/pythoncore/libkvipythoncore.cpp new file mode 100644 index 000000000..e26bfba2e --- /dev/null +++ b/src/modules/pythoncore/libkvipythoncore.cpp @@ -0,0 +1,121 @@ +//============================================================================= +// +// File : libkvipythoncore.cpp +// Creation date : Fri Nov 07 00:18:31 2008 GMT by Elvio Basello +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2008 Elvio Basello (hellvis69 at netsons dot org) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= + + +#include "kvi_settings.h" +#include "kvi_module.h" +#include "kvi_locale.h" +//#include "kvi_modulemanager.h" +//#include "kvi_fileutils.h" +//#include "kvi_app.h" +//#include "kvi_options.h" +//#include "kvi_out.h" + +#ifdef COMPILE_PYTHON_SUPPORT + #include "kvircmodule.h" + #include "pythoncoreinterface.h" + #include <Python.h> + +/* + class KviPythonInterpreter + { + public: + KviPythonInterpreter(const QString & szContextName); + ~KviPythonInterpreter(); + protected: + QString m_szContextName; + //PerlInterpreter * m_pInterpreter; + public: + bool init(); // if this fails then well.. :D + void done(); + bool execute(const QString & szCode, QStringList & lArgs, QString & szRetVal, QString & szError, QStringList & lWarnings); + const QString & contextName(){ return m_szContextName; }; + //protected: + // QString svToQString(SV * sv); + }; + + KviPythonInterpreter::KviPythonInterpreter(const QString & szContextName) + { + m_szContextName = szContextName; + //m_pInterpreter = 0; + } + + KviPythonInterpreter::~KviPythonInterpreter() + { + done(); + } +*/ +#endif // COMPILE_PYTHON_SUPPORT + +static bool pythoncore_module_init(KviModule * m) +{ +#ifdef COMPILE_PYTHON_SUPPORT + + // Initialize the Python interpreter + debug("Initializing Python interpreter"); +#ifdef COMPILE_ON_MAC + PyMac_Initialize(); +#else + Py_Initialize(); +#endif + + // Initialize the Python module for KVIrc + python_init(); + + //g_pInterpreters = new KviPointerHashTable<QString,KviPerlInterpreter>(17,false); + //g_pInterpreters->setAutoDelete(false); + return true; + +#endif // COMPILE_PYTHON_SUPPORT + + return false; +} + +static bool pythoncore_module_cleanup(KviModule * m) +{ +#ifdef COMPILE_PYTHON_SUPPORT + //perlcore_destroy_all_interpreters(); + //delete g_pInterpreters; + //g_pInterpreters = 0; + + // Free the memory used by the Python interpreter + Py_Finalize(); + + // Close the intepreter + Py_Exit(0); +#endif // COMPILE_PYTHON_SUPPORT + + return true; +} + +KVIRC_MODULE( + "PythonCore", // module name + "4.0.0", // module version + "Copyright (C) 2008 Elvio Basello (hellvis69 at netsons dot org", // author & (C) + "Python Scripting Engine Core", + pythoncore_module_init, + 0, + 0, + pythoncore_module_cleanup +) diff --git a/src/modules/pythoncore/pythoncoreinterface.h b/src/modules/pythoncore/pythoncoreinterface.h new file mode 100644 index 000000000..f09fde948 --- /dev/null +++ b/src/modules/pythoncore/pythoncoreinterface.h @@ -0,0 +1,52 @@ +#ifndef _PYTHONCOREINTERFACE_H_ +#define _PYTHONCOREINTERFACE_H_ +//============================================================================= +// +// File : pythoncoreinterface.h +// Creation date : Fri Nov 07 00:18:31 2008 GMT by Elvio Basello +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2008 Elvio Basello (hellvis69 at netsons dot org) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= + +#include "kvi_settings.h" +#include "kvi_qstring.h" +#include "kvi_kvs_runtimecontext.h" + +#include <QStringList> + +typedef struct _KviPythonCoreCtrlCommand_execute +{ + unsigned int uSize; + KviKvsRunTimeContext * pKvsContext; + QString szCode; + bool bExitOk; + QString szRetVal; + QString szError; + QStringList lWarnings; + QStringList lArgs; + bool bQuiet; +} KviPythonCoreCtrlCommand_execute; + +typedef struct _KviPythonCoreCtrlCommand_destroy +{ + unsigned int uSize; + QString szContext; +} KviPythonCoreCtrlCommand_destroy; + +#endif // _PYTHONCOREINTERFACE_H_ |
