- add python, missing gui
[vuplus_dvbapp] / lib / python / python.cpp
1 #include <lib/python/python.h>
2 #include <Python.h>
3
4 extern "C" void init_enigma();
5
6 ePython::ePython()
7 {
8         Py_Initialize();
9         
10         init_enigma();
11 }
12
13 ePython::~ePython()
14 {
15         Py_Finalize();
16 }
17
18 int ePython::execute(const std::string &pythonfile, const std::string &funcname)
19 {
20         PyObject *pName, *pModule, *pDict, *pFunc, *pArgs, *pValue;
21         
22         pName = PyString_FromString(pythonfile.c_str());
23         
24         pModule = PyImport_Import(pName);
25         Py_DECREF(pName);
26         
27         if (pModule != NULL)
28         {
29                 pDict = PyModule_GetDict(pModule);
30                 
31                 pFunc = PyDict_GetItemString(pDict, funcname.c_str());
32                 
33                 if (pFunc && PyCallable_Check(pFunc))
34                 {
35                         pArgs = PyTuple_New(0);
36                                 // implement arguments..
37                         pValue = PyObject_CallObject(pFunc, pArgs);
38                         Py_DECREF(pArgs);
39                         if (pValue != NULL)
40                         {
41                                 printf("Result of call: %ld\n", PyInt_AsLong(pValue));
42                                 Py_DECREF(pValue);
43                         } else
44                         {
45                                 Py_DECREF(pModule);
46                                 PyErr_Print();
47                                 return 1;
48                         }
49                 }
50         } else
51         {
52                 if (PyErr_Occurred())
53                         PyErr_Print();
54                 return 1;
55         }
56         return 0;
57 }