summaryrefslogtreecommitdiff
path: root/efl/ecore
diff options
context:
space:
mode:
authorDavide Andreoli <dave@gurumeditation.it>2013-02-11 22:32:50 +0000
committerDavide Andreoli <dave@gurumeditation.it>2013-02-11 22:32:50 +0000
commit8b8639886059814a36f57164d5572e97bcb00a47 (patch)
tree1c5a170de002793c1402d6afcc16c63115d81caa /efl/ecore
Put in a first, still wip, version of the python bindings in a merged tree.
This is meant to be the 1.8 version of the wrappers and will include everything that now is in the python folder. Atm this include evas, ecore, edje, elementary and emotion (emotion still commented in the build couse it need some more testing). Eo is used as a base for all the objects that inherit from it in C, but in real nothing is used from Eo, it is used more like a container to share code between the libs. All the docs has been stripped out because we want to use the new sphinx style docs that Kay has done in his git repo. (Kay: please wait a little bit to include it, as working on the libs without docs is much more easy) The new wrappers include a new container module called efl and thus you can live with both the old and the new installation. This also means that you need to import the new modules as: "from efl import evas" (instead of the old "import evas") The idea here is that you can make your code works with both version doing something like: try: import evas except: from efl import evas ...like is done in the gtk bindings Some stuff has been leaved out on purpose, because was old stuff (like the hacked evas rotation stuff) or because was not working as expected (like all the ecore.evas.XXX modules). See the TODO.txt file for more info. Probably some stuff is out just because I missed them, let me know if you miss something. Improvements from the old version: - Py3 compatible (still some work to be done, but really only TODO, no problems to resolv) - Should also works on other platforms, like windoz (but not tested) - Unittests greatly improved, you can also run ALL tests at once - much more simpler :) I will contine the works in the next weeks and hope someone will help too. NOTE: I switched back to setup.py instead of autotools, because that is the right way to compile python stuff. So to build just use: python setup.py install or python3 setup.py install Enjoy davemds SVN revision: 83831
Diffstat (limited to 'efl/ecore')
-rw-r--r--efl/ecore/efl.ecore.pyx141
-rw-r--r--efl/ecore/efl.ecore_animator.pxi57
-rw-r--r--efl/ecore/efl.ecore_events.pxi354
-rw-r--r--efl/ecore/efl.ecore_exe.pxi534
-rw-r--r--efl/ecore/efl.ecore_fd_handler.pxi164
-rw-r--r--efl/ecore/efl.ecore_file_download.pxi109
-rw-r--r--efl/ecore/efl.ecore_idler.pxi83
-rw-r--r--efl/ecore/efl.ecore_timer.pxi91
8 files changed, 1533 insertions, 0 deletions
diff --git a/efl/ecore/efl.ecore.pyx b/efl/ecore/efl.ecore.pyx
new file mode 100644
index 0000000..693dd8e
--- /dev/null
+++ b/efl/ecore/efl.ecore.pyx
@@ -0,0 +1,141 @@
1######################################################################
2# Copyright (C) 2007-2013 Gustavo Sverzut Barbieri
3#
4# This file is part of Python-Ecore.
5#
6# Python-Ecore is free software; you can redistribute it and/or
7# modify it under the terms of the GNU Lesser General Public
8# License as published by the Free Software Foundation; either
9# version 2.1 of the License, or (at your option) any later version.
10#
11# Python-Ecore is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14# Lesser General Public License for more details.
15#
16# You should have received a copy of the GNU Lesser General Public License
17# along with this Python-Ecore. If not, see <http://www.gnu.org/licenses/>.
18######################################################################
19
20import traceback
21from efl.eo cimport Eo
22from efl.eo cimport _fruni, _cfruni
23from efl.eo cimport PY_REFCOUNT
24from cpython cimport Py_INCREF, Py_DECREF
25
26
27ECORE_CALLBACK_CANCEL = 0
28ECORE_CALLBACK_RENEW = 1
29
30# Ecore_Fd_Handler_Flags:
31ECORE_FD_READ = 1
32ECORE_FD_WRITE = 2
33ECORE_FD_ERROR = 4
34ECORE_FD_ALL = 7
35
36
37# Ecore_Exe_Flags:
38ECORE_EXE_PIPE_READ = 1
39ECORE_EXE_PIPE_WRITE = 2
40ECORE_EXE_PIPE_ERROR = 4
41ECORE_EXE_PIPE_READ_LINE_BUFFERED = 8
42ECORE_EXE_PIPE_ERROR_LINE_BUFFERED = 16
43ECORE_EXE_PIPE_AUTO = 32
44ECORE_EXE_RESPAWN = 64
45ECORE_EXE_USE_SH = 128
46ECORE_EXE_NOT_LEADER = 256
47ECORE_EXE_TERM_WITH_PARENT = 512
48
49ECORE_EXE_PRIORITY_INHERIT = 9999
50
51
52# Ecore_File_Progress_Return:
53ECORE_FILE_PROGRESS_CONTINUE = 0
54ECORE_FILE_PROGRESS_ABORT = 1
55
56
57cdef Eina_Bool _ecore_task_cb(void *data) with gil:
58 cdef Eo obj = <Eo>data
59 cdef Eina_Bool ret
60
61 try:
62 ret = bool(obj._task_exec())
63 except Exception, e:
64 traceback.print_exc()
65 ret = 0
66
67 if not ret:
68 obj.delete()
69
70 return ret
71
72
73cdef int _ecore_events_registered = 0
74
75
76def init():
77 global _ecore_events_registered
78
79 r = ecore_init()
80
81 if r > 0 and _ecore_events_registered == 0:
82 _ecore_events_registered = 1
83
84 global _event_type_mapping
85 _event_type_mapping = {
86 ECORE_EVENT_SIGNAL_USER: EventSignalUser,
87 ECORE_EVENT_SIGNAL_HUP: EventSignalHup,
88 ECORE_EVENT_SIGNAL_EXIT: EventSignalExit,
89 ECORE_EVENT_SIGNAL_POWER: EventSignalPower,
90 ECORE_EVENT_SIGNAL_REALTIME: EventSignalRealtime,
91 ECORE_EXE_EVENT_ADD: EventExeAdd,
92 ECORE_EXE_EVENT_DEL: EventExeDel,
93 ECORE_EXE_EVENT_DATA: EventExeData,
94 ECORE_EXE_EVENT_ERROR: EventExeData,
95 }
96
97 ecore_file_init()
98 return r
99
100
101def shutdown():
102 ecore_file_shutdown()
103 return ecore_shutdown()
104
105
106def main_loop_quit():
107 ecore_main_loop_quit()
108
109
110def main_loop_begin():
111 with nogil:
112 ecore_main_loop_begin()
113
114
115def main_loop_iterate():
116 with nogil:
117 ecore_main_loop_iterate()
118
119
120def main_loop_glib_integrate():
121 if not ecore_main_loop_glib_integrate():
122 raise SystemError("failed to integrate GLib main loop into ecore.")
123
124
125def time_get():
126 return ecore_time_get()
127
128
129def loop_time_get():
130 return ecore_loop_time_get()
131
132
133include "efl.ecore_animator.pxi"
134include "efl.ecore_timer.pxi"
135include "efl.ecore_idler.pxi"
136include "efl.ecore_fd_handler.pxi"
137include "efl.ecore_events.pxi"
138include "efl.ecore_exe.pxi"
139include "efl.ecore_file_download.pxi"
140
141init()
diff --git a/efl/ecore/efl.ecore_animator.pxi b/efl/ecore/efl.ecore_animator.pxi
new file mode 100644
index 0000000..ee033ee
--- /dev/null
+++ b/efl/ecore/efl.ecore_animator.pxi
@@ -0,0 +1,57 @@
1# Copyright (C) 2007-2013 Gustavo Sverzut Barbieri, Ulisses Furquim
2#
3# This file is part of Python-Ecore.
4#
5# Python-Ecore is free software; you can redistribute it and/or
6# modify it under the terms of the GNU Lesser General Public
7# License as published by the Free Software Foundation; either
8# version 2.1 of the License, or (at your option) any later version.
9#
10# Python-Ecore is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# Lesser General Public License for more details.
14#
15# You should have received a copy of the GNU Lesser General Public License
16# along with this Python-Ecore. If not, see <http://www.gnu.org/licenses/>.
17
18# This file is included verbatim by efl.ecore.pyx
19
20
21cdef class Animator(Eo):
22 def __init__(self, func, *args, **kargs):
23 if not callable(func):
24 raise TypeError("Parameter 'func' must be callable")
25 self.func = func
26 self.args = args
27 self.kargs = kargs
28 self._set_obj(ecore_animator_add(_ecore_task_cb, <void *>self))
29
30 def __str__(self):
31 return "%s Animator(func=%s, args=%s, kargs=%s)" % (Eo.__repr__(self),
32 self.func, self.args, self.kargs)
33
34 def __repr__(self):
35 return "%s Animator(func=%s, args=%s, kargs=%s)" % (Eo.__repr__(self),
36 self.func, self.args, self.kargs)
37
38 cpdef object _task_exec(self):
39 return self.func(*self.args, **self.kargs)
40
41 def delete(self):
42 ecore_animator_del(self.obj)
43
44 def stop(self):
45 self.delete()
46
47
48def animator_add(func, *args, **kargs):
49 return Animator(func, *args, **kargs)
50
51
52def animator_frametime_set(double frametime):
53 ecore_animator_frametime_set(frametime)
54
55
56def animator_frametime_get():
57 return ecore_animator_frametime_get()
diff --git a/efl/ecore/efl.ecore_events.pxi b/efl/ecore/efl.ecore_events.pxi
new file mode 100644
index 0000000..b84ebab
--- /dev/null
+++ b/efl/ecore/efl.ecore_events.pxi
@@ -0,0 +1,354 @@
1# Copyright (C) 2007-2008 Gustavo Sverzut Barbieri
2#
3# This file is part of Python-Ecore.
4#
5# Python-Ecore is free software; you can redistribute it and/or
6# modify it under the terms of the GNU Lesser General Public
7# License as published by the Free Software Foundation; either
8# version 2.1 of the License, or (at your option) any later version.
9#
10# Python-Ecore is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# Lesser General Public License for more details.
14#
15# You should have received a copy of the GNU Lesser General Public License
16# along with this Python-Ecore. If not, see <http://www.gnu.org/licenses/>.
17
18# This file is included verbatim by c_ecore.pyx
19
20
21cdef object _event_type_mapping = dict()
22
23def _event_mapping_register(int type, cls):
24 if type in _event_type_mapping:
25 raise ValueError("event type '%d' already registered." % type)
26 if not issubclass(cls, Event):
27 raise TypeError("cls (%s) must be subclass of Event" % cls)
28 _event_type_mapping[type] = cls
29
30
31def _event_mapping_unregister(int type):
32 _event_type_mapping.pop(type)
33
34
35cdef Eina_Bool event_handler_cb(void *data, int type, void *event) with gil:
36 cdef EventHandler handler
37 cdef Eina_Bool r
38
39 assert event != NULL
40 assert data != NULL
41 handler = <EventHandler>data
42 assert type == handler.type
43
44 try:
45 r = handler._exec(event)
46 except Exception, e:
47 traceback.print_exc()
48 r = 0
49
50 if not r:
51 handler.delete()
52 return r
53
54
55cdef class Event(object):
56 def __init__(self):
57 if type(self) is Event:
58 raise TypeError("Must not instantiate Event, but subclasses")
59
60 def __str__(self):
61 attrs = []
62 for attr in dir(self):
63 if not attr.startswith("_"):
64 attrs.append("%s=%r" % (attr, getattr(self, attr)))
65 return "%s(%s)" % (self.__class__.__name__, ", ".join(attrs))
66
67 cdef int _set_obj(self, void *obj) except 0:
68 raise NotImplementedError("Event._set_obj() not implemented.")
69
70
71cdef class EventHandler(object):
72 def __init__(self, int type, func, *args, **kargs):
73 "@parm: B{type} event type, as registered with ecore_event_type_new()."
74 if not callable(func):
75 raise TypeError("Parameter 'func' must be callable")
76 event_cls = _event_type_mapping.get(type, None)
77 if event_cls is None:
78 raise ValueError("Unknow Ecore_Event type %d" % type)
79 self.type = type
80 self.event_cls = event_cls
81 self.func = func
82 self.args = args
83 self.kargs = kargs
84 self._set_obj(ecore_event_handler_add(type, event_handler_cb,
85 <void *>self))
86
87 def __str__(self):
88 return "%s(type=%d, func=%s, args=%s, kargs=%s, event_cls=%s)" % \
89 (self.__class__.__name__, self.type,
90 self.func, self.args, self.kargs, self.event_cls)
91
92 def __repr__(self):
93 return ("%s(%#x, type=%d, func=%s, args=%s, kargs=%s, event_cls=%s, "
94 "Ecore_Event_Handler=%#x, refcount=%d)") % \
95 (self.__class__.__name__, <unsigned long><void *>self,
96 self.type, self.func, self.args, self.kargs, self.event_cls,
97 <unsigned long>self.obj, PY_REFCOUNT(self))
98
99 def __dealloc__(self):
100 if self.obj != NULL:
101 ecore_event_handler_del(self.obj)
102
103 cdef int _set_obj(self, Ecore_Event_Handler *obj) except 0:
104 assert self.obj == NULL, "Object must be clean"
105 assert obj != NULL, "Cannot set NULL as object"
106 self.obj = obj
107 Py_INCREF(self)
108 return 1
109
110 cdef int _unset_obj(self) except 0:
111 if self.obj != NULL:
112 ecore_event_handler_del(self.obj)
113 self.obj = NULL
114 self.event_cls = None
115 self.func = None
116 self.args = None
117 self.kargs = None
118 Py_DECREF(self)
119 return 1
120
121 cdef Eina_Bool _exec(self, void *event) except 2:
122 cdef Event e
123 e = self.event_cls()
124 e._set_obj(event)
125 return bool(self.func(e, *self.args, **self.kargs))
126
127 def delete(self):
128 if self.obj != NULL:
129 self._unset_obj()
130
131 def stop(self):
132 self.delete()
133
134
135def event_handler_add(int type, func, *args, **kargs):
136 return EventHandler(type, func, *args, **kargs)
137
138
139cdef class EventSignalUser(Event):
140 cdef int _set_obj(self, void *o) except 0:
141 cdef Ecore_Event_Signal_User *obj
142 obj = <Ecore_Event_Signal_User*>o
143 self.number = obj.number
144 return 1
145
146 def __str__(self):
147 return "%s(number=%d)" % (self.__class__.__name__, self.number)
148
149 def __repr__(self):
150 return "%s(number=%d)" % (self.__class__.__name__, self.number)
151
152
153cdef class EventSignalUser1(EventSignalUser):
154 def __str__(self):
155 return "%s()" % (self.__class__.__name__,)
156
157 def __repr__(self):
158 return "%s()" % (self.__class__.__name__,)
159
160
161cdef class EventSignalUser2(EventSignalUser):
162 def __str__(self):
163 return "%s()" % (self.__class__.__name__,)
164
165 def __repr__(self):
166 return "%s()" % (self.__class__.__name__,)
167
168
169cdef class EventHandlerSignalUser(EventHandler):
170 def __init__(self, func, *args, **kargs):
171 EventHandler.__init__(self, ECORE_EVENT_SIGNAL_USER,
172 func, *args, **kargs)
173
174 cdef Eina_Bool _exec(self, void *event) except 2:
175 cdef Ecore_Event_Signal_User *obj = <Ecore_Event_Signal_User *>event
176 cdef EventSignalUser e
177 if obj.number == 1:
178 e = EventSignalUser1()
179 elif obj.number == 2:
180 e = EventSignalUser2()
181 else:
182 e = EventSignalUser()
183 e._set_obj(event)
184 return bool(self.func(e, *self.args, **self.kargs))
185
186
187def on_signal_user(func, *args, **kargs):
188 return EventHandlerSignalUser(func, *args, **kargs)
189
190
191cdef class EventSignalHup(Event):
192 cdef int _set_obj(self, void *o) except 0:
193 return 1
194
195 def __str__(self):
196 return "%s()" % (self.__class__.__name__,)
197
198 def __repr__(self):
199 return "%s()" % (self.__class__.__name__,)
200
201
202def on_signal_hup(func, *args, **kargs):
203 return EventHandler(ECORE_EVENT_SIGNAL_HUP, func, *args, **kargs)
204
205
206cdef class EventSignalExit(Event):
207 cdef int _set_obj(self, void *o) except 0:
208 cdef Ecore_Event_Signal_Exit *obj
209 obj = <Ecore_Event_Signal_Exit*>o
210 self.interrupt = bool(obj.interrupt)
211 self.quit = bool(obj.quit)
212 self.terminate = bool(obj.terminate)
213 return 1
214
215 def __str__(self):
216 return "%s(interrupt=%s, quit=%s, terminate=%s)" % \
217 (self.__class__.__name__, self.interrupt, self.quit, self.terminate)
218
219 def __repr__(self):
220 return "%s(interrupt=%s, quit=%s, terminate=%s)" % \
221 (self.__class__.__name__, self.interrupt, self.quit, self.terminate)
222
223
224cdef class EventSignalQuit(EventSignalExit):
225 def __str__(self):
226 return "%s()" % (self.__class__.__name__,)
227
228 def __repr__(self):
229 return "%s()" % (self.__class__.__name__,)
230
231
232cdef class EventSignalInterrupt(EventSignalExit):
233 def __str__(self):
234 return "%s()" % (self.__class__.__name__,)
235
236 def __repr__(self):
237 return "%s()" % (self.__class__.__name__,)
238
239
240cdef class EventSignalTerminate(EventSignalExit):
241 def __str__(self):
242 return "%s()" % (self.__class__.__name__,)
243
244 def __repr__(self):
245 return "%s()" % (self.__class__.__name__,)
246
247
248cdef class EventHandlerSignalExit(EventHandler):
249 def __init__(self, func, *args, **kargs):
250 EventHandler.__init__(self, ECORE_EVENT_SIGNAL_EXIT,
251 func, *args, **kargs)
252
253 cdef Eina_Bool _exec(self, void *event) except 2:
254 cdef Ecore_Event_Signal_Exit *obj = <Ecore_Event_Signal_Exit *>event
255 cdef EventSignalExit e
256 if obj.terminate:
257 e = EventSignalTerminate()
258 elif obj.interrupt:
259 e = EventSignalInterrupt()
260 elif obj.quit:
261 e = EventSignalQuit()
262 else:
263 e = EventSignalExit()
264 e._set_obj(event)
265 return bool(self.func(e, *self.args, **self.kargs))
266
267
268def on_signal_exit(func, *args, **kargs):
269 return EventHandlerSignalExit(func, *args, **kargs)
270
271
272cdef class EventSignalPower(Event):
273 cdef int _set_obj(self, void *o) except 0:
274 return 1
275
276 def __str__(self):
277 return "%s()" % (self.__class__.__name__,)
278
279 def __repr__(self):
280 return "%s()" % (self.__class__.__name__,)
281
282
283def on_signal_power(func, *args, **kargs):
284 return EventHandler(ECORE_EVENT_SIGNAL_POWER, func, *args, **kargs)
285
286
287cdef class EventSignalRealtime(Event):
288 cdef int _set_obj(self, void *o) except 0:
289 cdef Ecore_Event_Signal_Realtime *obj
290 obj = <Ecore_Event_Signal_Realtime*>o
291 self.num = obj.num
292 return 1
293
294 def __str__(self):
295 return "%s(num=%d)" % (self.__class__.__name__, self.num)
296
297 def __repr__(self):
298 return "%s(num=%d)" % (self.__class__.__name__, self.num)
299
300
301def on_signal_realtime(func, *args, **kargs):
302 return EventHandler(ECORE_EVENT_SIGNAL_REALTIME, func, *args, **kargs)
303
304
305cdef class CustomEvent(Event):
306 cdef int _set_obj(self, void *obj):
307 self.obj = <object>obj
308 return 1
309
310def event_type_new(cls):
311 cdef int type
312
313 type = ecore_event_type_new()
314
315 _event_mapping_register(type, cls)
316
317 return type
318
319
320cdef void _event_free_cb(void *data, void *event) with gil:
321 cdef QueuedEvent ev
322
323 ev = <QueuedEvent>data
324 ev._free()
325
326
327cdef class QueuedEvent(object):
328 def __init__(self, int type, *args):
329 self.args = args
330 self._set_obj(ecore_event_add(type, <void *>self.args, _event_free_cb,
331 <void*>self))
332
333 cdef int _set_obj(self, Ecore_Event *ev):
334 assert self.obj == NULL, "Object must be clean"
335 assert ev != NULL, "Cannot set NULL as object"
336 self.obj = ev
337 Py_INCREF(self)
338 return 1
339
340 cdef int _unset_obj(self):
341 if self.obj != NULL:
342 self.obj = NULL
343 self.args = None
344 Py_DECREF(self)
345 return 1
346
347 def _free(self):
348 self._unset_obj()
349
350 def delete(self):
351 ecore_event_del(self.obj)
352
353def event_add(int type, *args):
354 return QueuedEvent(type, args)
diff --git a/efl/ecore/efl.ecore_exe.pxi b/efl/ecore/efl.ecore_exe.pxi
new file mode 100644
index 0000000..a52a227
--- /dev/null
+++ b/efl/ecore/efl.ecore_exe.pxi
@@ -0,0 +1,534 @@
1# Copyright (C) 2010 Gustavo Sverzut Barbieri
2#
3# This file is part of Python-Ecore.
4#
5# Python-Ecore is free software; you can redistribute it and/or
6# modify it under the terms of the GNU Lesser General Public
7# License as published by the Free Software Foundation; either
8# version 2.1 of the License, or (at your option) any later version.
9#
10# Python-Ecore is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# Lesser General Public License for more details.
14#
15# You should have received a copy of the GNU Lesser General Public License
16# along with this Python-Ecore. If not, see <http://www.gnu.org/licenses/>.
17
18# This file is included verbatim by c_ecore.pyx
19
20
21# TODO: remove me after usage is update to new buffer api
22cdef extern from "Python.h":
23 int PyObject_AsReadBuffer(obj, void **buffer, Py_ssize_t *buffer_len) except -1
24 object PyUnicode_FromStringAndSize(char *s, Py_ssize_t len)
25
26
27cdef exe_flags2str(int value):
28 flags = []
29 if value & ECORE_EXE_PIPE_READ:
30 flags.append("PIPE_READ")
31 if value & ECORE_EXE_PIPE_WRITE:
32 flags.append("PIPE_WRITE")
33 if value & ECORE_EXE_PIPE_ERROR:
34 flags.append("PIPE_ERROR")
35 if value & ECORE_EXE_PIPE_READ_LINE_BUFFERED:
36 flags.append("PIPE_READ_LINE_BUFFERED")
37 if value & ECORE_EXE_PIPE_ERROR_LINE_BUFFERED:
38 flags.append("PIPE_ERROR_LINE_BUFFERED")
39 if value & ECORE_EXE_PIPE_AUTO:
40 flags.append("PIPE_AUTO")
41 if value & ECORE_EXE_RESPAWN:
42 flags.append("RESPAWN")
43 if value & ECORE_EXE_USE_SH:
44 flags.append("USE_SH")
45 if value & ECORE_EXE_NOT_LEADER:
46 flags.append("NOT_LEADER")
47 return ", ".join(flags)
48
49
50cdef Eina_Bool _exe_event_filter_cb(void *data, int type, void *event) with gil:
51 cdef ExeEventFilter self = <ExeEventFilter>data
52 cdef Ecore_Exe_Event_Add *e_add
53 cdef Ecore_Exe_Event_Del *e_del
54 cdef Ecore_Exe_Event_Data *e_data
55 cdef Event e
56
57 try:
58 assert self.event_type == type, "event is not what we asked? impossible"
59 if type == ECORE_EXE_EVENT_ADD:
60 e_add = <Ecore_Exe_Event_Add *>event
61 if e_add.exe != self.exe:
62 return 1
63 e = EventExeAdd()
64 elif type == ECORE_EXE_EVENT_DEL:
65 e_del = <Ecore_Exe_Event_Del *>event
66 if e_del.exe != self.exe:
67 return 1
68 e = EventExeDel()
69 elif type == ECORE_EXE_EVENT_DATA or type == ECORE_EXE_EVENT_ERROR:
70 e_data = <Ecore_Exe_Event_Data *>event
71 if e_data.exe != self.exe:
72 return 1
73 e = EventExeData()
74 else:
75 raise SystemError("unknown event type=%d" % type)
76
77 r = e._set_obj(event)
78 assert r != -1, "exe is not known?! impossible!"
79
80 cb = tuple(self.callbacks) # copy, so we can change self.callbacks
81 for func, args, kargs in cb:
82 try:
83 func(self.owner, e, *args, **kargs)
84 except:
85 traceback.print_exc()
86
87 except:
88 traceback.print_exc()
89
90 return 1 # always return true, no matter what
91
92
93cdef class ExeEventFilter:
94 def __cinit__(self, *a, **ka):
95 self.exe = NULL
96 self.handler = NULL
97 self.owner = None
98 self.event_type = -1
99 self.callbacks = []
100
101 def __dealloc__(self):
102 if self.handler != NULL:
103 ecore_event_handler_del(self.handler)
104 self.handler = NULL
105
106 self.exe = NULL
107 self.owner = None
108 self.event_type = None
109 self.callbacks = None
110
111 def __init__(self, Exe exe not None, int event_type):
112 self.exe = exe.exe
113 self.owner = exe
114 self.event_type = event_type
115 self.callbacks = []
116
117 def delete(self):
118 if self.handler != NULL:
119 ecore_event_handler_del(self.handler)
120 self.handler = NULL
121 self.callbacks = None
122
123 def callback_add(self, func, args, kargs):
124 if self.handler == NULL:
125 self.handler = ecore_event_handler_add(
126 self.event_type, _exe_event_filter_cb, <void *>self)
127 self.callbacks.append((func, args, kargs))
128
129 def callback_del(self, func, args, kargs):
130 try:
131 self.callbacks.remove((func, args, kargs))
132 except ValueError, e:
133 raise ValueError(
134 "callback is not registered: %s, args=%s, kargs=%s" %
135 (func, args, kargs))
136
137 if self.callbacks:
138 return
139
140 if self.handler != NULL:
141 ecore_event_handler_del(self.handler)
142 self.handler = NULL
143
144
145def exe_run_priority_set(int pri):
146 ecore_exe_run_priority_set(pri)
147
148
149def exe_run_priority_get():
150 return ecore_exe_run_priority_get()
151
152
153cdef object _ecore_exe_event_mapping
154_ecore_exe_event_mapping = {}
155
156
157cdef void _ecore_exe_pre_free_cb(void *data, const_Ecore_Exe *exe) with gil:
158 cdef Exe obj
159 try:
160 if data == NULL:
161 raise ValueError("data parameter is NULL")
162 else:
163 obj = <Exe>data
164 obj._unset_obj()
165 except Exception, e:
166 traceback.print_exc()
167
168
169cdef class Exe(object):
170 def __cinit__(self, *a, **ka):
171 self.exe = NULL
172 self.__data = None
173 self.__callbacks = {}
174
175 def __init__(self, exe_cmd, int flags=0, data=None):
176 if not exe_cmd:
177 raise ValueError("exe_cmd must not be empty!")
178
179 if flags is None:
180 flags = 0
181
182 self._set_obj(_fruni(exe_cmd), flags)
183 self.__data = data
184 self.__callbacks = {}
185
186 cdef int _set_obj(self, char *exe_cmd, int flags) except 0:
187 cdef Ecore_Exe *exe
188
189 assert self.exe == NULL, "Exe must be clean, not wrapping any Ecore_Exe"
190
191 exe = ecore_exe_pipe_run(exe_cmd, <Ecore_Exe_Flags>flags, <void *>self)
192 if exe == NULL:
193 raise SystemError("could not run subprocess %r, flags=%#x" %
194 (exe_cmd, flags))
195
196 Py_INCREF(self)
197 self.exe = exe
198 ecore_exe_callback_pre_free_set(exe, _ecore_exe_pre_free_cb)
199 _ecore_exe_event_mapping[<long><void *>exe] = self
200 return 1
201
202 cdef int _unset_obj(self) except 0:
203 assert self.exe != NULL, "Exe must wrap something"
204 for t, filter in self.__callbacks.iteritems():
205 filter.delete()
206 self.__callbacks = None
207
208 _ecore_exe_event_mapping.pop(<long><void *>self.exe)
209 self.exe = NULL
210 Py_DECREF(self)
211 return 1
212
213 def __str__(self):
214 if self.exe == NULL:
215 pid = None
216 cmd = None
217 flags = ""
218 data = None
219 else:
220 pid = self.pid
221 cmd = self.cmd
222 flags = exe_flags2str(self.flags)
223 data = None
224 return "%s(pid=%s, cmd=%r, flags=[%s], data=%r)" % \
225 (self.__class__.__name__, pid, cmd, flags, data)
226
227 def __repr__(self):
228 if self.exe == NULL:
229 pid = None
230 cmd = None
231 flags = ""
232 data = None
233 else:
234 pid = self.pid
235 cmd = self.cmd
236 flags = exe_flags2str(self.flags)
237 data = None
238 return ("%s(%#x, Ecore_Exe=%#x, refcount=%d, pid=%s, cmd=%r, "
239 "flags=[%s], data=%r)") % \
240 (self.__class__.__name__, <unsigned long><void *>self,
241 <unsigned long>self.exe, PY_REFCOUNT(self),
242 pid, cmd, flags, data)
243
244 def delete(self):
245 if self.exe == NULL:
246 raise ValueError("%s already deleted" % self.__class__.__name__)
247 ecore_exe_free(self.exe)
248
249 def free(self):
250 self.delete()
251
252 def send(self, buffer, long size=0):
253 cdef const_void *b_data
254 cdef Py_ssize_t b_size
255
256 # TODO: update to new buffer api
257 PyObject_AsReadBuffer(buffer, &b_data, &b_size)
258 if size <= 0:
259 size = b_size
260 elif size > b_size:
261 raise ValueError(
262 "given size (%d) is larger than buffer size (%d)." %
263 (size, b_size))
264
265 return bool(ecore_exe_send(self.exe, b_data, size))
266
267 def close_stdin(self):
268 ecore_exe_close_stdin(self.exe)
269
270 def auto_limits_set(self, int start_bytes, int end_bytes,
271 int start_lines, int end_lines):
272 ecore_exe_auto_limits_set(self.exe, start_bytes, end_bytes,
273 start_lines, end_lines)
274
275 def event_data_get(self, int flags):
276 pass
277 # TODO:
278 #Ecore_Exe_Event_Data *ecore_exe_event_data_get(Ecore_Exe *exe, Ecore_Exe_Flags flags)
279 #void ecore_exe_event_data_free(Ecore_Exe_Event_Data *data)
280
281 def cmd_get(self):
282 cdef const_char_ptr cmd = ecore_exe_cmd_get(self.exe)
283 if cmd != NULL:
284 return cmd
285 return None
286
287 property cmd:
288 def __get__(self):
289 return self.cmd_get()
290
291 def pid_get(self):
292 return ecore_exe_pid_get(self.exe)
293
294 property pid:
295 def __get__(self):
296 return self.pid_get()
297
298 def tag_set(self, char *tag):
299 cdef char *s
300 if tag is None:
301 s = NULL
302 else:
303 s = tag
304 ecore_exe_tag_set(self.exe, s)
305
306 def tag_get(self):
307 cdef const_char_ptr tag = ecore_exe_tag_get(self.exe)
308 if tag != NULL:
309 return tag
310 return None
311
312 property tag:
313 def __set__(self, char *tag):
314 self.tag_set(tag)
315
316 def __get__(self):
317 return self.tag_get()
318
319 def data_get(self):
320 return self.__data
321
322 property data:
323 def __get__(self):
324 return self.data_get()
325
326 def flags_get(self):
327 return ecore_exe_flags_get(self.exe)
328
329 property flags:
330 def __get__(self):
331 return self.flags_get()
332
333 def signal(self, int num):
334 if num != 1 or num != 2:
335 raise ValueError("num must be either 1 or 2. Got %d." % num)
336 ecore_exe_signal(self.exe, num)
337
338 def pause(self):
339 ecore_exe_pause(self.exe)
340
341 def stop(self):
342 self.pause()
343
344 def continue_(self):
345 ecore_exe_continue(self.exe)
346
347 def resume(self):
348 self.continue_()
349
350 def interrupt(self):
351 ecore_exe_interrupt(self.exe)
352
353 def quit(self):
354 ecore_exe_quit(self.exe)
355
356 def terminate(self):
357 ecore_exe_terminate(self.exe)
358
359 def kill(self):
360 ecore_exe_kill(self.exe)
361
362 def hup(self):
363 ecore_exe_hup(self.exe)
364
365 def on_add_event_add(self, func, *args, **kargs):
366 filter = self.__callbacks.get(ECORE_EXE_EVENT_ADD)
367 if filter is None:
368 filter = ExeEventFilter(self, ECORE_EXE_EVENT_ADD)
369 self.__callbacks[ECORE_EXE_EVENT_ADD] = filter
370 filter.callback_add(func, args, kargs)
371
372 def on_add_event_del(self, func, *args, **kargs):
373 filter = self.__callbacks.get(ECORE_EXE_EVENT_ADD)
374 if filter is None:
375 raise ValueError("callback not registered %s, args=%s, kargs=%s" %
376 (func, args, kargs))
377 filter.callback_del(func, args, kargs)
378
379 def on_del_event_add(self, func, *args, **kargs):
380 filter = self.__callbacks.get(ECORE_EXE_EVENT_DEL)
381 if filter is None:
382 filter = ExeEventFilter(self, ECORE_EXE_EVENT_DEL)
383 self.__callbacks[ECORE_EXE_EVENT_DEL] = filter
384 filter.callback_add(func, args, kargs)
385
386 def on_del_event_del(self, func, *args, **kargs):
387 filter = self.__callbacks.get(ECORE_EXE_EVENT_DEL)
388 if filter is None:
389 raise ValueError("callback not registered %s, args=%s, kargs=%s" %
390 (func, args, kargs))
391 filter.callback_del(func, args, kargs)
392
393 def on_data_event_add(self, func, *args, **kargs):
394 filter = self.__callbacks.get(ECORE_EXE_EVENT_DATA)
395 if filter is None:
396 filter = ExeEventFilter(self, ECORE_EXE_EVENT_DATA)
397 self.__callbacks[ECORE_EXE_EVENT_DATA] = filter
398 filter.callback_add(func, args, kargs)
399
400 def on_data_event_del(self, func, *args, **kargs):
401 filter = self.__callbacks.get(ECORE_EXE_EVENT_DATA)
402 if filter is None:
403 raise ValueError("callback not registered %s, args=%s, kargs=%s" %
404 (func, args, kargs))
405 filter.callback_del(func, args, kargs)
406
407 def on_error_event_add(self, func, *args, **kargs):
408 filter = self.__callbacks.get(ECORE_EXE_EVENT_ERROR)
409 if filter is None:
410 filter = ExeEventFilter(self, ECORE_EXE_EVENT_ERROR)
411 self.__callbacks[ECORE_EXE_EVENT_ERROR] = filter
412 filter.callback_add(func, args, kargs)
413
414 def on_error_event_del(self, func, *args, **kargs):
415 filter = self.__callbacks.get(ECORE_EXE_EVENT_ERROR)
416 if filter is None:
417 raise ValueError("callback not registered %s, args=%s, kargs=%s" %
418 (func, args, kargs))
419 filter.callback_del(func, args, kargs)
420
421
422def exe_run(char *exe_cmd, data=None):
423 return Exe(exe_cmd, data=data)
424
425
426def exe_pipe_run(char *exe_cmd, int flags=0, data=None):
427 return Exe(exe_cmd, flags, data)
428
429
430cdef class EventExeAdd(Event):
431 cdef int _set_obj(self, void *o) except 0:
432 cdef Ecore_Exe_Event_Add *obj
433 obj = <Ecore_Exe_Event_Add*>o
434 self.exe = _ecore_exe_event_mapping.get(<long>obj.exe)
435 if self.exe is None:
436 return -1
437 return 1
438
439 def __str__(self):
440 return "%s(exe=%s)" % (self.__class__.__name__, self.exe)
441
442 def __repr__(self):
443 return "%s(exe=%r)" % (self.__class__.__name__, self.exe)
444
445
446cdef class EventExeDel(Event):
447 cdef int _set_obj(self, void *o) except 0:
448 cdef Ecore_Exe_Event_Del *obj
449 obj = <Ecore_Exe_Event_Del*>o
450 self.exe = _ecore_exe_event_mapping.get(<long>obj.exe)
451 if self.exe is None:
452 return -1
453 self.pid = obj.pid
454 self.exit_code = obj.exit_code
455 self.exit_signal = obj.exit_signal
456 self.exited = bool(obj.exited)
457 self.signalled = bool(obj.signalled)
458 return 1
459
460 def __str__(self):
461 return ("%s(pid=%s, exit_code=%s, exit_signal=%s, exited=%s, "
462 "signalled=%s, exe=%s)") % \
463 (self.__class__.__name__, self.pid, self.exit_code,
464 self.exit_signal, self.exited, self.signalled, self.exe)
465
466 def __repr__(self):
467 return ("%s(pid=%s, exit_code=%s, exit_signal=%s, exited=%s, "
468 "signalled=%s, exe=%r)") % \
469 (self.__class__.__name__, self.pid, self.exit_code,
470 self.exit_signal, self.exited, self.signalled, self.exe)
471
472
473cdef class EventExeData(Event):
474 cdef int _set_obj(self, void *o) except 0:
475 cdef Ecore_Exe_Event_Data *obj
476 cdef int i
477 obj = <Ecore_Exe_Event_Data*>o
478 self.exe = _ecore_exe_event_mapping.get(<long>obj.exe)
479 if self.exe is None:
480 return -1
481 self.data = PyUnicode_FromStringAndSize(<char*>obj.data, obj.size)
482 self.size = obj.size
483 self.lines = []
484
485 line_append = self.lines.append
486 if obj.lines:
487 i = 0
488 while obj.lines[i].line != NULL:
489 line_append(PyUnicode_FromStringAndSize(
490 obj.lines[i].line, obj.lines[i].size))
491 i += 1
492
493 return 1
494
495 def __str__(self):
496 if self.lines is None:
497 count = None
498 else:
499 count = len(self.lines)
500 return "%s(size=%d, lines=#%d, exe=%s)" % \
501 (self.__class__.__name__, self.size, count, self.exe)
502
503 def __repr__(self):
504 if self.lines is None:
505 count = None
506 else:
507 count = len(self.lines)
508 return "%s(size=%d, lines=#%d, exe=%r)" % \
509 (self.__class__.__name__, self.size, count, self.exe)
510
511
512cdef class EventHandlerExe(EventHandler):
513 cdef Eina_Bool _exec(self, void *event) except 2:
514 cdef Event e
515 e = self.event_cls()
516 if e._set_obj(event) == -1: # no exe
517 return True
518 return bool(self.func(e, *self.args, **self.kargs))
519
520
521def on_exe_add_event_add(func, *args, **kargs):
522 return EventHandlerExe(ECORE_EXE_EVENT_ADD, func, *args, **kargs)
523
524
525def on_exe_del_event_add(func, *args, **kargs):
526 return EventHandlerExe(ECORE_EXE_EVENT_DEL, func, *args, **kargs)
527
528
529def on_exe_data_event_add(func, *args, **kargs):
530 return EventHandlerExe(ECORE_EXE_EVENT_DATA, func, *args, **kargs)
531
532
533def on_exe_error_event_add(func, *args, **kargs):
534 return EventHandlerExe(ECORE_EXE_EVENT_ERROR, func, *args, **kargs)
diff --git a/efl/ecore/efl.ecore_fd_handler.pxi b/efl/ecore/efl.ecore_fd_handler.pxi
new file mode 100644
index 0000000..d60b8a8
--- /dev/null
+++ b/efl/ecore/efl.ecore_fd_handler.pxi
@@ -0,0 +1,164 @@
1# Copyright (C) 2007-2008 Gustavo Sverzut Barbieri, Ulisses Furquim
2#
3# This file is part of Python-Ecore.
4#
5# Python-Ecore is free software; you can redistribute it and/or
6# modify it under the terms of the GNU Lesser General Public
7# License as published by the Free Software Foundation; either
8# version 2.1 of the License, or (at your option) any later version.
9#
10# Python-Ecore is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# Lesser General Public License for more details.
14#
15# You should have received a copy of the GNU Lesser General Public License
16# along with this Python-Ecore. If not, see <http://www.gnu.org/licenses/>.
17
18# This file is included verbatim by c_ecore.pyx
19
20
21cdef void fd_handler_prepare_cb(void *data, Ecore_Fd_Handler *fdh) with gil:
22 cdef FdHandler obj = <FdHandler>data
23 cdef int r
24
25 if obj._prepare_callback is None:
26 return
27 func, args, kargs = obj._prepare_callback
28 try:
29 func(obj, *args, **kargs)
30 except Exception, e:
31 traceback.print_exc()
32
33
34cdef flags2str(int value):
35 flags = []
36 if value & <int>ECORE_FD_READ:
37 flags.append("READ")
38 if value & <int>ECORE_FD_WRITE:
39 flags.append("WRITE")
40 if value & <int>ECORE_FD_ERROR:
41 flags.append("ERROR")
42 return ", ".join(flags)
43
44
45cdef Eina_Bool fd_handler_cb(void *data, Ecore_Fd_Handler *fdh) with gil:
46 cdef FdHandler obj = <FdHandler>data
47 cdef Eina_Bool r
48
49 try:
50 r = bool(obj._exec())
51 except Exception, e:
52 traceback.print_exc()
53 r = 0
54
55 if not r:
56 obj.delete()
57 return r
58
59
60cdef class FdHandler(object):
61 def __init__(self, fd, int flags, func, *args, **kargs):
62 if not callable(func):
63 raise TypeError("Parameter 'func' must be callable")
64 self.func = func
65 self.args = args
66 self.kargs = kargs
67 self._prepare_callback = None
68 if self.obj == NULL:
69 if not isinstance(fd, (int, long)):
70 try:
71 fd = fd.fileno()
72 except AttributeError, e:
73 raise ValueError("fd must be integer or have fileno()")
74
75 self.obj = ecore_main_fd_handler_add(fd,
76 <Ecore_Fd_Handler_Flags>flags,
77 fd_handler_cb, <void *>self,
78 NULL, NULL)
79 if self.obj != NULL:
80 Py_INCREF(self)
81
82 def __str__(self):
83 if self.obj == NULL:
84 fd = None
85 flags = ""
86 else:
87 fd = self.fd_get()
88 flags = flags2str(self.active_get(7))
89 return "%s(func=%s, args=%s, kargs=%s, fd=%s, flags=[%s])" % \
90 (self.__class__.__name__, self.func, self.args, self.kargs,
91 fd, flags)
92
93 def __repr__(self):
94 if self.obj == NULL:
95 fd = None
96 flags = ""
97 else:
98 fd = self.fd_get()
99 flags = flags2str(self.active_get(7))
100 return ("%s(%#x, func=%s, args=%s, kargs=%s, fd=%s, flags=[%s], "
101 "Ecore_Fd_Handler=%#x, refcount=%d)") % \
102 (self.__class__.__name__, <unsigned long><void *>self,
103 self.func, self.args, self.kargs, fd, flags,
104 <unsigned long>self.obj, PY_REFCOUNT(self))
105
106 def __dealloc__(self):
107 if self.obj != NULL:
108 ecore_main_fd_handler_del(self.obj)
109 self.obj = NULL
110 self.func = None
111 self.args = None
112 self.kargs = None
113
114 cdef object _exec(self):
115 return self.func(self, *self.args, **self.kargs)
116
117 def delete(self):
118 if self.obj != NULL:
119 ecore_main_fd_handler_del(self.obj)
120 self.obj = NULL
121 Py_DECREF(self)
122
123 def stop(self):
124 self.delete()
125
126 def fd_get(self):
127 return ecore_main_fd_handler_fd_get(self.obj)
128
129 property fd:
130 def __get__(self):
131 return self.fd_get()
132
133 def active_get(self, int flags):
134 cdef Ecore_Fd_Handler_Flags v = <Ecore_Fd_Handler_Flags>flags
135 return bool(ecore_main_fd_handler_active_get(self.obj, v))
136
137 def active_set(self, int flags):
138 cdef Ecore_Fd_Handler_Flags v = <Ecore_Fd_Handler_Flags>flags
139 ecore_main_fd_handler_active_set(self.obj, v)
140
141 def can_read(self):
142 return bool(ecore_main_fd_handler_active_get(self.obj, ECORE_FD_READ))
143
144 def can_write(self):
145 return bool(ecore_main_fd_handler_active_get(self.obj, ECORE_FD_WRITE))
146
147 def has_error(self):
148 return bool(ecore_main_fd_handler_active_get(self.obj, ECORE_FD_ERROR))
149
150 def prepare_callback_set(self, func, *args, **kargs):
151 if func is None:
152 self._prepare_callback = None
153 ecore_main_fd_handler_prepare_callback_set(self.obj, NULL, NULL)
154 elif callable(func):
155 self._prepare_callback = (func, args, kargs)
156 ecore_main_fd_handler_prepare_callback_set(self.obj,
157 fd_handler_prepare_cb,
158 <void *>self)
159 else:
160 raise TypeError("Parameter 'func' must be callable")
161
162
163def fd_handler_add(fd, int flags, func, *args, **kargs):
164 return FdHandler(fd, flags, func, *args, **kargs)
diff --git a/efl/ecore/efl.ecore_file_download.pxi b/efl/ecore/efl.ecore_file_download.pxi
new file mode 100644
index 0000000..aa8219d
--- /dev/null
+++ b/efl/ecore/efl.ecore_file_download.pxi
@@ -0,0 +1,109 @@
1# Copyright (C) 2007-2008 Gustavo Sverzut Barbieri
2#
3# This file is part of Python-Ecore.
4#
5# Python-Ecore is free software; you can redistribute it and/or
6# modify it under the terms of the GNU Lesser General Public
7# License as published by the Free Software Foundation; either
8# version 2.1 of the License, or (at your option) any later version.
9#
10# Python-Ecore is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# Lesser General Public License for more details.
14#
15# You should have received a copy of the GNU Lesser General Public License
16# along with this Python-Ecore. If not, see <http://www.gnu.org/licenses/>.
17
18# This file is included verbatim by c_ecore_file.pyx
19
20
21cdef void _completion_cb(void *data, const_char_ptr file, int status) with gil:
22 obj = <FileDownload>data
23 try:
24 obj._exec_completion(file, status)
25 except Exception, e:
26 traceback.print_exc()
27
28cdef int _progress_cb(void *data, const_char_ptr file, long int dltotal,
29 long int dlnow, long int ultotal, long int ulnow) with gil:
30 obj = <FileDownload>data
31 try:
32 return obj._exec_progress(file, dltotal, dlnow, ultotal, ulnow)
33 except Exception, e:
34 traceback.print_exc()
35
36
37cdef class FileDownload(object):
38 def __init__(self, url, dst, completion_cb, progress_cb, *args, **kargs):
39 cdef Ecore_File_Download_Job *job
40
41 if completion_cb is not None and not callable(completion_cb):
42 raise TypeError("Parameter 'completion_cb' must be callable, or None")
43
44 if progress_cb is not None and not callable(progress_cb):
45 raise TypeError("Parameter 'progress_cb' must be callable, or None")
46
47 self.completion_cb = completion_cb
48 self.progress_cb = progress_cb
49 self.args = args
50 self.kargs = kargs
51
52 if not ecore_file_download(_cfruni(url), _cfruni(dst),
53 _completion_cb, _progress_cb,
54 <void *>self, &job):
55 raise SystemError("could not download '%s' to %s" % (url, dst))
56
57 self.job = job
58 Py_INCREF(self)
59
60 def __str__(self):
61 return "%s(completion_cb=%s, progress_cb=%s args=%s, kargs=%s)" % \
62 (self.__class__.__name__, self.completion_cb,
63 self.progress_cb, self.args, self.kargs)
64
65 def __repr__(self):
66 return ("%s(%#x, completion_cb=%s, progress_cb=%s, args=%s, kargs=%s, "
67 "Ecore_File_Download_Job=%#x, refcount=%d)") % \
68 (self.__class__.__name__, <unsigned long><void *>self,
69 self.completion_cb, self.progress_cb, self.args, self.kargs,
70 <unsigned long>self.job, PY_REFCOUNT(self))
71
72 def __dealloc__(self):
73 if self.job != NULL:
74 ecore_file_download_abort(self.job)
75 self.job = NULL
76 self.completion_cb = None
77 self.progress_cb = None
78 self.args = None
79 self.kargs = None
80
81 cdef object _exec_completion(self, const_char_ptr file, int status):
82 if self.completion_cb:
83 self.completion_cb(file, status, *self.args, **self.kargs)
84
85 cdef object _exec_progress(self, const_char_ptr file, long int dltotal,
86 long int dlnow, long int ultotal, long int ulnow):
87 if self.progress_cb:
88 return self.progress_cb(file, dltotal, dlnow, ultotal, ulnow,
89 *self.args, **self.kargs)
90 return 0
91
92 def abort(self):
93 if self.job != NULL:
94 ecore_file_download_abort(self.job)
95 self.job = NULL
96 Py_DECREF(self)
97
98
99def file_download(url, dst, completion_cb, progress_cb, *args, **kargs):
100 return FileDownload(url, dst, completion_cb, progress_cb, *args, **kargs)
101
102def file_download_abort(instance):
103 instance.abort()
104
105def file_download_abort_all():
106 ecore_file_download_abort_all()
107
108def file_download_protocol_available(protocol):
109 return bool(ecore_file_download_protocol_available(protocol))
diff --git a/efl/ecore/efl.ecore_idler.pxi b/efl/ecore/efl.ecore_idler.pxi
new file mode 100644
index 0000000..a8a4159
--- /dev/null
+++ b/efl/ecore/efl.ecore_idler.pxi
@@ -0,0 +1,83 @@
1# Copyright (C) 2007-2013 Gustavo Sverzut Barbieri, Ulisses Furquim
2#
3# This file is part of Python-Ecore.
4#
5# Python-Ecore is free software; you can redistribute it and/or
6# modify it under the terms of the GNU Lesser General Public
7# License as published by the Free Software Foundation; either
8# version 2.1 of the License, or (at your option) any later version.
9#
10# Python-Ecore is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# Lesser General Public License for more details.
14#
15# You should have received a copy of the GNU Lesser General Public License
16# along with this Python-Ecore. If not, see <http://www.gnu.org/licenses/>.
17
18# This file is included verbatim by efl.ecore.pyx
19
20
21cdef class Idler(Eo):
22 def __init__(self, func, *args, **kargs):
23 if not callable(func):
24 raise TypeError("Parameter 'func' must be callable")
25 self.func = func
26 self.args = args
27 self.kargs = kargs
28 self._set_obj(ecore_idler_add(_ecore_task_cb, <void *>self))
29
30 def __str__(self):
31 return "%s Idler(func=%s, args=%s, kargs=%s)" % (Eo.__repr__(self),
32 self.func, self.args, self.kargs)
33
34 def __repr__(self):
35 return "%s Idler(func=%s, args=%s, kargs=%s)" % (Eo.__repr__(self),
36 self.func, self.args, self.kargs)
37
38 cpdef object _task_exec(self):
39 return self.func(*self.args, **self.kargs)
40
41 def delete(self):
42 ecore_idler_del(self.obj)
43
44 def stop(self):
45 self.delete()
46
47
48cdef class IdleEnterer(Idler):
49 def __init__(self, func, *args, **kargs):
50 if not callable(func):
51 raise TypeError("Parameter 'func' must be callable")
52 self.func = func
53 self.args = args
54 self.kargs = kargs
55 self._set_obj(ecore_idle_enterer_add(_ecore_task_cb, <void *>self))
56
57 def delete(self):
58 ecore_idle_enterer_del(self.obj)
59
60
61cdef class IdleExiter(Idler):
62 def __init__(self, func, *args, **kargs):
63 if not callable(func):
64 raise TypeError("Parameter 'func' must be callable")
65 self.func = func
66 self.args = args
67 self.kargs = kargs
68 self._set_obj(ecore_idle_exiter_add(_ecore_task_cb, <void *>self))
69
70 def delete(self):
71 ecore_idle_exiter_del(self.obj)
72
73
74def idler_add(func, *args, **kargs):
75 return Idler(func, *args, **kargs)
76
77
78def idle_enterer_add(func, *args, **kargs):
79 return IdleEnterer(func, *args, **kargs)
80
81
82def idle_exiter_add(func, *args, **kargs):
83 return IdleExiter(func, *args, **kargs)
diff --git a/efl/ecore/efl.ecore_timer.pxi b/efl/ecore/efl.ecore_timer.pxi
new file mode 100644
index 0000000..5c2b701
--- /dev/null
+++ b/efl/ecore/efl.ecore_timer.pxi
@@ -0,0 +1,91 @@
1# Copyright (C) 2007-2013 Gustavo Sverzut Barbieri, Ulisses Furquim
2#
3# This file is part of Python-Ecore.
4#
5# Python-Ecore is free software; you can redistribute it and/or
6# modify it under the terms of the GNU Lesser General Public
7# License as published by the Free Software Foundation; either
8# version 2.1 of the License, or (at your option) any later version.
9#
10# Python-Ecore is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# Lesser General Public License for more details.
14#
15# You should have received a copy of the GNU Lesser General Public License
16# along with this Python-Ecore. If not, see <http://www.gnu.org/licenses/>.
17
18# This file is included verbatim by efl.ecore.pyx
19
20
21cdef class Timer(Eo):
22 def __init__(self, double interval, func, *args, **kargs):
23 if not callable(func):
24 raise TypeError("Parameter 'func' must be callable")
25 self.func = func
26 self.args = args
27 self.kargs = kargs
28 self._set_obj(ecore_timer_add(interval, _ecore_task_cb, <void *>self))
29
30 def __str__(self):
31 return "%s Timer(func=%s, args=%s, kargs=%s)" % (Eo.__str__(self),
32 self.func, self.args, self.kargs)
33
34 def __repr__(self):
35 return "%s Timer(interval=%f, func=%s, args=%s, kargs=%s)" % (Eo.__repr__(self),
36 self.interval if self.obj else -1.0,
37 self.func, self.args, self.kargs)
38
39 cpdef object _task_exec(self):
40 return self.func(*self.args, **self.kargs)
41
42 def delete(self):
43 ecore_timer_del(self.obj)
44
45 def stop(self):
46 self.delete()
47
48 def freeze(self):
49 ecore_timer_freeze(self.obj)
50
51 def thaw(self):
52 ecore_timer_thaw(self.obj)
53
54 def interval_set(self, double t):
55 ecore_timer_interval_set(self.obj, t)
56
57 def interval_get(self):
58 return ecore_timer_interval_get(self.obj)
59
60 property interval:
61 def __get__(self):
62 return ecore_timer_interval_get(self.obj)
63
64 def __set__(self, double t):
65 ecore_timer_interval_set(self.obj, t)
66
67 def delay(self, double add):
68 ecore_timer_delay(self.obj, add)
69
70 def reset(self):
71 ecore_timer_reset(self.obj)
72
73 def ecore_timer_pending_get(self):
74 ecore_timer_pending_get(self.obj)
75
76 property pending:
77 def __get__(self):
78 return ecore_timer_pending_get(self.obj)
79
80
81def timer_add(double t, func, *args, **kargs):
82 return Timer(t, func, *args, **kargs)
83
84
85def timer_precision_get():
86 return ecore_timer_precision_get()
87
88
89def timer_precision_set(double value):
90 ecore_timer_precision_set(value)
91