aboutsummaryrefslogtreecommitdiffstats
path: root/examples/ethumb/ethumb_client.py
blob: 59b788a1ff76f3b4b99bf6f01cab1519c8ff76c6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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()