diff --git a/doc/elementary/image.rst b/doc/elementary/image.rst index 8abb85e..1b8d31a 100644 --- a/doc/elementary/image.rst +++ b/doc/elementary/image.rst @@ -38,6 +38,13 @@ Emitted signals - ``download,progress`` - url download in progress - ``download,end`` - remote url download has finished - ``download,error`` - remote url download has finished with errors +- ``load,open`` - Triggered when the file has been opened, if async open is + enabled (image size is known). (since 1.19) +- ``load,ready`` - Triggered when the image file is ready for display, if + preload is enabled. (since 1.19) +- ``load,error`` - Triggered if an async I/O or decoding error occurred, if + async open or preload is enabled (since 1.19) +- ``load,cancel`` - Triggered whenener async I/O was cancelled. (since 1.19) Enumerations diff --git a/efl/elementary/image.pxi b/efl/elementary/image.pxi index 3cf4411..0389aef 100644 --- a/efl/elementary/image.pxi +++ b/efl/elementary/image.pxi @@ -406,7 +406,7 @@ cdef class Image(Object): property preload_disabled: """Enable or disable preloading of the image - :type: bool + :type: bool (**writeonly**) """ def __set__(self, disabled): @@ -415,6 +415,22 @@ cdef class Image(Object): def preload_disabled_set(self, disabled): elm_image_preload_disabled_set(self.obj, disabled) + property async_open: + """ Enable asynchronous file I/O for file set. + + If True, this will make elm_image_file_set() an asynchronous operation. + + :type: bool (**writeonly**) + + .. versionadded:: 1.19 + + """ + def __set__(self, bint async): + elm_image_async_open_set(self.obj, async) + + def async_open_set(self, bint async): + elm_image_async_open_set(self.obj, async) + property orient: """The image orientation. @@ -602,5 +618,51 @@ cdef class Image(Object): def callback_download_error_del(self, func): self._callback_del_full("download,error", _image_download_error_conv, func) + def callback_load_open_add(self, func, *args, **kwargs): + """ Triggered when the file has been opened, if async open is enabled + (image size is known) + + .. versionadded:: 1.19 + + """ + self._callback_add("load,open", func, args, kwargs) + + def callback_load_open_del(self, func): + self._callback_del("load,open", func) + + def callback_load_ready_add(self, func, *args, **kwargs): + """ Triggered when the image file is ready for display, + if preload is enabled + + .. versionadded:: 1.19 + + """ + self._callback_add("load,ready", func, args, kwargs) + + def callback_load_ready_del(self, func): + self._callback_del("load,ready", func) + + def callback_load_error_add(self, func, *args, **kwargs): + """ Triggered if an async I/O or decoding error occurred, + if async open or preload is enabled + + .. versionadded:: 1.19 + + """ + self._callback_add("load,error", func, args, kwargs) + + def callback_load_error_del(self, func): + self._callback_del("load,error", func) + + def callback_load_cancel_add(self, func, *args, **kwargs): + """ Triggered whenener async I/O was cancelled + + .. versionadded:: 1.19 + + """ + self._callback_add("load,cancel", func, args, kwargs) + + def callback_load_cancel_del(self, func): + self._callback_del("load,cancel", func) _object_mapping_register("Efl.Ui.Image", Image) diff --git a/efl/elementary/image_cdef.pxi b/efl/elementary/image_cdef.pxi index f187cd3..a3f7531 100644 --- a/efl/elementary/image_cdef.pxi +++ b/efl/elementary/image_cdef.pxi @@ -38,3 +38,4 @@ cdef extern from "Elementary.h": Eina_Bool elm_image_no_scale_get(const Evas_Object *obj) void elm_image_aspect_fixed_set(Evas_Object *obj, Eina_Bool fixed) Eina_Bool elm_image_aspect_fixed_get(const Evas_Object *obj) + void elm_image_async_open_set(Evas_Object *obj, Eina_Bool async) diff --git a/examples/elementary/test.py b/examples/elementary/test.py index bcb5aa5..3192006 100755 --- a/examples/elementary/test.py +++ b/examples/elementary/test.py @@ -157,6 +157,7 @@ items = [ ("Icon Standard", "test_icon", "icon_standard_clicked"), ("Image", "test_image", "test_image"), ("Image with memfile", "test_image_memfile", "test_image_memfile"), + ("Image async load", "test_image_async", "test_image_async"), ("Photo", "test_photo", "photo_clicked"), ("Photocam", "test_photocam", "photocam_clicked"), ("Slideshow", "test_slideshow", "slideshow_clicked"), diff --git a/examples/elementary/test_image_async.py b/examples/elementary/test_image_async.py new file mode 100644 index 0000000..016f5dd --- /dev/null +++ b/examples/elementary/test_image_async.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python +# encoding: utf-8 + +import os + +from efl import elementary as elm +from efl.elementary import StandardWindow, Box, Image, Check, Button +from efl.evas import EXPAND_BOTH, FILL_BOTH, EXPAND_HORIZ, FILL_HORIZ + + +script_path = os.path.dirname(os.path.abspath(__file__)) +img_path = os.path.join(script_path, "images") +img_file = os.path.join(img_path, "insanely_huge_test_image.jpg") + + +def create_image(win): + box = win.data["box"] + async = win.data["async_chk"].state + preload_disabled = win.data["preload_chk"].state + + if "image" in win.data: + print("Deleting old image") + win.data["image"].delete() + + print("Creating image, async: %s, preload_disabled: %s" % ( + async, preload_disabled)) + + im = Image(win, async_open=async, preload_disabled=preload_disabled, + size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) + box.pack_start(im) + win.data["image"] = im + + im.callback_load_open_add(lambda i: print("load,open")) + im.callback_load_ready_add(lambda i: print("load,ready")) + im.callback_load_error_add(lambda i: print("load,error")) + im.callback_load_cancel_add(lambda i: print("load,cancel")) + + im.show() + im.file = img_file + + +def test_image_async(obj, it=None): + win = StandardWindow("image-async", "Image Async Test", + autodel=True, size=(320, 480)) + + box = Box(win, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) + win.resize_object_add(box) + box.show() + win.data["box"] = box + + hbox = Box(box, horizontal=True, + size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) + box.pack_end(hbox) + hbox.show() + + ck = Check(hbox, text="Async file open") + hbox.pack_end(ck) + ck.show() + win.data["async_chk"] = ck + + ck = Check(hbox, text="Disable preload") + hbox.pack_end(ck) + ck.show() + win.data["preload_chk"] = ck + + bt = Button(box, text="Image Reload") + bt.callback_clicked_add(lambda b: create_image(win)) + box.pack_end(bt) + bt.show() + + create_image(win) + win.show() + + +if __name__ == "__main__": + elm.policy_set(elm.ELM_POLICY_QUIT, elm.ELM_POLICY_QUIT_LAST_WINDOW_CLOSED) + test_image_async(None) + elm.run()