aboutsummaryrefslogtreecommitdiffstats
path: root/examples/elementary/test_photocam.py
blob: 7903e7534907d8b6e125659371574bd186a4ee87 (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env python
# encoding: utf-8

from efl.evas import EVAS_HINT_EXPAND, EVAS_HINT_FILL, EXPAND_BOTH, FILL_BOTH, \
    EVAS_IMAGE_ORIENT_0, EVAS_IMAGE_ORIENT_90, EVAS_IMAGE_ORIENT_180, \
    EVAS_IMAGE_ORIENT_270, EVAS_IMAGE_FLIP_HORIZONTAL, EVAS_IMAGE_FLIP_VERTICAL, \
    EVAS_IMAGE_FLIP_TRANSPOSE, EVAS_IMAGE_FLIP_TRANSVERSE
from efl import elementary
from efl.elementary.window import StandardWindow
from efl.elementary.box import Box
from efl.elementary.button import Button
from efl.elementary.photocam import Photocam, ELM_PHOTOCAM_ZOOM_MODE_MANUAL, \
    ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT, ELM_PHOTOCAM_ZOOM_MODE_AUTO_FILL
from efl.elementary.progressbar import Progressbar
from efl.elementary.separator import Separator
from efl.elementary.table import Table
from efl.elementary.fileselector_button import FileselectorButton


remote_url = "http://eoimages.gsfc.nasa.gov/images/imagerecords/73000/73751/world.topo.bathy.200407.3x21600x10800.jpg"


def _cb_zoom_in(bt, pc):
    pc.zoom_mode = ELM_PHOTOCAM_ZOOM_MODE_MANUAL
    zoom = pc.zoom - 0.5
    if zoom >= (1.0 / 32.0):
        pc.zoom = zoom

def _cb_zoom_out(bt, pc):
    pc.zoom_mode = ELM_PHOTOCAM_ZOOM_MODE_MANUAL
    zoom = pc.zoom + 0.5
    if zoom <= 256.0:
        pc.zoom = zoom


def _cb_pc_download_start(im, pb):
    print("CB DOWNLOAD START")
    pb.value = 0.0
    pb.show()

def _cb_pc_download_done(im, pb):
    print("CB DOWNLOAD DONE")
    pb.hide()

def _cb_pc_download_progress(im, progress, pb):
    if progress.total > 0:
        print("CB DOWNLOAD PROGRESS [now: %.0f, total: %.0f, %.2f %%]" %
             (progress.now, progress.total, progress.now / progress.total * 100))
        pb.value = progress.now / progress.total

def _cb_pc_download_error(im, info, pb):
    print("CB DOWNLOAD ERROR [status %s, open_error: %s]" % (info.status, info.open_error))
    pb.hide()


def _cb_orient(btn, pc, orient):
    pc.image_orient = orient


def photocam_clicked(obj):
    win = StandardWindow("photocam", "Photocam test", autodel=True,
        size=(600, 600))
    if obj is None:
        win.callback_delete_request_add(lambda o: elementary.exit())

    # Photocam widget
    pc = Photocam(win, size_hint_weight=EXPAND_BOTH)
    win.resize_object_add(pc)
    pc.show()

    # table for buttons
    tb = Table(win, size_hint_weight=EXPAND_BOTH)
    win.resize_object_add(tb)
    tb.show()

    # zoom out btn
    bt = Button(win, text="Z -", size_hint_weight=EXPAND_BOTH,
        size_hint_align=(0.1, 0.1))
    bt.callback_clicked_add(_cb_zoom_out, pc)
    tb.pack(bt, 0, 0, 1, 1)
    bt.show()

    # select file btn
    bt = FileselectorButton(win, text="Select Photo File",
        size_hint_weight=EXPAND_BOTH, size_hint_align=(0.5, 0.1))
    bt.callback_file_chosen_add(lambda fs, path: pc.file_set(path))
    tb.pack(bt, 1, 0, 1, 1)
    bt.show()

    # zoom in btn
    bt = Button(win, text="Z +", size_hint_weight=EXPAND_BOTH,
        size_hint_align=(0.9, 0.1))
    bt.callback_clicked_add(_cb_zoom_in, pc)
    tb.pack(bt, 2, 0, 1, 1)
    bt.show()

    # progressbar for remote loading
    pb = Progressbar(win, unit_format="loading %.2f %%",
        size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
    tb.pack(pb, 1, 1, 1, 1)

    # Fit btn
    bt = Button(win, text="Fit", size_hint_weight=EXPAND_BOTH,
        size_hint_align=(0.1, 0.9))
    bt.callback_clicked_add(lambda b: pc.zoom_mode_set(ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT))
    tb.pack(bt, 0, 2, 1, 1)
    bt.show()

    # load remote url
    bt = Button(win, text="Load remote URL (27MB)",
        size_hint_weight=EXPAND_BOTH, size_hint_align=(0.5, 0.9))
    bt.callback_clicked_add(lambda b: pc.file_set(remote_url))
    tb.pack(bt, 1, 2, 1, 1)
    bt.show()

    pc.callback_download_start_add(_cb_pc_download_start, pb)
    pc.callback_download_done_add(_cb_pc_download_done, pb)
    pc.callback_download_progress_add(_cb_pc_download_progress, pb)
    pc.callback_download_error_add(_cb_pc_download_error, pb)

    # Fill btn
    bt = Button(win, text="Fill", size_hint_weight=EXPAND_BOTH,
        size_hint_align=(0.9, 0.9))
    bt.callback_clicked_add(lambda b: pc.zoom_mode_set(ELM_PHOTOCAM_ZOOM_MODE_AUTO_FILL))
    tb.pack(bt, 2, 2, 1, 1)
    bt.show()

    # Orient buttons
    box = Box(win, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
    tb.pack(box, 0, 1, 1, 1)
    box.show()

    orients = [
        (EVAS_IMAGE_ORIENT_0, "Orient 0"),
        (EVAS_IMAGE_ORIENT_90, "Orient 90"),
        (EVAS_IMAGE_ORIENT_180, "Orient 180"),
        (EVAS_IMAGE_ORIENT_270, "Orient 270"),
        (EVAS_IMAGE_FLIP_HORIZONTAL, "Flip Horiz"),
        (EVAS_IMAGE_FLIP_VERTICAL, "Flip Vert"),
        (EVAS_IMAGE_FLIP_TRANSPOSE, "Transpose"),
        (EVAS_IMAGE_FLIP_TRANSVERSE, "Transverse"),
    ]

    for val, label in orients:
        bt = Button(win, text=label, size_hint_align=(0.1, 0.5))
        bt.callback_clicked_add(_cb_orient, pc, val)
        box.pack_end(bt)
        bt.show()

    # show the win
    win.show()


if __name__ == "__main__":

    photocam_clicked(None)

    elementary.run()