first version of PythonSignals - need to be finalized a bit, but work basically
authorFelix Domke <tmbinc@elitedvb.net>
Tue, 18 Jan 2005 06:43:49 +0000 (06:43 +0000)
committerFelix Domke <tmbinc@elitedvb.net>
Tue, 18 Jan 2005 06:43:49 +0000 (06:43 +0000)
lib/gui/ebutton.cpp
lib/gui/ebutton.h
lib/python/enigma_python.i
lib/python/python.cpp
lib/python/python.h

index effcf1f..e24abd6 100644 (file)
@@ -6,7 +6,7 @@ eButton::eButton(eWidget *parent): eLabel(parent)
 
 void eButton::push()
 {
-//     selected();
+       selected();
 }
 
 int eButton::event(int event, void *data, void *data2)
index 2508707..a635d67 100644 (file)
@@ -2,12 +2,13 @@
 #define __lib_gui_ebutton_h
 
 #include <lib/gui/elabel.h>
+#include <lib/python/connections.h>
 
 class eButton: public eLabel
 {
 public:
        eButton(eWidget *parent);
-//     Signal0<void> selected;
+       PSignal0<void> selected;
 
        void push();
 protected:
index c9dc42e..15bc16e 100644 (file)
@@ -13,6 +13,7 @@
 #include <lib/gui/ewindow.h>
 #include <lib/gui/ewidgetdesktop.h>
 #include <lib/gui/eslider.h>
+#include <lib/python/connections.h>
 %}
 
 #define DEBUG
@@ -25,6 +26,8 @@
 %include <lib/service/service.h>
 %template(eServiceCenterPtr) ePtr<eServiceCenter>;
 
+%immutable eButton::selected;
+
 %include <lib/gdi/epoint.h>
 %include <lib/gdi/erect.h>
 %include <lib/gdi/esize.h>
 %include <lib/gui/eslider.h>
 %include <lib/gui/ewidgetdesktop.h>
 
+template<class R> class PSignal0
+{
+public:
+       PyObject *get();
+};
+
+template<class R, class P0> class PSignal1
+{
+public:
+       PyObject *get();
+};
+
+template<class R, class P0, class P1> class PSignal2
+{
+public:
+       PyObject *get();
+};
+
+%template(PSignal1VI) PSignal1<void,int>;
+
+%typemap(out) PSignal1VI {
+       $1 = $input->get();
+}
+
+%template(PSignal0V) PSignal0<void>;
+
+%typemap(out) PSignal0V {
+       $1 = $input->get();
+}
+
index a9ad32f..9e7e5c2 100644 (file)
@@ -1,8 +1,47 @@
 #include <lib/python/python.h>
+#include <lib/base/eerror.h>
 #include <Python.h>
 
 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;
+       }
+}
index bde1814..9435917 100644 (file)
@@ -3,14 +3,30 @@
 
 #include <string>
 
+/* 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