annotate libervia/desktop_kivy/core/common_widgets.py @ 508:d87b9a6b0b69

doc (calls): updated documentation to describe the new UI features: fix 425
author Goffi <goffi@goffi.org>
date Wed, 25 Oct 2023 15:29:33 +0200
parents b3cedbee561d
children 196483685a63
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
379
1da3c379205b fixed shebangs
Goffi <goffi@goffi.org>
parents: 378
diff changeset
1 #!/usr/bin/env python3
1da3c379205b fixed shebangs
Goffi <goffi@goffi.org>
parents: 378
diff changeset
2
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
3 #Libervia Desktop-Kivy
461
3c9ba4a694ef dates update
Goffi <goffi@goffi.org>
parents: 436
diff changeset
4 # Copyright (C) 2016-2021 Jérôme Poisson (goffi@goffi.org)
237
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
5
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
10
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
15
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
18
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
19 """common advanced widgets, which can be reused everywhere."""
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
20
424
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
21 from kivy.clock import Clock
237
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from kivy import properties
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from kivy.metrics import dp
424
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
24 from kivy.uix.scatterlayout import ScatterLayout
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
25 from kivy.uix.boxlayout import BoxLayout
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
26 from kivy.uix.label import Label
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
27 from libervia.backend.core.i18n import _
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
28 from libervia.backend.core import log as logging
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
29 from libervia.desktop_kivy import G
424
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
30 from .behaviors import TouchMenuItemBehavior
237
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
31
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
32 log = logging.getLogger(__name__)
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
33
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
34
324
4374cb741eb5 core (common widgets): added a DelayedBoxLayout class:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
35 class DelayedBoxLayout(BoxLayout):
4374cb741eb5 core (common widgets): added a DelayedBoxLayout class:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
36 """A BoxLayout with delayed layout, to avoid slowing down during resize"""
4374cb741eb5 core (common widgets): added a DelayedBoxLayout class:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
37 # XXX: thanks to Alexander Taylor for his blog post at
4374cb741eb5 core (common widgets): added a DelayedBoxLayout class:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
38 # https://blog.kivy.org/2019/07/a-delayed-resize-layout-in-kivy/
4374cb741eb5 core (common widgets): added a DelayedBoxLayout class:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
39
4374cb741eb5 core (common widgets): added a DelayedBoxLayout class:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
40 do_layout_event = properties.ObjectProperty(None, allownone=True)
4374cb741eb5 core (common widgets): added a DelayedBoxLayout class:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
41 layout_delay_s = properties.NumericProperty(0.2)
329
51520ce98154 common_widgets (DelayedBoxLayout), chat: don't delay layout on new message:
Goffi <goffi@goffi.org>
parents: 324
diff changeset
42 #: set this to X to force next X layouts to be done without delay
51520ce98154 common_widgets (DelayedBoxLayout), chat: don't delay layout on new message:
Goffi <goffi@goffi.org>
parents: 324
diff changeset
43 dont_delay_next_layouts = properties.NumericProperty(0)
324
4374cb741eb5 core (common widgets): added a DelayedBoxLayout class:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
44
4374cb741eb5 core (common widgets): added a DelayedBoxLayout class:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
45 def do_layout(self, *args, **kwargs):
4374cb741eb5 core (common widgets): added a DelayedBoxLayout class:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
46 if self.do_layout_event is not None:
4374cb741eb5 core (common widgets): added a DelayedBoxLayout class:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
47 self.do_layout_event.cancel()
329
51520ce98154 common_widgets (DelayedBoxLayout), chat: don't delay layout on new message:
Goffi <goffi@goffi.org>
parents: 324
diff changeset
48 if self.dont_delay_next_layouts>0:
51520ce98154 common_widgets (DelayedBoxLayout), chat: don't delay layout on new message:
Goffi <goffi@goffi.org>
parents: 324
diff changeset
49 self.dont_delay_next_layouts-=1
51520ce98154 common_widgets (DelayedBoxLayout), chat: don't delay layout on new message:
Goffi <goffi@goffi.org>
parents: 324
diff changeset
50 super().do_layout()
51520ce98154 common_widgets (DelayedBoxLayout), chat: don't delay layout on new message:
Goffi <goffi@goffi.org>
parents: 324
diff changeset
51 else:
51520ce98154 common_widgets (DelayedBoxLayout), chat: don't delay layout on new message:
Goffi <goffi@goffi.org>
parents: 324
diff changeset
52 real_do_layout = super().do_layout
51520ce98154 common_widgets (DelayedBoxLayout), chat: don't delay layout on new message:
Goffi <goffi@goffi.org>
parents: 324
diff changeset
53 self.do_layout_event = Clock.schedule_once(
51520ce98154 common_widgets (DelayedBoxLayout), chat: don't delay layout on new message:
Goffi <goffi@goffi.org>
parents: 324
diff changeset
54 lambda dt: real_do_layout(*args, **kwargs),
51520ce98154 common_widgets (DelayedBoxLayout), chat: don't delay layout on new message:
Goffi <goffi@goffi.org>
parents: 324
diff changeset
55 self.layout_delay_s)
324
4374cb741eb5 core (common widgets): added a DelayedBoxLayout class:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
56
4374cb741eb5 core (common widgets): added a DelayedBoxLayout class:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
57
237
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
58 class Identities(object):
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
59
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
60 def __init__(self, entity_ids):
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
61 identities = {}
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
62 for cat, type_, name in entity_ids:
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
63 identities.setdefault(cat, {}).setdefault(type_, []).append(name)
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
64 client = identities.get('client', {})
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
65 if 'pc' in client:
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
66 self.type = 'desktop'
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
67 elif 'phone' in client:
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
68 self.type = 'phone'
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
69 elif 'web' in client:
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
70 self.type = 'web'
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
71 elif 'console' in client:
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
72 self.type = 'console'
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
73 else:
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
74 self.type = 'desktop'
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
75
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
76 self.identities = identities
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
77
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
78 @property
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
79 def name(self):
374
3002704318e3 core (common_widgets): fixed own jid detection in DeviceWidget + `name` property in Identities
Goffi <goffi@goffi.org>
parents: 329
diff changeset
80 first_identity = next(iter(self.identities.values()))
3002704318e3 core (common_widgets): fixed own jid detection in DeviceWidget + `name` property in Identities
Goffi <goffi@goffi.org>
parents: 329
diff changeset
81 names = next(iter(first_identity.values()))
3002704318e3 core (common_widgets): fixed own jid detection in DeviceWidget + `name` property in Identities
Goffi <goffi@goffi.org>
parents: 329
diff changeset
82 return names[0]
237
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
83
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
84
404
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 379
diff changeset
85 class ItemWidget(TouchMenuItemBehavior, BoxLayout):
237
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
86 name = properties.StringProperty()
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
87 base_width = properties.NumericProperty(dp(100))
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
88
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
89
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
90 class DeviceWidget(ItemWidget):
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
91
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
92 def __init__(self, main_wid, entity_jid, identities, **kw):
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
93 self.entity_jid = entity_jid
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
94 self.identities = identities
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
95 own_jid = next(iter(G.host.profiles.values())).whoami
374
3002704318e3 core (common_widgets): fixed own jid detection in DeviceWidget + `name` property in Identities
Goffi <goffi@goffi.org>
parents: 329
diff changeset
96 self.own_device = entity_jid.bare == own_jid.bare
237
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
97 if self.own_device:
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
98 name = self.identities.name
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
99 elif self.entity_jid.node:
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
100 name = self.entity_jid.node
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
101 elif self.entity_jid == own_jid.domain:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
102 name = _("your server")
237
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
103 else:
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
104 name = entity_jid
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
105
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
106 super(DeviceWidget, self).__init__(name=name, main_wid=main_wid, **kw)
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
107
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
108 @property
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
109 def profile(self):
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
110 return self.main_wid.profile
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
111
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 461
diff changeset
112 def get_symbol(self):
237
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
113 if self.identities.type == 'desktop':
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
114 return 'desktop'
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
115 elif self.identities.type == 'phone':
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
116 return 'mobile'
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
117 elif self.identities.type == 'web':
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
118 return 'globe'
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
119 elif self.identities.type == 'console':
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
120 return 'terminal'
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
121 else:
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
122 return 'desktop'
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
123
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
124 def do_item_action(self, touch):
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
125 pass
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
126
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
127
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
128 class CategorySeparator(Label):
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
diff changeset
129 pass
424
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
130
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
131
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
132 class ImageViewer(ScatterLayout):
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
133 source = properties.StringProperty()
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
134
436
036ff0ed7474 common widgets (ImagesGallery): reset image transformation on slide change or double tap.
Goffi <goffi@goffi.org>
parents: 424
diff changeset
135 def on_touch_down(self, touch):
036ff0ed7474 common widgets (ImagesGallery): reset image transformation on slide change or double tap.
Goffi <goffi@goffi.org>
parents: 424
diff changeset
136 if touch.is_double_tap:
036ff0ed7474 common widgets (ImagesGallery): reset image transformation on slide change or double tap.
Goffi <goffi@goffi.org>
parents: 424
diff changeset
137 self.reset()
036ff0ed7474 common widgets (ImagesGallery): reset image transformation on slide change or double tap.
Goffi <goffi@goffi.org>
parents: 424
diff changeset
138 return True
036ff0ed7474 common widgets (ImagesGallery): reset image transformation on slide change or double tap.
Goffi <goffi@goffi.org>
parents: 424
diff changeset
139 return super().on_touch_down(touch)
036ff0ed7474 common widgets (ImagesGallery): reset image transformation on slide change or double tap.
Goffi <goffi@goffi.org>
parents: 424
diff changeset
140
036ff0ed7474 common widgets (ImagesGallery): reset image transformation on slide change or double tap.
Goffi <goffi@goffi.org>
parents: 424
diff changeset
141 def reset(self):
036ff0ed7474 common widgets (ImagesGallery): reset image transformation on slide change or double tap.
Goffi <goffi@goffi.org>
parents: 424
diff changeset
142 self.rotation = 0
036ff0ed7474 common widgets (ImagesGallery): reset image transformation on slide change or double tap.
Goffi <goffi@goffi.org>
parents: 424
diff changeset
143 self.scale = 1
036ff0ed7474 common widgets (ImagesGallery): reset image transformation on slide change or double tap.
Goffi <goffi@goffi.org>
parents: 424
diff changeset
144 self.x = 0
036ff0ed7474 common widgets (ImagesGallery): reset image transformation on slide change or double tap.
Goffi <goffi@goffi.org>
parents: 424
diff changeset
145 self.y = 0
036ff0ed7474 common widgets (ImagesGallery): reset image transformation on slide change or double tap.
Goffi <goffi@goffi.org>
parents: 424
diff changeset
146
424
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
147
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
148 class ImagesGallery(BoxLayout):
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
149 """Show list of images in a Carousel, with some controls to downloads"""
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
150 sources = properties.ListProperty()
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
151 carousel = properties.ObjectProperty()
436
036ff0ed7474 common widgets (ImagesGallery): reset image transformation on slide change or double tap.
Goffi <goffi@goffi.org>
parents: 424
diff changeset
152 previous_slide = None
424
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
153
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
154 def on_kv_post(self, __):
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
155 self.on_sources(None, self.sources)
436
036ff0ed7474 common widgets (ImagesGallery): reset image transformation on slide change or double tap.
Goffi <goffi@goffi.org>
parents: 424
diff changeset
156 self.previous_slide = self.carousel.current_slide
036ff0ed7474 common widgets (ImagesGallery): reset image transformation on slide change or double tap.
Goffi <goffi@goffi.org>
parents: 424
diff changeset
157 self.carousel.bind(current_slide=self.on_slide_change)
424
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
158
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
159 def on_parent(self, __, parent):
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
160 # we hide the head widget to have full screen
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 461
diff changeset
161 G.host.app.show_head_widget(not bool(parent), animation=False)
424
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
162
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
163 def on_sources(self, __, sources):
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
164 if not sources or not self.carousel:
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
165 return
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
166 self.carousel.clear_widgets()
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
167 for source in sources:
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
168 img = ImageViewer(
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
169 source=source,
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
170 )
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
171 self.carousel.add_widget(img)
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
172
436
036ff0ed7474 common widgets (ImagesGallery): reset image transformation on slide change or double tap.
Goffi <goffi@goffi.org>
parents: 424
diff changeset
173 def on_slide_change(self, __, slide):
036ff0ed7474 common widgets (ImagesGallery): reset image transformation on slide change or double tap.
Goffi <goffi@goffi.org>
parents: 424
diff changeset
174 if isinstance(self.previous_slide, ImageViewer):
036ff0ed7474 common widgets (ImagesGallery): reset image transformation on slide change or double tap.
Goffi <goffi@goffi.org>
parents: 424
diff changeset
175 self.previous_slide.reset()
036ff0ed7474 common widgets (ImagesGallery): reset image transformation on slide change or double tap.
Goffi <goffi@goffi.org>
parents: 424
diff changeset
176
036ff0ed7474 common widgets (ImagesGallery): reset image transformation on slide change or double tap.
Goffi <goffi@goffi.org>
parents: 424
diff changeset
177 self.previous_slide = slide
036ff0ed7474 common widgets (ImagesGallery): reset image transformation on slide change or double tap.
Goffi <goffi@goffi.org>
parents: 424
diff changeset
178
424
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
179 def key_input(self, window, key, scancode, codepoint, modifier):
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
180 if key == 27:
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 461
diff changeset
181 G.host.close_ui()
424
027fad764864 common widgets: ImagesGallery first draft:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
182 return True