Mercurial > libervia-desktop-kivy
changeset 424:027fad764864
common widgets: ImagesGallery first draft:
This widget handle the fullscreen display of images. Some features like sharing or
download are planned in the future.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 26 Feb 2020 16:43:48 +0100 |
parents | f8ba934ea462 |
children | 13884aac1220 |
files | cagou/core/common_widgets.py cagou/kv/common_widgets.kv |
diffstat | 2 files changed, 57 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/cagou/core/common_widgets.py Wed Feb 26 16:42:22 2020 +0100 +++ b/cagou/core/common_widgets.py Wed Feb 26 16:43:48 2020 +0100 @@ -19,15 +19,16 @@ """common advanced widgets, which can be reused everywhere.""" -from sat.core.i18n import _ -from kivy.uix.label import Label -from kivy.uix.boxlayout import BoxLayout -from .behaviors import TouchMenuItemBehavior +from kivy.clock import Clock from kivy import properties from kivy.metrics import dp -from kivy.clock import Clock +from kivy.uix.scatterlayout import ScatterLayout +from kivy.uix.boxlayout import BoxLayout +from kivy.uix.label import Label +from sat.core.i18n import _ +from sat.core import log as logging from cagou import G -from sat.core import log as logging +from .behaviors import TouchMenuItemBehavior log = logging.getLogger(__name__) @@ -127,3 +128,35 @@ class CategorySeparator(Label): pass + + +class ImageViewer(ScatterLayout): + source = properties.StringProperty() + + +class ImagesGallery(BoxLayout): + """Show list of images in a Carousel, with some controls to downloads""" + sources = properties.ListProperty() + carousel = properties.ObjectProperty() + + def on_kv_post(self, __): + self.on_sources(None, self.sources) + + def on_parent(self, __, parent): + # we hide the head widget to have full screen + G.host.app.showHeadWidget(not bool(parent), animation=False) + + def on_sources(self, __, sources): + if not sources or not self.carousel: + return + self.carousel.clear_widgets() + for source in sources: + img = ImageViewer( + source=source, + ) + self.carousel.add_widget(img) + + def key_input(self, window, key, scancode, codepoint, modifier): + if key == 27: + G.host.closeUI() + return True
--- a/cagou/kv/common_widgets.kv Wed Feb 26 16:42:22 2020 +0100 +++ b/cagou/kv/common_widgets.kv Wed Feb 26 16:43:48 2020 +0100 @@ -45,3 +45,21 @@ bold: True font_size: sp(20) color: app.c_sec + +<ImageViewer>: + do_rotation: False + AsyncImage: + source: root.source + allow_stretch: True, + + +<ImagesGallery>: + carousel: carousel + canvas.before: + Color: + rgba: 0, 0, 0, 1 + Rectangle: + pos: self.pos + size: self.size + Carousel: + id: carousel