Revamp old and broken EthumbClient module

This was not functional at all, so I broke the API "a bit"
This commit is contained in:
Davide Andreoli 2016-01-03 18:50:33 +01:00
parent 93d2c01002
commit 17df9e69aa
9 changed files with 700 additions and 438 deletions

View File

@ -0,0 +1,6 @@
.. currentmodule:: efl.ethumb_client
:class:`efl.ethumb_client.EthumbClient` Class
=============================================
.. autoclass:: efl.ethumb_client.EthumbClient

View File

@ -44,6 +44,7 @@ API Reference
:titlesonly:
module-ethumb.rst
module-ethumb_client.rst
Inheritance diagram

View File

@ -1,11 +1,3 @@
diff --git doc/ethumb/ethumb_module.rst doc/ethumb/ethumb_module.rst
deleted file mode 100644
index a7189f9..0000000
--- doc/ethumb/ethumb_module.rst
+++ /dev/null
@@ -1,5 +0,0 @@
-:mod:`efl.ethumb` Module
-========================
-
-.. automodule:: efl.ethumb
- :exclude-members: PyEthumb
.. automodule:: efl.ethumb
:exclude-members: Ethumb

View File

@ -0,0 +1,3 @@
.. automodule:: efl.ethumb_client
:exclude-members: EthumbClient

View File

