Python-EFL: some works on the photocam widget
* implemented a proper test * implemented remote url feature * fixed file_set error raise * implemented all the missing legacy setter/getters
This commit is contained in:
parent
66e7f00308
commit
7925fc7056
|
@ -47,7 +47,10 @@ Signals that you can add callbacks for are:
|
|||
typed object onto the object in question -- the
|
||||
event info argument is the path to that image file
|
||||
- ``"clicked"`` - This is called when a user has clicked the image
|
||||
|
||||
- ``"download,start"`` - remote url download has started
|
||||
- ``"download,progress"`` - url download in progress
|
||||
- ``"download,end"`` - remote url download has finished
|
||||
- ``"download,error"`` - remote url download has finished with errors
|
||||
|
||||
Enumerations
|
||||
------------
|
||||
|
|
|
@ -4,6 +4,14 @@ from enums cimport Elm_Photocam_Zoom_Mode
|
|||
from libc.string cimport const_char
|
||||
|
||||
cdef extern from "Elementary.h":
|
||||
ctypedef struct Elm_Photocam_Progress:
|
||||
double now
|
||||
double total
|
||||
|
||||
ctypedef struct Elm_Photocam_Error:
|
||||
int status
|
||||
Eina_Bool open_error
|
||||
|
||||
Evas_Object *elm_photocam_add(Evas_Object *parent)
|
||||
Evas_Load_Error elm_photocam_file_set(Evas_Object *obj, const_char *file)
|
||||
const_char * elm_photocam_file_get(Evas_Object *obj)
|
||||
|
|
|
@ -50,6 +50,10 @@ Signals that you can add callbacks for are:
|
|||
- "scroll,anim,stop" - scrolling animation has stopped
|
||||
- "scroll,drag,start" - dragging the contents around has started
|
||||
- "scroll,drag,stop" - dragging the contents around has stopped
|
||||
- "download,start" - remote url download has started
|
||||
- "download,progress" - url download in progress
|
||||
- "download,end" - remote url download has finished
|
||||
- "download,error" - remote url download has finished with errors
|
||||
|
||||
|
||||
Enumerations
|
||||
|
@ -93,6 +97,50 @@ ELM_PHOTOCAM_ZOOM_MODE_AUTO_FILL = enums.ELM_PHOTOCAM_ZOOM_MODE_AUTO_FILL
|
|||
ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT_IN = enums.ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT_IN
|
||||
ELM_PHOTOCAM_ZOOM_MODE_LAST = enums.ELM_PHOTOCAM_ZOOM_MODE_LAST
|
||||
|
||||
|
||||
class PhotocamProgressInfo(object):
|
||||
"""
|
||||
|
||||
The info sent in the callback for the "download,progress" signals emitted
|
||||
by Photocam while downloading remote urls.
|
||||
|
||||
:var now: The amount of data received so far.
|
||||
:var total: The total amount of data to download.
|
||||
|
||||
"""
|
||||
def __init__(self):
|
||||
self.now = 0
|
||||
self.total = 0
|
||||
|
||||
def _photocam_download_progress_conv(long addr):
|
||||
cdef Elm_Photocam_Progress *pp = <Elm_Photocam_Progress *>addr
|
||||
ppi = PhotocamProgressInfo()
|
||||
ppi.now = pp.now
|
||||
ppi.total = pp.total
|
||||
return ppi
|
||||
|
||||
class PhotocamErrorInfo(object):
|
||||
"""
|
||||
|
||||
The info sent in the callback for the "download,error" signals emitted
|
||||
by Photocam when fail to download remote urls.
|
||||
|
||||
:var status: The http error code (such as 401)
|
||||
:var open_error: TODOC
|
||||
|
||||
"""
|
||||
def __init__(self):
|
||||
self.status = 0
|
||||
self.open_error = False
|
||||
|
||||
def _photocam_download_error_conv(long addr):
|
||||
cdef Elm_Photocam_Error *pe = <Elm_Photocam_Error *>addr
|
||||
pei = PhotocamErrorInfo()
|
||||
pei.status = pe.status
|
||||
pei.open_error = pe.open_error
|
||||
return pei
|
||||
|
||||
|
||||
cdef class Photocam(Object):
|
||||
|
||||
"""This is the class that actually implements the widget."""
|
||||
|
@ -116,13 +164,18 @@ cdef class Photocam(Object):
|
|||
"""
|
||||
def __set__(self, file):
|
||||
if isinstance(file, unicode): file = PyUnicode_AsUTF8String(file)
|
||||
# TODO: Check if Evas_Load_Error is being used correctly here
|
||||
if not elm_photocam_file_set(self.obj,
|
||||
<const_char *>file if file is not None else NULL):
|
||||
if elm_photocam_file_set(self.obj,
|
||||
<const_char *>file if file is not None else NULL) != 0:
|
||||
raise RuntimeError("Could not set file")
|
||||
|
||||
def __get__(self):
|
||||
return _ctouni(elm_photocam_file_get(self.obj))
|
||||
|
||||
def file_set(self, file):
|
||||
self.file = file
|
||||
def file_get(self):
|
||||
return _ctouni(elm_photocam_file_get(self.obj))
|
||||
|
||||
property zoom:
|
||||
"""The zoom level of the photo
|
||||
|
||||
|
@ -140,6 +193,11 @@ cdef class Photocam(Object):
|
|||
def __get__(self):
|
||||
return elm_photocam_zoom_get(self.obj)
|
||||
|
||||
def zoom_set(self, zoom):
|
||||
elm_photocam_zoom_set(self.obj, zoom)
|
||||
def zoom_get(self):
|
||||
return elm_photocam_zoom_get(self.obj)
|
||||
|
||||
property zoom_mode:
|
||||
"""Set the zoom mode
|
||||
|
||||
|
@ -162,6 +220,11 @@ cdef class Photocam(Object):
|
|||
def __get__(self):
|
||||
return elm_photocam_zoom_mode_get(self.obj)
|
||||
|
||||
def zoom_mode_set(self, mode):
|
||||
elm_photocam_zoom_mode_set(self.obj, mode)
|
||||
def zoom_mode_get(self):
|
||||
return elm_photocam_zoom_mode_get(self.obj)
|
||||
|
||||
property image_size:
|
||||
"""Get the current image pixel width and height
|
||||
|
||||
|
@ -177,6 +240,11 @@ cdef class Photocam(Object):
|
|||
elm_photocam_image_size_get(self.obj, &w, &h)
|
||||
return (w, h)
|
||||
|
||||
def image_size_get(self):
|
||||
cdef int w, h
|
||||
elm_photocam_image_size_get(self.obj, &w, &h)
|
||||
return (w, h)
|
||||
|
||||
property image_region:
|
||||
"""Get the region of the image that is currently shown
|
||||
|
||||
|
@ -191,6 +259,11 @@ cdef class Photocam(Object):
|
|||
elm_photocam_image_region_get(self.obj, &x, &y, &w, &h)
|
||||
return (x, y, w, h)
|
||||
|
||||
def image_region_get(self):
|
||||
cdef int x, y, w, h
|
||||
elm_photocam_image_region_get(self.obj, &x, &y, &w, &h)
|
||||
return (x, y, w, h)
|
||||
|
||||
def image_region_show(self, x, y, w, h):
|
||||
"""image_region_show(int x, int y, int w, int h)
|
||||
|
||||
|
@ -245,6 +318,11 @@ cdef class Photocam(Object):
|
|||
def __get__(self):
|
||||
return bool(elm_photocam_paused_get(self.obj))
|
||||
|
||||
def paused_set(self, paused):
|
||||
elm_photocam_paused_set(self.obj, paused)
|
||||
def paused_get(self):
|
||||
return bool(elm_photocam_paused_get(self.obj))
|
||||
|
||||
property internal_image:
|
||||
"""Get the internal low-res image used for photocam
|
||||
|
||||
|
@ -261,6 +339,9 @@ cdef class Photocam(Object):
|
|||
img.obj = obj
|
||||
return img
|
||||
|
||||
def internal_image_get(self):
|
||||
return self.internal_image
|
||||
|
||||
property bounce:
|
||||
"""Photocam scrolling bouncing.
|
||||
|
||||
|
@ -275,6 +356,13 @@ cdef class Photocam(Object):
|
|||
elm_scroller_bounce_get(self.obj, &h_bounce, &v_bounce)
|
||||
return (h_bounce, v_bounce)
|
||||
|
||||
def bounce_set(self, h_bounce, v_bounce):
|
||||
elm_scroller_bounce_set(self.obj, h_bounce, v_bounce)
|
||||
def bounce_get(self):
|
||||
cdef Eina_Bool h_bounce, v_bounce
|
||||
elm_scroller_bounce_get(self.obj, &h_bounce, &v_bounce)
|
||||
return (h_bounce, v_bounce)
|
||||
|
||||
property gesture_enabled:
|
||||
"""Set the gesture state for photocam.
|
||||
|
||||
|
@ -289,6 +377,11 @@ cdef class Photocam(Object):
|
|||
def __get__(self):
|
||||
return bool(elm_photocam_gesture_enabled_get(self.obj))
|
||||
|
||||
def gesture_enabled_set(self, gesture):
|
||||
elm_photocam_gesture_enabled_set(self.obj, gesture)
|
||||
def gesture_enabled_get(self):
|
||||
return bool(elm_photocam_gesture_enabled_get(self.obj))
|
||||
|
||||
def callback_clicked_add(self, func, *args, **kwargs):
|
||||
"""This is called when a user has clicked the photo without dragging
|
||||
around."""
|
||||
|
@ -405,5 +498,33 @@ cdef class Photocam(Object):
|
|||
def callback_scroll_drag_stop_del(self, func):
|
||||
self._callback_del("scroll,drag,stop", func)
|
||||
|
||||
def callback_download_start_add(self, func, *args, **kwargs):
|
||||
"""This is called when you set a remote url and the download start"""
|
||||
self._callback_add("download,start", func, *args, **kwargs)
|
||||
|
||||
def callback_download_start_del(self, func):
|
||||
self._callback_del("download,start", func)
|
||||
|
||||
def callback_download_progress_add(self, func, *args, **kwargs):
|
||||
"""This is called while a remote image download is in progress"""
|
||||
self._callback_add_full("download,progress", _photocam_download_progress_conv, func, *args, **kwargs)
|
||||
|
||||
def callback_download_progress_del(self, func):
|
||||
self._callback_del_full("download,progress", _photocam_download_progress_conv, func)
|
||||
|
||||
def callback_download_done_add(self, func, *args, **kwargs):
|
||||
"""This is called when you set a remote url and the download finish"""
|
||||
self._callback_add("download,done", func, *args, **kwargs)
|
||||
|
||||
def callback_download_done_del(self, func):
|
||||
self._callback_del("download,end", func)
|
||||
|
||||
def callback_download_error_add(self, func, *args, **kwargs):
|
||||
"""This is called in case a download has errors"""
|
||||
self._callback_add_full("download,error", _photocam_download_error_conv, func, *args, **kwargs)
|
||||
|
||||
def callback_download_error_del(self, func):
|
||||
self._callback_add_full("download,error", _photocam_download_error_conv, func)
|
||||
|
||||
|
||||
_object_mapping_register("elm_photocam", Photocam)
|
||||
|
|
|
@ -90,6 +90,7 @@ items = [
|
|||
("Icon Transparent", "test_icon", "icon_transparent_clicked"),
|
||||
("Image", "test_image", "image_clicked"),
|
||||
("Photo", "test_photo", "photo_clicked"),
|
||||
("Photocam", "test_photocam", "photocam_clicked"),
|
||||
("Slideshow", "test_slideshow", "slideshow_clicked"),
|
||||
("Thumb", "test_thumb", "thumb_clicked"),
|
||||
("Video", "test_video", "video_clicked"),
|
||||
|
|
|
@ -0,0 +1,148 @@
|
|||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
from efl import evas
|
||||
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
|
||||
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 = elementary.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 = elementary.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 photocam_clicked(obj):
|
||||
win = StandardWindow("photocam", "Photocam test")
|
||||
win.autodel_set(True)
|
||||
if obj is None:
|
||||
win.callback_delete_request_add(lambda o: elementary.exit())
|
||||
|
||||
# Photocam widget
|
||||
pc = Photocam(win)
|
||||
pc.size_hint_weight = evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND
|
||||
win.resize_object_add(pc)
|
||||
pc.show()
|
||||
|
||||
# table for buttons
|
||||
tb = Table(win);
|
||||
tb.size_hint_weight = evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND
|
||||
win.resize_object_add(tb)
|
||||
tb.show()
|
||||
|
||||
# zoom out btn
|
||||
bt = Button(win)
|
||||
bt.text = "Z -"
|
||||
bt.size_hint_weight = evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND
|
||||
bt.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)
|
||||
bt.text = "Select Photo File"
|
||||
bt.size_hint_weight = evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND
|
||||
bt.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)
|
||||
bt.text = "Z +"
|
||||
bt.size_hint_weight = evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND
|
||||
bt.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)
|
||||
pb.unit_format = "loading %.2f %%"
|
||||
pb.size_hint_weight = evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND
|
||||
pb.size_hint_align = evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL
|
||||
tb.pack(pb, 1, 1, 1, 1)
|
||||
|
||||
# Fit btn
|
||||
bt = Button(win);
|
||||
bt.text = "Fit"
|
||||
bt.size_hint_weight = evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND
|
||||
bt.size_hint_align = 0.1, 0.9
|
||||
bt.callback_clicked_add(lambda b: pc.zoom_mode_set(elementary.ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT))
|
||||
tb.pack(bt, 0, 2, 1, 1)
|
||||
bt.show()
|
||||
|
||||
# load remote url
|
||||
bt = Button(win)
|
||||
bt.text = "Load remote URL (27MB)"
|
||||
bt.size_hint_weight = evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND
|
||||
bt.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);
|
||||
bt.text = "Fill"
|
||||
bt.size_hint_weight = evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND
|
||||
bt.size_hint_align = 0.9, 0.9
|
||||
bt.callback_clicked_add(lambda b: pc.zoom_mode_set(elementary.ELM_PHOTOCAM_ZOOM_MODE_AUTO_FILL))
|
||||
tb.pack(bt, 2, 2, 1, 1)
|
||||
bt.show()
|
||||
|
||||
# show the win
|
||||
win.resize(600, 600)
|
||||
win.show()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
elementary.init()
|
||||
|
||||
photocam_clicked(None)
|
||||
|
||||
elementary.run()
|
||||
elementary.shutdown()
|
Loading…
Reference in New Issue