comparison cagou/core/common_widgets.py @ 436:036ff0ed7474

common widgets (ImagesGallery): reset image transformation on slide change or double tap.
author Goffi <goffi@goffi.org>
date Sun, 01 Mar 2020 22:11:25 +0100
parents 027fad764864
children 3c9ba4a694ef
comparison
equal deleted inserted replaced
435:53bb3886b408 436:036ff0ed7474
1 #!/usr/bin/env python3 1 #!/usr/bin/env python3
2
3 2
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client 3 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client
5 # Copyright (C) 2016-2020 Jérôme Poisson (goffi@goffi.org) 4 # Copyright (C) 2016-2020 Jérôme Poisson (goffi@goffi.org)
6 5
7 # This program is free software: you can redistribute it and/or modify 6 # This program is free software: you can redistribute it and/or modify
131 130
132 131
133 class ImageViewer(ScatterLayout): 132 class ImageViewer(ScatterLayout):
134 source = properties.StringProperty() 133 source = properties.StringProperty()
135 134
135 def on_touch_down(self, touch):
136 if touch.is_double_tap:
137 self.reset()
138 return True
139 return super().on_touch_down(touch)
140
141 def reset(self):
142 self.rotation = 0
143 self.scale = 1
144 self.x = 0
145 self.y = 0
146
136 147
137 class ImagesGallery(BoxLayout): 148 class ImagesGallery(BoxLayout):
138 """Show list of images in a Carousel, with some controls to downloads""" 149 """Show list of images in a Carousel, with some controls to downloads"""
139 sources = properties.ListProperty() 150 sources = properties.ListProperty()
140 carousel = properties.ObjectProperty() 151 carousel = properties.ObjectProperty()
152 previous_slide = None
141 153
142 def on_kv_post(self, __): 154 def on_kv_post(self, __):
143 self.on_sources(None, self.sources) 155 self.on_sources(None, self.sources)
156 self.previous_slide = self.carousel.current_slide
157 self.carousel.bind(current_slide=self.on_slide_change)
144 158
145 def on_parent(self, __, parent): 159 def on_parent(self, __, parent):
146 # we hide the head widget to have full screen 160 # we hide the head widget to have full screen
147 G.host.app.showHeadWidget(not bool(parent), animation=False) 161 G.host.app.showHeadWidget(not bool(parent), animation=False)
148 162
154 img = ImageViewer( 168 img = ImageViewer(
155 source=source, 169 source=source,
156 ) 170 )
157 self.carousel.add_widget(img) 171 self.carousel.add_widget(img)
158 172
173 def on_slide_change(self, __, slide):
174 if isinstance(self.previous_slide, ImageViewer):
175 self.previous_slide.reset()
176
177 self.previous_slide = slide
178
159 def key_input(self, window, key, scancode, codepoint, modifier): 179 def key_input(self, window, key, scancode, codepoint, modifier):
160 if key == 27: 180 if key == 27:
161 G.host.closeUI() 181 G.host.closeUI()
162 return True 182 return True