@ -338,7 +338,7 @@ cdef class Ethumb(object):
const char *group
const char *swallow
ethumb_frame_get(self.obj, &theme, &group, &swallow)
return tuple(_ctouni(theme), _ctouni(group), _ctouni(swallow))
return _ctouni(theme), _ctouni(group), _ctouni(swallow)
# destination thumb properties
property thumb_path:
@ -412,9 +412,7 @@ cdef class Ethumb(object):
<const char *>cat if cat is not None else NULL)
def __get__(self):
cdef const char *cat
cat = ethumb_thumb_category_get(self.obj)
return _ctouni(cat)
return _ctouni(ethumb_thumb_category_get(self.obj))
property thumb_fdo:
""" Set a standard FDO thumbnail size
@ -441,11 +439,9 @@ cdef class Ethumb(object):
ethumb_thumb_size_set(self.obj, w, h)
def __get__(self):
cdef:
int w
int h
cdef int w, h
ethumb_thumb_size_get(self.obj, &w, &h)
return tuple(w, h)
return w, h
property thumb_format:
""" The fileformat for the thumbnails.
@ -511,7 +507,7 @@ cdef class Ethumb(object):
float x
float y
ethumb_thumb_crop_align_get(self.obj, &x, &y)
return tuple(x, y)
return x, y
property thumb_quality:
""" The thumbnail compression quality.

File diff suppressed because it is too large Load Diff

110
examples/ethumb/ethumb_client.py Executable file
View File

@ -0,0 +1,110 @@
#!/usr/bin/env python
# encoding: utf-8
import os
import sys
import logging
from efl import ecore
from efl import ethumb_client as ethumb
script_path = os.path.dirname(os.path.abspath(__file__))
# parse command line arguments
if len(sys.argv) != 2:
print("Python EthumbClient test application.\n\n" \
"usage: ethumb_client.py filename\n")
exit(1)
filename = sys.argv[1]
print("Original file: %s\n" % filename)
# setup efl logging (you also need to set EINA_LOG_LEVEL=X)
l = logging.getLogger("efl")
h = logging.StreamHandler()
h.setFormatter(logging.Formatter("EFL %(levelname)s %(message)s"))
l.addHandler(h)
l.setLevel(logging.DEBUG)
complete_count = 0
def generate_cb(client, id, file, key, thumb_path, thumb_key, success, num):
global complete_count
# thumbnail completed
if success is True:
print("Thumb #%d completed: '%s'" % (num, thumb_path))
complete_count += 1
if complete_count >= 6:
print("\nTest Complete!")
ecore.main_loop_quit()
else:
print(" ERROR! aborting.")
ecore.main_loop_quit()
def connect_cb(client, success):
if success is False:
print("Connection Failed")
ecore.main_loop_quit()
return
else:
print("Connection Successfull")
# request some thumbnails
print("1. Request a standard FDO thumbnail (default)")
et.file = filename
et.generate(generate_cb, 1)
print("2. Request a large FDO thumbnail...")
et.file = filename
et.fdo = ethumb.ETHUMB_THUMB_LARGE
et.generate(generate_cb, 2)
print("3. Request a very large JPEG thumbnail...")
et.file = filename
et.format = ethumb.ETHUMB_THUMB_JPEG
et.size = 512, 512
et.generate(generate_cb, 3)
print("4. Request a cropped thumbnail...")
et.file = filename
et.aspect = ethumb.ETHUMB_THUMB_CROP
et.generate(generate_cb, 4)
print("5. Request a rotated thumbnail")
et.file = filename
et.orientation = ethumb.ETHUMB_THUMB_ROTATE_180
et.size = 256, 256
et.aspect = ethumb.ETHUMB_THUMB_KEEP_ASPECT
et.generate(generate_cb, 5)
print("6. Request a poor quality thumbnail in this folder\n")
et.file = filename
et.orientation = ethumb.ETHUMB_THUMB_ORIENT_NONE
et.thumb_path = os.path.join(script_path, 'big_poor2.jpg')
et.format = ethumb.ETHUMB_THUMB_JPEG
et.size = 512, 512
et.quality = 10
et.generate(generate_cb, 6)
# ...and now wait for the responses
def server_die_cb(client):
print("Server die!")
ecore.main_loop_quit()
# create a single Ethumb instance
et = ethumb.EthumbClient(connect_cb)
et.on_server_die_callback_set(server_die_cb)
# enter the ecore the main loop
ecore.main_loop_begin()
# free used resource
et.disconnect()

View File

@ -16,17 +16,64 @@
# along with this Python-EFL. If not, see <http://www.gnu.org/licenses/>.
from efl.eina cimport Eina_Bool, Eina_Free_Cb
from efl.ethumb cimport Ethumb_Thumb_Orientation
cdef extern from "Ethumb_Client.h":
####################################################################
# Enums
#
cpdef enum Ethumb_Thumb_Orientation:
ETHUMB_THUMB_ORIENT_NONE
ETHUMB_THUMB_ROTATE_90_CW
ETHUMB_THUMB_ROTATE_180
ETHUMB_THUMB_ROTATE_90_CCW
ETHUMB_THUMB_FLIP_HORIZONTAL
ETHUMB_THUMB_FLIP_VERTICAL
ETHUMB_THUMB_FLIP_TRANSPOSE
ETHUMB_THUMB_FLIP_TRANSVERSE
ETHUMB_THUMB_ORIENT_ORIGINAL
ctypedef enum Ethumb_Thumb_Orientation:
pass
cpdef enum Ethumb_Thumb_FDO_Size:
ETHUMB_THUMB_NORMAL
ETHUMB_THUMB_LARGE
ctypedef enum Ethumb_Thumb_FDO_Size:
pass
cpdef enum Ethumb_Thumb_Format:
ETHUMB_THUMB_FDO
ETHUMB_THUMB_JPEG
ETHUMB_THUMB_EET
ctypedef enum Ethumb_Thumb_Format:
pass
cpdef enum Ethumb_Thumb_Aspect:
ETHUMB_THUMB_KEEP_ASPECT
ETHUMB_THUMB_IGNORE_ASPECT
ETHUMB_THUMB_CROP
ctypedef enum Ethumb_Thumb_Aspect:
pass
####################################################################
# Structs
#
ctypedef struct Ethumb_Client
ctypedef struct Ethumb_Exists
####################################################################
# Other typedefs
#
ctypedef void (*Ethumb_Client_Connect_Cb)(void *data, Ethumb_Client *client, Eina_Bool success)
ctypedef void (*Ethumb_Client_Die_Cb)(void *data, Ethumb_Client *client)
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)
ctypedef void (*Ethumb_Client_Thumb_Exists_Cb)(void *data, Ethumb_Client *client, Ethumb_Exists *thread, Eina_Bool exists)
ctypedef void (*Ethumb_Client_Generate_Cancel_Cb)(void *data, Eina_Bool success)
####################################################################
# Functions
#
int ethumb_client_init()
int ethumb_client_shutdown()
@ -90,7 +137,8 @@ cdef extern from "Ethumb_Client.h":
void ethumb_client_thumb_async_cancel(Ethumb_Client *client, Ethumb_Client_Async *request)
cdef class Client:
cdef class EthumbClient:
cdef Ethumb_Client *obj
cdef object _on_connect_callback
cdef object _on_server_die_callback

View File

@ -351,8 +351,9 @@ if set(("build", "build_ext", "install", "bdist", "sdist")) & set(sys.argv):
extra_link_args=ethumb_libs + eina_libs)
ext_modules.append(ethumb_ext)
ethumb_client_cflags, ethumb_client_libs = pkg_config(
'Ethumb_Client', 'ethumb_client', EFL_MIN_VER)
# === Ethumb Client ===
ethumb_client_cflags, ethumb_client_libs = pkg_config('Ethumb_Client',
'ethumb_client', EFL_MIN_VER)
ethumb_client_ext = Extension("ethumb_client",
["efl/ethumb/efl.ethumb_client" + module_suffix],
include_dirs=['include/'],