summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2014-04-11 18:12:49 +0300
committerKai Huuhko <kai.huuhko@gmail.com>2014-04-11 18:12:49 +0300
commit6ebdf2b607491594c44deb6599861a35ff633667 (patch)
tree630f5e17abcb0f485cabd670eb295799b549e7b3
parent8cc17b5777ab7de3781a83b7c40f6e51da976fe8 (diff)
Bring back Python bindings for Ethumb.
-rw-r--r--TODO5
-rw-r--r--doc/ethumb/class-ethumb.rst13
-rw-r--r--doc/ethumb/ethumb.rst30
-rw-r--r--doc/index.rst6
-rw-r--r--efl/ethumb/__init__.py30
-rw-r--r--efl/ethumb/efl.ethumb.pyx30
-rw-r--r--efl/ethumb/efl.ethumb_client.pyx655
-rw-r--r--include/efl.ethumb.enums.pxd26
-rw-r--r--include/efl.ethumb.pxd106
-rw-r--r--include/efl.ethumb_client.pxd96
-rwxr-xr-xsetup.py18
11 files changed, 1012 insertions, 3 deletions
diff --git a/TODO b/TODO
index 668f3da..87df368 100644
--- a/TODO
+++ b/TODO
@@ -25,9 +25,7 @@ TODO
25* Review the internal functions and name them consistently 25* Review the internal functions and name them consistently
26* Evas: SmartObject needs testing, work. Make it inheritable by extension 26* Evas: SmartObject needs testing, work. Make it inheritable by extension
27 classes? 27 classes?
28* Elm unit tests, things like top_widget and getting child objects 28* Improve ethumb
29 can be done easily.
30* include python-ethumb
31* edje: complete the unit tests 29* edje: complete the unit tests
32* Initial Evas GL support (for Elm) 30* Initial Evas GL support (for Elm)
33* Add more documentation for callbacks, events, etc. 31* Add more documentation for callbacks, events, etc.
@@ -40,6 +38,7 @@ Elm
40* Add more examples 38* Add more examples
41* Prefs 39* Prefs
42* GLView 40* GLView
41* Unit tests
43* Images missing in the documentation: 42* Images missing in the documentation:
44 - datetime 43 - datetime
45 - video 44 - video
diff --git a/doc/ethumb/class-ethumb.rst b/doc/ethumb/class-ethumb.rst
new file mode 100644
index 0000000..593d585
--- /dev/null
+++ b/doc/ethumb/class-ethumb.rst
@@ -0,0 +1,13 @@
1.. currentmodule:: efl.ethumb
2
3:class:`efl.ethumb.PyEthumb` Class
4==================================
5
6.. autoclass:: efl.ethumb.PyEthumb
7
8.. currentmodule:: efl.ethumb
9
10:class:`efl.ethumb_client.Client` Class
11========================================
12
13.. autoclass:: efl.ethumb_client.Client
diff --git a/doc/ethumb/ethumb.rst b/doc/ethumb/ethumb.rst
new file mode 100644
index 0000000..d9f923a
--- /dev/null
+++ b/doc/ethumb/ethumb.rst
@@ -0,0 +1,30 @@
1:mod:`efl.ethumb` Module
2============================
3
4.. module:: efl.ethumb
5
6What is Ethumb?
7----------------
8
9
10How to use the Ethumb object
11-----------------------------
12
13
14Reference
15---------
16
17.. toctree::
18 :maxdepth: 4
19
20 class-ethumb
21
22
23Inheritance diagram
24-------------------
25
26.. inheritance-diagram::
27 efl.ethumb
28 efl.ethumb_client
29 :parts: 2
30
diff --git a/doc/index.rst b/doc/index.rst
index 2e56615..ac42901 100644
--- a/doc/index.rst
+++ b/doc/index.rst
@@ -54,6 +54,12 @@ Evas
54.. toctree:: evas/evas 54.. toctree:: evas/evas
55 55
56 56
57Ethumb
58------
59
60.. toctree:: ethumb/ethumb
61
62
57Edje 63Edje
58---- 64----
59 65
diff --git a/efl/ethumb/__init__.py b/efl/ethumb/__init__.py
new file mode 100644
index 0000000..d8d3e48
--- /dev/null
+++ b/efl/ethumb/__init__.py
@@ -0,0 +1,30 @@
1# Copyright (C) 2009 by ProFUSION embedded systems
2#
3# This file is part of Python-Ethumb.
4#
5# Python-Ethumb 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-Ethumb 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-Ethumb. If not, see <http://www.gnu.org/licenses/>.
17
18from c_ethumb import init, shutdown, PyEthumb
19
20ETHUMB_THUMB_NORMAL = 0
21ETHUMB_THUMB_LARGE = 1
22
23ETHUMB_THUMB_FDO = 0
24ETHUMB_THUMB_JPEG = 1
25ETHUMB_THUMB_EET = 2
26
27ETHUMB_THUMB_KEEP_ASPECT = 0
28ETHUMB_THUMB_IGNORE_ASPECT = 1
29ETHUMB_THUMB_CROP = 2
30
diff --git a/efl/ethumb/efl.ethumb.pyx b/efl/ethumb/efl.ethumb.pyx
new file mode 100644
index 0000000..80db58a
--- /dev/null
+++ b/efl/ethumb/efl.ethumb.pyx
@@ -0,0 +1,30 @@
1# Copyright (C) 2009 by ProFUSION embedded systems
2#
3# This file is part of Python-Ethumb.
4#
5# Python-Ethumb 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-Ethumb 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-Ethumb. If not, see <http://www.gnu.org/licenses/>.
17
18def init():
19 return ethumb_init()
20
21def shutdown():
22 ethumb_shutdown()
23
24cdef class PyEthumb:
25 """Ethumb thumbnail generator"""
26 def __init__(self):
27 """Ethumb constructor."""
28
29
30init()
diff --git a/efl/ethumb/efl.ethumb_client.pyx b/efl/ethumb/efl.ethumb_client.pyx
new file mode 100644
index 0000000..7666250
--- /dev/null
+++ b/efl/ethumb/efl.ethumb_client.pyx
@@ -0,0 +1,655 @@
1# Copyright (C) 2009 by ProFUSION embedded systems
2#
3# This file is part of Python-Ethumb.
4#
5# Python-Ethumb 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-Ethumb 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-Ethumb. If not, see <http://www.gnu.org/licenses/>.
17
18from cpython cimport Py_INCREF, Py_DECREF
19from libc.stdint cimport uintptr_t
20import traceback
21
22def shutdown():
23 ethumb_client_shutdown()
24
25def init():
26 return ethumb_client_init()
27
28cdef void _connect_cb(void *data, Ethumb_Client *client, Eina_Bool success) with gil:
29 cdef Client self = <Client>data
30 s = bool(success)
31 try:
32 func, args, kargs = self._on_connect_callback
33 func(self, s, *args, **kargs)
34 except Exception, e:
35 traceback.print_exc()
36
37 if not s and self.obj != NULL:
38 ethumb_client_disconnect(self.obj)
39 self.obj = NULL
40 self._on_connect_callback = None
41
42
43cdef void _on_server_die_cb(void *data, Ethumb_Client *client) with gil:
44 cdef Client self = <Client>data
45 if self._on_server_die_callback is not None:
46 try:
47 func, args, kargs = self._on_server_die_callback
48 func(self, *args, **kargs)
49 except Exception, e:
50 traceback.print_exc()
51
52 if self.obj != NULL:
53 ethumb_client_disconnect(self.obj)
54 self.obj = NULL
55 self._on_server_die_callback = None
56
57
58cdef void _generated_cb(void *data, Ethumb_Client *client, int id, const char *file, const char *key, const char *thumb_path, const char *thumb_key, Eina_Bool success) with gil:
59 obj = <object>data
60 (self, func, args, kargs) = obj
61 f = str_from_c(file)
62 k = str_from_c(key)
63 tp = str_from_c(thumb_path)
64 tk = str_from_c(thumb_key)
65 s = bool(success != 0)
66 try:
67 func(self, id, f, k, tp, tk, s, *args, **kargs)
68 except Exception, e:
69 traceback.print_exc()
70
71cdef void _generated_cb_free_data(void *data) with gil:
72 obj = <object>data
73 Py_DECREF(obj)
74
75cdef void _thumb_exists_cb(void *data, Ethumb_Client *client, Ethumb_Exists *thread, Eina_Bool exists) with gil:
76 #TODO
77 print("Not implemented")
78 #pass
79
80cdef char *str_to_c(object s):
81 cdef char *mystr
82 if s is None:
83 mystr = NULL
84 else:
85 mystr = s
86 return mystr
87
88cdef object str_from_c(const char *mystr):
89 if mystr != NULL:
90 return mystr
91
92cdef class Client:
93 """
94
95 Client for Ethumbd server.
96
97 This client is the recommended way to generate thumbnails with
98 Ethumb. All you have to do is create a client instance, wait it to
99 be connected to server, configure thumbnail parameters and then
100 start feed it with file_set(), exists() generate(). Basic steps are:
101
102 - instantiate Client, wait for func to be called with success.
103 - set various parameters, like format and size.
104 - loop on original files:
105
106 - ``c.file_set(file)``
107 - ``if not c.exists(): c.generate(generated_cb)``
108
109 When the last reference to client is released, server is
110 automatically disconnected. Since callback may contain references
111 to server itself, it is recommended explicit call to
112 :py:func:`disconnect` function.
113
114 """
115
116 def __init__(self, func, *args, **kargs):
117 """
118
119 Ethumb Client constructor.
120
121 Server is ready to receive requests just after **func** is
122 called back with ``status == True``.
123
124 :param func: function to call when connection with server is
125 established. Function signature is::
126
127 func(client, status, *args, **kargs)
128
129 with status being True for successful connection or False
130 on error.
131
132 :raise TypeError: if **func** is not callable.
133 :raise SystemError: if it was not possible to connect to
134 server, allocate memory or use DBus.
135
136 """
137 if not callable(func):
138 raise TypeError("Parameter 'func' must be callable")
139 if self.obj == NULL:
140 self._on_connect_callback = (func, args, kargs)
141 self._on_server_die_callback = None
142 self.obj = ethumb_client_connect(_connect_cb, <void*>self, NULL)
143 if self.obj == NULL:
144 raise SystemError("Error connecting to server.")
145 else:
146 ethumb_client_on_server_die_callback_set(
147 self.obj, _on_server_die_cb, <void*>self, NULL)
148
149 def __dealloc__(self):
150 if self.obj != NULL:
151 ethumb_client_disconnect(self.obj)
152
153 def disconnect(self):
154 """Explicitly request server disconnection.
155
156 After this call object becomes shallow, that is operations
157 will be void.
158 """
159 if self.obj != NULL:
160 ethumb_client_disconnect(self.obj)
161 self.obj = NULL
162 self._on_connect_callback = None
163 self._on_server_die_callback = None
164
165 def __str__(self):
166 f, k = self.file
167 tf, tk = self.thumb_path
168 w, h = self.size
169
170 format = ("FDO", "JPEG", "EET")[self.format]
171 aspect = ("KEEP", "IGNORE", "CROP")[self.aspect]
172 if self.aspect == 2:
173 aspect = "CROP[%f, %f]" % self.crop
174 return ("%s(file=(%r, %r), thumb=(%r, %r), exists=%s, size=%dx%d, "
175 "format=%s, aspect=%s, quality=%d, compress=%d, "
176 "directory=%r, category=%r)") % \
177 (self.__class__.__name__, f, k, tf, tk, self.thumb_exists(),
178 w, h, format, aspect, self.quality, self.compress,
179 self.directory, self.category)
180
181 def __repr__(self):
182 f, k = self.file
183 tf, tk = self.thumb_path
184 return "%s(obj=%#x, file=(%r, %r), thumb=(%r, %r), exists=%s)" % \
185 (self.__class__.__name__, <uintptr_t><void *>self, f, k, tf, tk, self.thumb_exists())
186
187 def on_server_die_callback_set(self, func, *args, **kargs):
188 """Function to call when server dies.
189
190 When server is dead there is nothing to do with this client
191 anymore, just create a new one and start over, hope that
192 server could be started and you could generate more
193 thumbnails.
194
195 :param func: function to call when server dies.
196 Signature::
197
198 func(client, *args, **kargs)
199
200 :raise TypeError: if **func** is not callable or None.
201 """
202 if func is None:
203 self._on_server_die_callback = None
204 elif callable(func):
205 self._on_server_die_callback = (func, args, kargs)
206 else:
207 raise TypeError("Parameter 'func' must be callable or None")
208
209 def fdo_set(self, int s):
210 """Configure future requests to use FreeDesktop.Org preset.
211
212 This is a preset to provide freedesktop.org (fdo) standard
213 compliant thumbnails. That is, files are stored as JPEG under
214 ~/.thumbnails/SIZE, with size being either normal (128x128) or
215 large (256x256).
216
217 :param s: size identifier, either ETHUMB_THUMB_NORMAL (0) or
218 ETHUMB_THUMB_LARGE.
219
220 .. seealso:: :py:func:`size_set`, :py:func:`format_set`, :py:func:`aspect_set`, :py:func:`crop_set`,
221 :py:func:`category_set`, :py:func:`directory_set`.
222 """
223 ethumb_client_fdo_set(self.obj, s)
224
225 def size_set(self, int w, int h):
226 """Configure future request to use custom size.
227
228 :param w: width, default is 128.
229 :param h: height, default is 128.
230 """
231 ethumb_client_size_set(self.obj, w, h)
232
233 def size_get(self):
234 """Get current size being used by requests.
235
236 :rtype: tuple of int.
237 """
238 cdef int w, h
239 ethumb_client_size_get(self.obj, &w, &h)
240 return (w, h)
241
242 property size:
243 def __set__(self, value):
244 cdef int w, h
245 w, h = value
246 self.size_set(w, h)
247
248 def __get__(self):
249 return self.size_get()
250
251 def format_set(self, int f):
252 """Configure format to use for future requests.
253
254 :param f: format identifier to use, either ETHUMB_THUMB_FDO (0),
255 ETHUMB_THUMB_JPEG (1) or ETHUMB_THUMB_EET (2). Default is FDO.
256 """
257 ethumb_client_format_set(self.obj, f)
258
259 def format_get(self):
260 """Get current format in use for requests.
261
262 :rtype: int
263 """
264 return ethumb_client_format_get(self.obj)
265
266 property format:
267 def __set__(self, value):
268 self.format_set(value)
269
270 def __get__(self):
271 return self.format_get()
272
273 def aspect_set(self, int a):
274 """Configure aspect mode to use.
275
276 If aspect is kept (ETHUMB_THUMB_KEEP_ASPECT), then image will
277 be rescaled so the largest dimension is not bigger than it's
278 specified size (see :py:func:`size_get`) and the other dimension is
279 resized in the same proportion. Example: size is 256x256,
280 image is 1000x500, resulting thumbnail is 256x128.
281
282 If aspect is ignored (ETHUMB_THUMB_IGNORE_ASPECT), then image
283 will be distorted to match required thumbnail size. Example:
284 size is 256x256, image is 1000x500, resulting thumbnail is
285 256x256.
286
287 If crop is required (ETHUMB_THUMB_CROP), then image will be
288 cropped so the smallest dimension is not bigger than its
289 specified size (see :py:func:`size_get`) and the other dimension
290 will overflow, not being visible in the final image. How it
291 will overflow is speficied by :py:func:`crop_set`
292 alignment. Example: size is 256x256, image is 1000x500, crop
293 alignment is 0.5, 0.5, resulting thumbnail is 256x256 with 250
294 pixels from left and 250 pixels from right being lost, that is
295 just the 500x500 central pixels of image will be considered
296 for scaling.
297
298 :param a: aspect mode identifier, either ETHUMB_THUMB_KEEP_ASPECT (0),
299 ETHUMB_THUMB_IGNORE_ASPECT (1) or ETHUMB_THUMB_CROP (2).
300
301 """
302 ethumb_client_aspect_set(self.obj, a)
303
304 def aspect_get(self):
305 """Get current aspect in use for requests.
306
307 :rtype: int
308 """
309 return ethumb_client_aspect_get(self.obj)
310
311 property aspect:
312 def __set__(self, value):
313 self.aspect_set(value)
314
315 def __get__(self):
316 return self.aspect_get()
317
318 def crop_set(self, float x, float y):
319 """Configure crop alignment in use for future requests.
320
321 :param x: horizontal alignment. 0.0 means left side will be
322 visible or right side is being lost. 1.0 means right
323 side will be visible or left side is being lost. 0.5
324 means just center is visible, both sides will be lost.
325 Default is 0.5.
326 :param y: vertical alignment. 0.0 is top visible, 1.0 is
327 bottom visible, 0.5 is center visible. Default is 0.5
328 """
329 ethumb_client_crop_align_set(self.obj, x, y)
330
331 def crop_get(self):
332 """Get current crop alignment in use for requests.
333
334 :rtype: tuple of float
335 """
336 cdef float x, y
337 ethumb_client_crop_align_get(self.obj, &x, &y)
338 return (x, y)
339
340 property crop:
341 def __set__(self, value):
342 cdef float x, y
343 x, y = value
344 self.crop_set(x, y)
345
346 def __get__(self):
347 return self.crop_get()
348
349 def quality_set(self, int quality):
350 """Configure quality to be used in thumbnails.
351
352 :param quality: value from 0 to 100, default is 80. The
353 effect depends on the format being used, PNG will not
354 use it.
355 """
356 ethumb_client_quality_set(self.obj, quality)
357
358 def quality_get(self):
359 """Get current quality in use for requests.
360
361 :rtype: int
362 """
363 return ethumb_client_quality_get(self.obj)
364
365 property quality:
366 def __set__(self, value):
367 self.quality_set(value)
368
369 def __get__(self):
370 return self.quality_get()
371
372 def compress_set(self, int compress):
373 """Configure compression level used in requests.
374
375 :param compress: value from 0 to 9, default is 9. The effect
376 depends on the format being used, JPEG will not use it.
377 """
378 ethumb_client_compress_set(self.obj, compress)
379
380 def compress_get(self):
381 """Get current compression level in use for requests.
382
383 :rtype: int
384 """
385 return ethumb_client_compress_get(self.obj)
386
387 property compress:
388 def __set__(self, value):
389 self.compress_set(value)
390
391 def __get__(self):
392 return self.compress_get()
393
394 def directory_set(self, path):
395 """Configure where to store thumbnails in future requests.
396
397 Note that this is the base, a category is added to this path
398 as a sub directory.
399
400 :param path: base directory where to store
401 thumbnails. Default is ~/.thumbnails
402 """
403 ethumb_client_dir_path_set(self.obj, str_to_c(path))
404
405 def directory_get(self):
406 """Get current base directory to store thumbnails.
407
408 :rtype: str or None
409 """
410 return str_from_c(ethumb_client_dir_path_get(self.obj))
411
412 property directory:
413 def __set__(self, value):
414 self.directory_set(value)
415
416 def __get__(self):
417 return self.directory_get()
418
419 def category_set(self, category):
420 """Category directory to store thumbnails.
421
422 :param category: category sub directory to store
423 thumbnail. Default is either "normal" or "large" for FDO
424 compliant thumbnails or
425 WIDTHxHEIGHT-ASPECT[-FRAMED]-FORMAT. It can be a string or
426 None to use auto generated names.
427 """
428 ethumb_client_category_set(self.obj, str_to_c(category))
429
430 def category_get(self):
431 """Get current category sub directory to store thumbnails.
432
433 :rtype: str or None
434 """
435 return str_from_c(ethumb_client_category_get(self.obj))
436
437 property category:
438 def __set__(self, value):
439 self.category_set(value)
440
441 def __get__(self):
442 return self.category_get()
443
444 def frame_set(self, file, group, swallow):
445 """Set frame to apply to future thumbnails.
446
447 This will create an edje object that will have image swallowed
448 in. This can be used to simulate Polaroid or wood frames in
449 the generated image. Remeber it is bad to modify the original
450 contents of thumbnails, but sometimes it's useful to have it
451 composited and avoid runtime overhead.
452
453 :param file: file path to edje.
454 :param group: group inside edje to use.
455 :param swallow: name of swallow part.
456 """
457 cdef:
458 char *f
459 char *g
460 char *s
461 f = str_to_c(file)
462 g = str_to_c(group)
463 s = str_to_c(swallow)
464 return ethumb_client_frame_set(self.obj, f, g, s)
465
466 def file_set(self, path, key=None):
467 """Set file to thumbnail.
468
469 Calling this function will zero :py:func:`thumb_set`
470 specifications. This is done to avoid one using the last thumb
471 path for new images.
472
473 :param path: path to thumbnail subject.
474 :param key: path to key inside **path**, this is used to
475 generate thumbnail of edje groups or images inside EET.
476 """
477 cdef:
478 char *p
479 char *k
480 p = str_to_c(path)
481 k = str_to_c(key)
482 ethumb_client_file_set(self.obj, p, k)
483
484 def file_get(self):
485 """Get current file to thumbnail.
486
487 :rtype: tuple of str
488 """
489 cdef:
490 const char *p
491 const char *k
492 ethumb_client_file_get(self.obj, &p, &k)
493 return (str_from_c(p), str_from_c(k))
494
495 property file:
496 def __set__(self, value):
497 p, k = value
498 self.file_set(p, k)
499
500 def __get__(self):
501 return self.file_get()
502
503 def file_free(self):
504 """Zero/Reset file parameters.
505
506 This call will reset file and thumb specifications.
507
508 .. seealso:: :py:func:`file_set` and :py:func:`thumb_set`
509 """
510 ethumb_client_file_free(self.obj)
511
512 def thumb_set(self, path, key=None):
513 """Set thumbnail path and key.
514
515 Note that these parameters are forgotten (reset) after
516 :py:func:`file_set`.
517
518 :param path: path to generated thumbnail to use, this is an
519 absolute path to file, overriding directory and category.
520 :param key: path to key inside **path**, this is used to
521 generate thumbnail inside EET files.
522 """
523 cdef:
524 const char *p
525 const char *k
526 p = str_to_c(path)
527 k = str_to_c(key)
528 ethumb_client_thumb_path_set(self.obj, p, k)
529
530 def thumb_get(self):
531 """Get current path and key of thumbnail.
532
533 Note that if no explicit :py:func:`thumb_set` was called, it will
534 auto generate path based on existing parameters such as
535 directory, category and others.
536
537 :rtype: tuple of str
538 """
539 cdef:
540 const char *p
541 const char *k
542 ethumb_client_thumb_path_get(self.obj, &p, &k)
543 return (str_from_c(p), str_from_c(k))
544
545 property thumb_path:
546 def __set__(self, value):
547 p, k = value
548 self.thumb_set(p, k)
549 def __get__(self):
550 return self.thumb_get()
551
552 def video_time_set(self, float time):
553 ethumb_client_video_time_set(self.obj, time)
554
555 def video_start_set(self, float start):
556 ethumb_client_video_start_set(self.obj, start)
557
558 def video_interval_set(self, float interval):
559 ethumb_client_video_interval_set(self.obj, interval)
560
561 def video_ntimes_set(self, int ntimes):
562 ethumb_client_video_ntimes_set(self.obj, ntimes)
563
564 def video_fps_set(self, int fps):
565 ethumb_client_video_fps_set(self.obj, fps)
566
567 # document_page
568 def document_page_set(self, int page):
569 ethumb_client_document_page_set(self.obj, page)
570
571 def thumb_exists(self, callback = None, *args, **kwargs):
572 """Checks if thumbnail already exists.
573
574 If you want to avoid regenerating thumbnails, check if they
575 already exist with this function.
576
577 """
578 cdef Ethumb_Client_Thumb_Exists_Cb cb = NULL
579 cdef Ethumb_Exists *res
580
581 if callback:
582 if not callable(callback):
583 raise TypeError("callback is not callable")
584 cb = _thumb_exists_cb
585
586 data = (args, kwargs)
587 res = ethumb_client_thumb_exists(self.obj, cb, <void *>data)
588
589 return False
590 #TODO: handle return value
591
592 def generate(self, func, *args, **kargs):
593 """Ask EThumb server to generate the specified thumbnail.
594
595 Thumbnail generation is asynchronous and depend on ecore main
596 loop running. Given function will be called back with
597 generation status if True is returned by this call. If False
598 is returned, given function will not be called.
599
600 Existing thumbnails will be overwritten with this call. Check
601 if they already exist with :py:func:`exists` before calling.
602
603 :param func: function to call on generation completion, even
604 if failed or succeeded. Signature is::
605
606 func(self, id, file, key, thumb_path, thumb_key, status, *args, **kargs)
607
608 with status being True for successful generation or
609 False on failure.
610
611 :return: request identifier. Request can be canceled calling
612 :py:func:`cancel` with given id. If an identifier is returned (>=
613 0), then func is guaranteed to be called unless it is
614 explicitly canceled.
615
616 :raise TypeError: if **func** is not callable.
617 :raise SystemError: if could not generate thumbnail, probably
618 no :py:func:`file_set`.
619
620 .. seealso:: :py:func:`cancel`, :py:func:`clear`, :py:func:`exists`
621 """
622 if not callable(func):
623 raise TypeError("func must be callable")
624
625 targs = (self, func, args, kargs)
626 r = ethumb_client_generate(self.obj, _generated_cb, <void*>targs,
627 _generated_cb_free_data)
628 if r >= 0:
629 Py_INCREF(targs)
630 return r
631 else:
632 raise SystemError("could not generate thumbnail. "
633 "Did you set the file?")
634
635 def generate_cancel(self, int id):
636 """Cancel thumbnail request given its id.
637
638 Calling this function aborts thumbnail generation and **func**
639 given to :py:func:`generate` will not be called!
640
641 :param id: identifier returned by :py:func:`generate`
642 """
643 ethumb_client_generate_cancel(self.obj, id, NULL, NULL, NULL)
644
645 def generate_cancel_all(self):
646 """Clear request queue, canceling all generation requests.
647
648 This will abort all existing requests, no **func** given to
649 :py:func:`generate` will be called.
650
651 Same as calling :py:func:`cancel` in all exising requests.
652 """
653 ethumb_client_generate_cancel_all(self.obj)
654
655init()
diff --git a/include/efl.ethumb.enums.pxd b/include/efl.ethumb.enums.pxd
new file mode 100644
index 0000000..2c6f6e4
--- /dev/null
+++ b/include/efl.ethumb.enums.pxd
@@ -0,0 +1,26 @@
1cdef extern from "Ethumb.h":
2 ctypedef enum Ethumb_Thumb_Orientation:
3 ETHUMB_THUMB_ORIENT_NONE # keep orientation as pixel data is
4 ETHUMB_THUMB_ROTATE_90_CW # rotate 90° clockwise
5 ETHUMB_THUMB_ROTATE_180 # rotate 180°
6 ETHUMB_THUMB_ROTATE_90_CCW # rotate 90° counter-clockwise
7 ETHUMB_THUMB_FLIP_HORIZONTAL # flip horizontally
8 ETHUMB_THUMB_FLIP_VERTICAL # flip vertically
9 ETHUMB_THUMB_FLIP_TRANSPOSE # transpose
10 ETHUMB_THUMB_FLIP_TRANSVERSE # transverse
11 ETHUMB_THUMB_ORIENT_ORIGINAL # use orientation from metadata (EXIF-only currently)
12
13 ctypedef enum Ethumb_Thumb_FDO_Size:
14 ETHUMB_THUMB_NORMAL # 128x128 as defined by FreeDesktop.Org standard
15 ETHUMB_THUMB_LARGE # 256x256 as defined by FreeDesktop.Org standard
16
17 ctypedef enum Ethumb_Thumb_Format:
18 ETHUMB_THUMB_FDO # PNG as defined by FreeDesktop.Org standard
19 ETHUMB_THUMB_JPEG # JPEGs are often smaller and faster to read/write
20 ETHUMB_THUMB_EET # EFL's own storage system, supports key parameter
21
22 ctypedef enum Ethumb_Thumb_Aspect:
23 ETHUMB_THUMB_KEEP_ASPECT # keep original proportion between width and height
24 ETHUMB_THUMB_IGNORE_ASPECT # ignore aspect and foce it to match thumbnail's width and height
25 ETHUMB_THUMB_CROP # keep aspect but crop (cut) the largest dimension
26
diff --git a/include/efl.ethumb.pxd b/include/efl.ethumb.pxd
new file mode 100644
index 0000000..16ffe60
--- /dev/null
+++ b/include/efl.ethumb.pxd
@@ -0,0 +1,106 @@
1# Copyright (C) 2009 by ProFUSION embedded systems
2#
3# This file is part of Python-Ethumb.
4#
5# Python-Ethumb 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-Ethumb 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-Ethumb. If not, see <http://www.gnu.org/licenses/>.
17
18from efl.eina cimport Eina_Bool, Eina_Free_Cb
19from efl.ethumb.enums cimport Ethumb_Thumb_FDO_Size, Ethumb_Thumb_Format, \
20 Ethumb_Thumb_Aspect, Ethumb_Thumb_Orientation
21
22cdef extern from "Ethumb.h":
23 cdef struct Ethumb:
24 int tw
25 int th
26 int format
27 int aspect
28
29 ctypedef void (*Ethumb_Generate_Cb)(void *data, Ethumb *e, Eina_Bool success)
30
31 # Ethumb
32 int ethumb_init()
33 void ethumb_shutdown()
34 Ethumb *ethumb_new()
35 void ethumb_free(Ethumb *e)
36
37 # Setup
38 Eina_Bool ethumb_frame_set(Ethumb *e, const char *theme_file, const char *group, const char *swallow)
39 void ethumb_frame_get(Ethumb *e, const char **theme_file, const char **group, const char **swallow)
40
41 void ethumb_thumb_dir_path_set(Ethumb *e, const char *path)
42 const char * ethumb_thumb_dir_path_get(Ethumb *e)
43
44 void ethumb_thumb_category_set(Ethumb *e, const char *category)
45 const char * ethumb_thumb_category_get(Ethumb *e)
46
47 void ethumb_thumb_path_set(Ethumb *e, const char *path, const char *key)
48 void ethumb_thumb_path_get(Ethumb *e, const char **path, const char **key)
49 void ethumb_thumb_hash(Ethumb *e)
50 void ethumb_thumb_hash_copy(Ethumb *dst, Ethumb *src)
51
52
53 void ethumb_thumb_fdo_set(Ethumb *e, Ethumb_Thumb_FDO_Size s)
54
55 void ethumb_thumb_size_set(Ethumb *e, int tw, int th)
56 void ethumb_thumb_size_get(Ethumb *e, int *tw, int *th)
57
58 void ethumb_thumb_format_set(Ethumb *e, Ethumb_Thumb_Format f)
59 Ethumb_Thumb_Format ethumb_thumb_format_get(Ethumb *e)
60
61 void ethumb_thumb_aspect_set(Ethumb *e, Ethumb_Thumb_Aspect a)
62 Ethumb_Thumb_Aspect ethumb_thumb_aspect_get(Ethumb *e)
63
64 void ethumb_thumb_orientation_set(Ethumb *e, Ethumb_Thumb_Orientation o)
65 Ethumb_Thumb_Orientation ethumb_thumb_orientation_get(Ethumb *e)
66
67 void ethumb_thumb_crop_align_set(Ethumb *e, float x, float y)
68 void ethumb_thumb_crop_align_get(Ethumb *e, float *x, float *y)
69
70 void ethumb_thumb_quality_set(Ethumb *e, int quality)
71 int ethumb_thumb_quality_get(Ethumb *e)
72
73 void ethumb_thumb_compress_set(Ethumb *e, int compress)
74 int ethumb_thumb_compress_get(Ethumb *e)
75
76 void ethumb_video_start_set(Ethumb *e, float start)
77 float ethumb_video_start_get(Ethumb *e)
78 void ethumb_video_time_set(Ethumb *e, float time)
79 float ethumb_video_time_get(Ethumb *e)
80 void ethumb_video_interval_set(Ethumb *e, float interval)
81 float ethumb_video_interval_get(Ethumb *e)
82 void ethumb_video_ntimes_set(Ethumb *e, unsigned int ntimes)
83 unsigned int ethumb_video_ntimes_get(Ethumb *e)
84 void ethumb_video_fps_set(Ethumb *e, unsigned int fps)
85 unsigned int ethumb_video_fps_get(Ethumb *e)
86
87 # Basics
88 void ethumb_document_page_set(Ethumb *e, unsigned int page)
89 unsigned int ethumb_document_page_get(Ethumb *e)
90
91 Eina_Bool ethumb_file_set(Ethumb *e, const char *path, const char *key)
92 void ethumb_file_get(Ethumb *e, const char **path, const char **key)
93 void ethumb_file_free(Ethumb *e)
94
95 Eina_Bool ethumb_generate(Ethumb *e, Ethumb_Generate_Cb finished_cb, void *data, Eina_Free_Cb free_data)
96 Eina_Bool ethumb_exists(Ethumb *e)
97
98 Ethumb *ethumb_dup(Ethumb *e)
99 Eina_Bool ethumb_cmp(Ethumb *e1, Ethumb *e2)
100 int ethumb_hash(void *key, int key_length)
101 int ethumb_key_cmp(void *key1, int key1_length, void *key2, int key2_length)
102 unsigned int ethumb_length(void *key)
103
104
105cdef class PyEthumb:
106 cdef Ethumb *obj
diff --git a/include/efl.ethumb_client.pxd b/include/efl.ethumb_client.pxd
new file mode 100644
index 0000000..902f4dd
--- /dev/null
+++ b/include/efl.ethumb_client.pxd
@@ -0,0 +1,96 @@
1# Copyright (C) 2009 by ProFUSION embedded systems
2#
3# This file is part of Python-Ethumb.
4#
5# Python-Ethumb 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-Ethumb 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-Ethumb. If not, see <http://www.gnu.org/licenses/>.
17
18from efl.eina cimport Eina_Bool, Eina_Free_Cb
19from efl.ethumb.enums cimport Ethumb_Thumb_Orientation
20
21cdef extern from "Ethumb_Client.h":
22 ctypedef struct Ethumb_Client
23 ctypedef struct Ethumb_Exists
24 ctypedef void (*Ethumb_Client_Connect_Cb)(void *data, Ethumb_Client *client, Eina_Bool success)
25 ctypedef void (*Ethumb_Client_Die_Cb)(void *data, Ethumb_Client *client)
26 ctypedef void (*Ethumb_Client_Generate_Cb)(void *data, Ethumb_Client *client, int id, const char *file, const char *key, const char *thumb_path, const char *thumb_key, Eina_Bool success)
27 ctypedef void (*Ethumb_Client_Thumb_Exists_Cb)(void *data, Ethumb_Client *client, Ethumb_Exists *thread, Eina_Bool exists)
28 ctypedef void (*Ethumb_Client_Generate_Cancel_Cb)(void *data, Eina_Bool success)
29
30 int ethumb_client_init()
31 int ethumb_client_shutdown()
32
33 Ethumb_Client *ethumb_client_connect(Ethumb_Client_Connect_Cb cb, void *data, Eina_Free_Cb free_data)
34 void ethumb_client_disconnect(Ethumb_Client *client)
35 void ethumb_client_on_server_die_callback_set(Ethumb_Client *client, Ethumb_Client_Die_Cb server_die_cb, void *data, Eina_Free_Cb free_data)
36
37 void ethumb_client_fdo_set(Ethumb_Client *client, int s)
38
39 void ethumb_client_size_set(Ethumb_Client *client, int tw, int th)
40 void ethumb_client_size_get(Ethumb_Client *client, int *tw, int *th)
41 void ethumb_client_format_set(Ethumb_Client *client, int f)
42 int ethumb_client_format_get(Ethumb_Client *client)
43 void ethumb_client_aspect_set(Ethumb_Client *client, int a)
44 int ethumb_client_aspect_get(Ethumb_Client *client)
45 void ethumb_client_orientation_set(Ethumb_Client *client, Ethumb_Thumb_Orientation o)
46 Ethumb_Thumb_Orientation ethumb_client_orientation_get(Ethumb_Client *client)
47 void ethumb_client_crop_align_set(Ethumb_Client *client, float x, float y)
48 void ethumb_client_crop_align_get(Ethumb_Client *client, float *x, float *y)
49 void ethumb_client_quality_set(Ethumb_Client *client, int quality)
50 int ethumb_client_quality_get(Ethumb_Client *client)
51 void ethumb_client_compress_set(Ethumb_Client *client, int compress)
52 int ethumb_client_compress_get(Ethumb_Client *client)
53 Eina_Bool ethumb_client_frame_set(Ethumb_Client *client, const char *file, const char *group, const char *swallow)
54 void ethumb_client_dir_path_set(Ethumb_Client *client, const char *path)
55 const char * ethumb_client_dir_path_get(Ethumb_Client *client)
56 void ethumb_client_category_set(Ethumb_Client *client, const char *category)
57 const char * ethumb_client_category_get(Ethumb_Client *client)
58 void ethumb_client_video_time_set(Ethumb_Client *client, float time)
59 void ethumb_client_video_start_set(Ethumb_Client *client, float start)
60 void ethumb_client_video_interval_set(Ethumb_Client *client, float interval)
61 void ethumb_client_video_ntimes_set(Ethumb_Client *client, int ntimes)
62 void ethumb_client_video_fps_set(Ethumb_Client *client, int fps)
63 void ethumb_client_document_page_set(Ethumb_Client *client, int page)
64
65 void ethumb_client_ethumb_setup(Ethumb_Client *client)
66
67 void ethumb_client_thumb_path_set(Ethumb_Client *client, const char *path, const char *key)
68 void ethumb_client_thumb_path_get(Ethumb_Client *client, const char **path, const char **key)
69
70 Eina_Bool ethumb_client_file_set(Ethumb_Client *client, const char *path, const char *key)
71 void ethumb_client_file_get(Ethumb_Client *client, const char **path, const char **key)
72 void ethumb_client_file_free(Ethumb_Client *client)
73
74 Ethumb_Exists *ethumb_client_thumb_exists(Ethumb_Client *client, Ethumb_Client_Thumb_Exists_Cb exists_cb, void *data)
75 void ethumb_client_thumb_exists_cancel(Ethumb_Exists *exists)
76 Eina_Bool ethumb_client_thumb_exists_check(Ethumb_Exists *exists)
77 int ethumb_client_generate(Ethumb_Client *client, Ethumb_Client_Generate_Cb generated_cb, void *data, Eina_Free_Cb free_data)
78 void ethumb_client_generate_cancel(Ethumb_Client *client, int id, Ethumb_Client_Generate_Cancel_Cb cancel_cb, void *data, Eina_Free_Cb free_data)
79 void ethumb_client_generate_cancel_all(Ethumb_Client *client)
80
81 ctypedef void (*Ethumb_Client_Async_Done_Cb)(Ethumb_Client *ethumbd, const char *thumb_path, const char *thumb_key, void *data)
82 ctypedef void (*Ethumb_Client_Async_Error_Cb)(Ethumb_Client *ethumbd, void *data)
83
84 ctypedef struct Ethumb_Client_Async
85
86 Ethumb_Client_Async *ethumb_client_thumb_async_get(Ethumb_Client *client,
87 Ethumb_Client_Async_Done_Cb done,
88 Ethumb_Client_Async_Error_Cb error,
89 void *data)
90
91 void ethumb_client_thumb_async_cancel(Ethumb_Client *client, Ethumb_Client_Async *request)
92
93cdef class Client:
94 cdef Ethumb_Client *obj
95 cdef object _on_connect_callback
96 cdef object _on_server_die_callback
diff --git a/setup.py b/setup.py
index bd37371..822be2c 100755
--- a/setup.py
+++ b/setup.py
@@ -186,6 +186,24 @@ if set(("build", "build_ext", "install", "bdist", "sdist")) & set(sys.argv):
186 package_dirs["ecore"] = "compat/ecore" 186 package_dirs["ecore"] = "compat/ecore"
187 187
188 188
189 # === Ethumb ===
190 ethumb_cflags, ethumb_libs = pkg_config('Ethumb', 'ethumb', EFL_MIN_VERSION)
191 ethumb_ext = Extension("ethumb", ["efl/ethumb/efl.ethumb"+module_suffix],
192 include_dirs = ['include/'],
193 extra_compile_args = ethumb_cflags,
194 extra_link_args = ethumb_libs + eina_libs,
195 )
196 modules.append(ethumb_ext)
197
198 ethumb_client_cflags, ethumb_client_libs = pkg_config('Ethumb_Client', 'ethumb_client', EFL_MIN_VERSION)
199 ethumb_client_ext = Extension("ethumb_client", ["efl/ethumb/efl.ethumb_client"+module_suffix],
200 include_dirs = ['include/'],
201 extra_compile_args = ethumb_client_cflags,
202 extra_link_args = ethumb_client_libs + eina_libs,
203 )
204 modules.append(ethumb_client_ext)
205
206
189 # === Edje === 207 # === Edje ===
190 edje_cflags, edje_libs = pkg_config('Edje', 'edje', EFL_MIN_VERSION) 208 edje_cflags, edje_libs = pkg_config('Edje', 'edje', EFL_MIN_VERSION)
191 edje_ext = Extension("edje", ["efl/edje/efl.edje"+module_suffix], 209 edje_ext = Extension("edje", ["efl/edje/efl.edje"+module_suffix],