From: Felix Domke Date: Tue, 18 Jan 2005 06:43:49 +0000 (+0000) Subject: first version of PythonSignals - need to be finalized a bit, but work basically X-Git-Url: http://code.vuplus.com/gitweb/?p=vuplus_dvbapp;a=commitdiff_plain;h=7c12c1089cfbee5b0a390d5f3de37f85de210263;ds=sidebyside first version of PythonSignals - need to be finalized a bit, but work basically --- diff --git a/lib/gui/ebutton.cpp b/lib/gui/ebutton.cpp index effcf1f..e24abd6 100644 --- a/lib/gui/ebutton.cpp +++ b/lib/gui/ebutton.cpp @@ -6,7 +6,7 @@ eButton::eButton(eWidget *parent): eLabel(parent) void eButton::push() { -// selected(); + selected(); } int eButton::event(int event, void *data, void *data2) diff --git a/lib/gui/ebutton.h b/lib/gui/ebutton.h index 2508707..a635d67 100644 --- a/lib/gui/ebutton.h +++ b/lib/gui/ebutton.h @@ -2,12 +2,13 @@ #define __lib_gui_ebutton_h #include +#include class eButton: public eLabel { public: eButton(eWidget *parent); -// Signal0 selected; + PSignal0 selected; void push(); protected: diff --git a/lib/python/enigma_python.i b/lib/python/enigma_python.i index c9dc42e..15bc16e 100644 --- a/lib/python/enigma_python.i +++ b/lib/python/enigma_python.i @@ -13,6 +13,7 @@ #include #include #include +#include %} #define DEBUG @@ -25,6 +26,8 @@ %include %template(eServiceCenterPtr) ePtr; +%immutable eButton::selected; + %include %include %include @@ -36,3 +39,33 @@ %include %include +template class PSignal0 +{ +public: + PyObject *get(); +}; + +template class PSignal1 +{ +public: + PyObject *get(); +}; + +template class PSignal2 +{ +public: + PyObject *get(); +}; + +%template(PSignal1VI) PSignal1; + +%typemap(out) PSignal1VI { + $1 = $input->get(); +} + +%template(PSignal0V) PSignal0; + +%typemap(out) PSignal0V { + $1 = $input->get(); +} + diff --git a/lib/python/python.cpp b/lib/python/python.cpp index a9ad32f..9e7e5c2 100644 --- a/lib/python/python.cpp +++ b/lib/python/python.cpp @@ -1,8 +1,47 @@ #include +#include #include extern "C" void init_enigma(); +#if 0 +ePyObject::ePyObject(void *ptr): m_object(ptr) +{ + Py_XINCREF((PyObject*)ptr); +} + +ePyObject::ePyObject(ePyObject &p) +{ + m_object = p.m_object; + Py_XINCREF((PyObject*)m_object); +} + +ePyObject::ePyObject(): m_object(0) +{ +} + +ePyObject::~ePyObject() +{ + Py_XDECREF((PyObject*)m_object); +} + +ePyObject &ePyObject::operator=(ePyObject &p) +{ + Py_XDECREF((PyObject*)m_object); + m_object = p.m_object; + Py_XINCREF((PyObject*)m_object); + return *this; +} + +ePyObject &ePyObject::operator=(void *object) +{ + Py_XDECREF((PyObject*)m_object); + m_object = object; + Py_XINCREF((PyObject*)m_object); + return *this; +} +#endif + ePython::ePython() { Py_Initialize(); @@ -55,3 +94,45 @@ int ePython::execute(const std::string &pythonfile, const std::string &funcname) } return 0; } + +void ePython::call(PyObject *pFunc, PyObject *pArgs) +{ + PyObject *pValue; + if (pFunc && PyCallable_Check(pFunc)) + { + pValue = PyObject_CallObject(pFunc, pArgs); + if (pValue != NULL) + { + printf("Result of call: %ld\n", PyInt_AsLong(pValue)); + Py_DECREF(pValue); + } else + { + PyErr_Print(); + } + } +} + +PyObject *ePython::resolve(const std::string &pythonfile, const std::string &funcname) +{ + PyObject *pName, *pModule, *pDict, *pFunc; + + pName = PyString_FromString(pythonfile.c_str()); + + pModule = PyImport_Import(pName); + Py_DECREF(pName); + + if (pModule != NULL) + { + pDict = PyModule_GetDict(pModule); + pFunc = PyDict_GetItemString(pDict, funcname.c_str()); + Py_XINCREF(pFunc); + Py_DECREF(pModule); + eDebug("resolved to %p", pFunc); + return pFunc; + } else + { + if (PyErr_Occurred()) + PyErr_Print(); + return 0; + } +} diff --git a/lib/python/python.h b/lib/python/python.h index bde1814..9435917 100644 --- a/lib/python/python.h +++ b/lib/python/python.h @@ -3,14 +3,30 @@ #include +/* class ePyObject +{ + void *m_object; +public: + ePyObject(void *ptr); + ePyObject(ePyObject &p); + ePyObject(); + ePyObject &operator=(ePyObject &p); + ePyObject &operator=(void *p); + ~ePyObject(); + void *get() { return m_object; } +}; */ + +typedef struct _object PyObject; + class ePython { public: ePython(); ~ePython(); int execute(const std::string &pythonfile, const std::string &funcname); + static void call(PyObject *pFunc, PyObject *args); + static PyObject *resolve(const std::string &pythonfile, const std::string &funcname); private: - }; #endif