54a5bcf342a1d191573fde4e42cb6425aecdd8d3
[enigma2.git] / lib / python / enigma_python.i
1 /*
2   NOTE: you have two options when adding classes so that
3   they are callable *from* python.
4   
5    - either you %include the header file
6    - or you re-declare it
7    
8   In both cases, you must #include the required
9   header file (i.e. the header file itself), otherwise
10   enigma_python_wrap.cxx won't build.
11   
12         In case you import the whole header file,
13         please make sure that no unimportant stuff
14         is wrapped, as this makes the wrapper stuff
15         much more complex and it can probably break 
16         very easily because of missing typemaps etc.
17         
18         you could make use of dizzy macros to ensure
19         that some stuff is left out when parsed as SWIG
20         definitions, but be sure to not modify the binary 
21         representation. DON'T USE #ifdef SWIG_COMPILE
22         for leaving out stuff (unless you *really* know
23         what you are doing,of course!). you WILL break it.
24                 
25         The better way (with more work) is to re-declare
26         the class. It won't be compiled, so you can
27         leave out stuff as you like.
28
29
30
31 Oh, things like "operator= is private in this context" etc.
32 is usually caused by not marking PSignals as immutable. 
33 */
34
35 %module enigma
36 %{
37
38 #define SWIG_COMPILE
39 #include <lib/base/ebase.h>
40 #include <lib/base/smartptr.h>
41 #include <lib/base/eerror.h>
42 #include <lib/base/econfig.h>
43 #include <lib/service/iservice.h>
44 #include <lib/service/service.h>
45 #include <lib/service/event.h>
46 #include <lib/gdi/font.h>
47 #include <lib/gdi/gpixmap.h>
48 #include <lib/gui/ewidget.h>
49 #include <lib/gui/elabel.h>
50 #include <lib/gui/einput.h>
51 #include <lib/gui/einputstring.h>
52 #include <lib/gui/einputnumber.h>
53 #include <lib/gui/epixmap.h>
54 #include <lib/gui/ebutton.h>
55 #include <lib/gui/ewindow.h>
56 #include <lib/gui/ewidgetdesktop.h>
57 #include <lib/gui/ewindowstyle.h>
58 #include <lib/gui/ewindowstyleskinned.h>
59 #include <lib/gui/ewidgetanimation.h>
60 #include <lib/gui/eslider.h>
61 #include <lib/python/connections.h>
62 #include <lib/gui/elistbox.h>
63 #include <lib/gui/elistboxcontent.h>
64 #include <lib/service/listboxservice.h>
65 #include <lib/components/scan.h>
66 #include <lib/components/listboxepg.h>
67 #include <lib/nav/pcore.h>
68 #include <lib/actions/action.h>
69 #include <lib/gdi/gfont.h>
70 #include <lib/gdi/epng.h>
71 #include <lib/dvb/db.h>
72 #include <lib/dvb/volume.h>
73 #include <lib/dvb/sec.h>
74 #include <lib/dvb/epgcache.h>
75 #include <lib/dvb/frontendparms.h>
76 #include <lib/dvb/dvbtime.h>
77 #include <lib/driver/avswitch.h>
78 #include <lib/driver/rfmod.h>
79 #include <lib/driver/etimezone.h>
80 #include <lib/gdi/lcd.h>
81 #include <lib/dvb_ci/dvbci_ui.h>
82
83 extern void runMainloop();
84 extern void quitMainloop(int exit_code);
85 extern void setLCD(const char *c);
86 extern void setLCDClock(const char *c);
87
88 extern PSignal1<void,int> &keyPressedSignal();
89 %}
90
91 %feature("ref")   iObject "$this->AddRef(); /* eDebug(\"AddRef (%s:%d)!\", __FILE__, __LINE__); */ "
92 %feature("unref") iObject "$this->Release(); /* eDebug(\"Release! %s:%d\", __FILE__, __LINE__); */ "
93
94
95 /* this magic allows smartpointer to be used as OUTPUT arguments, i.e. call-by-reference-styled return value. */
96
97 %define %typemap_output_simple(Type)
98  %typemap(in,numinputs=0) Type *OUTPUT ($*1_ltype temp),
99               Type &OUTPUT ($*1_ltype temp)
100    "$1 = new Type;";
101  %fragment("t_out_helper"{Type},"header",
102      fragment="t_output_helper") {}
103  %typemap(argout,fragment="t_out_helper"{Type}) Type *OUTPUT, Type &OUTPUT
104    "$result = t_output_helper($result, (SWIG_NewPointerObj((void*)($1), $1_descriptor, 1)));"
105 %enddef
106
107 %define %typemap_output_ptr(Type)
108  %typemap(in,numinputs=0) Type *OUTPUT ($*1_ltype temp),
109               Type &OUTPUT ($*1_ltype temp)
110    "$1 = new Type;";
111  %fragment("t_out_helper"{Type},"header",
112      fragment="t_output_helper") {}
113  %typemap(argout,fragment="t_out_helper"{Type}) Type *OUTPUT, Type &OUTPUT
114                 // generate None if smartpointer is NULL
115    "$result = t_output_helper($result, ((*$1) ? SWIG_NewPointerObj((void*)($1), $1_descriptor, 1) : (Py_INCREF(Py_None), Py_None)));"
116 %enddef
117
118
119 #define DEBUG
120 typedef long time_t;
121 %include "typemaps.i"
122 %include "stl.i"
123 %include <lib/python/swig.h>
124 %include <lib/base/object.h>
125 %include <lib/base/eerror.h>
126 %include <lib/base/econfig.h>
127 %include <lib/base/smartptr.h>
128 %include <lib/service/iservice.h>
129 %include <lib/service/service.h>
130
131 %template(eServiceCenterPtr) ePtr<eServiceCenter>;
132 %include <lib/service/event.h>
133
134
135 // TODO: embed these...
136 %immutable eButton::selected;
137 %immutable eInput::changed;
138 %immutable eComponentScan::statusChanged;
139 %immutable pNavigation::m_event;
140
141 %include <lib/gdi/font.h>
142 %include <lib/gdi/gpixmap.h>
143 %include <lib/gdi/epoint.h>
144 %include <lib/gdi/erect.h>
145 %include <lib/gdi/esize.h>
146 %include <lib/gdi/region.h>
147 %include <lib/gui/ewidget.h>
148 %include <lib/gui/elabel.h>
149 %include <lib/gui/einput.h>
150 %include <lib/gui/einputstring.h>
151 %include <lib/gui/einputnumber.h>
152 %include <lib/gui/epixmap.h>
153 %include <lib/gui/ebutton.h>
154 %include <lib/gui/ewindow.h>
155 %include <lib/gui/eslider.h>
156 %include <lib/gui/ewidgetdesktop.h>
157 %include <lib/gui/elistbox.h>
158 %include <lib/gui/elistboxcontent.h>
159 %include <lib/gui/ewindowstyle.h>
160 %include <lib/gui/ewindowstyleskinned.h>
161 %include <lib/gui/ewidgetanimation.h>
162 %include <lib/service/listboxservice.h>
163 %include <lib/components/scan.h>
164 %include <lib/components/listboxepg.h>
165 %include <lib/nav/pcore.h>
166 %include <lib/actions/action.h>
167 %include <lib/gdi/gfont.h>
168 %include <lib/gdi/epng.h>
169 %include <lib/dvb/volume.h>
170 %include <lib/dvb/sec.h>
171 %include <lib/dvb/epgcache.h>
172 %include <lib/dvb/frontendparms.h>
173 %include <lib/dvb/dvbtime.h>
174 %include <lib/driver/avswitch.h>
175 %include <lib/driver/rfmod.h>
176 %include <lib/driver/etimezone.h>
177 %include <lib/gdi/lcd.h>
178 %include <lib/dvb_ci/dvbci_ui.h>
179 %include <lib/dvb/db.h>
180 /**************  eptr  **************/
181
182 %template(eActionMapPtr) ePtr<eActionMap>;
183
184 /**************  signals  **************/
185
186 template<class R> class PSignal0
187 {
188 public:
189         PyObject *get();
190 };
191
192 template<class R, class P0> class PSignal1
193 {
194 public:
195         PyObject *get();
196 };
197
198 template<class R, class P0, class P1> class PSignal2
199 {
200 public:
201         PyObject *get();
202 };
203
204 %template(PSignal1VI) PSignal1<void,int>;
205
206 %typemap(out) PSignal1VI {
207         $1 = $input->get();
208 }
209
210 %template(PSignal0V) PSignal0<void>;
211
212 %typemap(out) PSignal0V {
213         $1 = $input->get();
214 }
215
216 /**************  base  **************/
217
218 %immutable eTimer::timeout;
219
220 class eTimer
221 {
222 public:
223         eTimer(eMainloop *context = eApp);
224         PSignal0<void> timeout;
225
226         void start(long msec, bool singleShot=false);
227         void stop();
228         void changeInterval(long msek);
229 };
230
231 /**************  debug  **************/
232
233 void runMainloop();
234 void quitMainloop(int exit_code);
235 void setLCD(const char*);
236 void setLCDClock(const char*);
237 %immutable keyPressed;
238 PSignal1<void,int> &keyPressedSignal();
239
240 %{
241 RESULT SwigFromPython(ePtr<gPixmap> &result, PyObject *obj)
242 {       
243         ePtr<gPixmap> *res;
244
245         res = 0;
246         result = 0;
247         if (SWIG_Python_ConvertPtr(obj, (void **)&res, SWIGTYPE_p_ePtrTgPixmap_t, SWIG_POINTER_EXCEPTION | 0))
248                 return -1;
249         if (!res)
250                 return -1;
251         result = *res;
252         return 0;
253 }
254 %}