annotate libervia/desktop_kivy/plugins/plugin_wid_widget_selector.py @ 493:b3cedbee561d

refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
author Goffi <goffi@goffi.org>
date Fri, 02 Jun 2023 18:26:16 +0200
parents cagou/plugins/plugin_wid_widget_selector.py@203755bbe0fe
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
1 #!/usr/bin/env python3
12
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
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: 378
diff changeset
4 # Copyright (C) 2016-2021 Jérôme Poisson (goffi@goffi.org)
12
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
5
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
20 from libervia.backend.core import log as logging
12
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 log = logging.getLogger(__name__)
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
22 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
23 from libervia.desktop_kivy.core.constants import Const as C
169
6a288d4a493f widget selector: replaced deprecated ListView by BoxLayout
Goffi <goffi@goffi.org>
parents: 126
diff changeset
24 from kivy.uix.widget import Widget
12
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from kivy.uix.boxlayout import BoxLayout
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from kivy import properties
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from kivy.uix.behaviors import ButtonBehavior
493
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.desktop_kivy.core import cagou_widget
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
12
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
30
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
31
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
32 PLUGIN_INFO = {
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
33 "name": _("widget selector"),
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
34 "import_name": C.WID_SELECTOR,
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
35 "main": "WidgetSelector",
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
36 "description": _("show available widgets and allow to select one"),
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
37 "icon_medium": "{media}/icons/muchoslava/png/selector_no_border_blue_44.png"
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
38 }
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
39
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
40
12
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 class WidgetSelItem(ButtonBehavior, BoxLayout):
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
42 plugin_info = properties.DictProperty()
169
6a288d4a493f widget selector: replaced deprecated ListView by BoxLayout
Goffi <goffi@goffi.org>
parents: 126
diff changeset
43 item = properties.ObjectProperty()
12
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
44
169
6a288d4a493f widget selector: replaced deprecated ListView by BoxLayout
Goffi <goffi@goffi.org>
parents: 126
diff changeset
45 def on_release(self, *args):
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
46 log.debug("widget selection: {}".format(self.plugin_info["name"]))
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
47 factory = self.plugin_info["factory"]
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 461
diff changeset
48 G.host.switch_widget(
365
9c6fe392d623 core (widgets_handler): use a StencilView + BoxLayout instead of ScrollView as wrapper:
Goffi <goffi@goffi.org>
parents: 357
diff changeset
49 self, factory(self.plugin_info, None, profiles=iter(G.host.profiles)))
12
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
50
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
51
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
52 class WidgetSelector(cagou_widget.LiberviaDesktopKivyWidget):
365
9c6fe392d623 core (widgets_handler): use a StencilView + BoxLayout instead of ScrollView as wrapper:
Goffi <goffi@goffi.org>
parents: 357
diff changeset
53 container = properties.ObjectProperty()
12
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
54
16
ba14b596b90e host can now be get as a global value:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
55 def __init__(self):
ba14b596b90e host can now be get as a global value:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
56 super(WidgetSelector, self).__init__()
169
6a288d4a493f widget selector: replaced deprecated ListView by BoxLayout
Goffi <goffi@goffi.org>
parents: 126
diff changeset
57 self.items = []
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 461
diff changeset
58 for plugin_info in G.host.get_plugged_widgets(except_cls=self.__class__):
169
6a288d4a493f widget selector: replaced deprecated ListView by BoxLayout
Goffi <goffi@goffi.org>
parents: 126
diff changeset
59 item = WidgetSelItem(plugin_info=plugin_info)
6a288d4a493f widget selector: replaced deprecated ListView by BoxLayout
Goffi <goffi@goffi.org>
parents: 126
diff changeset
60 self.items.append(item.item)
6a288d4a493f widget selector: replaced deprecated ListView by BoxLayout
Goffi <goffi@goffi.org>
parents: 126
diff changeset
61 item.item.bind(minimum_width=self.adjust_width)
365
9c6fe392d623 core (widgets_handler): use a StencilView + BoxLayout instead of ScrollView as wrapper:
Goffi <goffi@goffi.org>
parents: 357
diff changeset
62 self.container.add_widget(item)
9c6fe392d623 core (widgets_handler): use a StencilView + BoxLayout instead of ScrollView as wrapper:
Goffi <goffi@goffi.org>
parents: 357
diff changeset
63 self.container.add_widget(Widget())
169
6a288d4a493f widget selector: replaced deprecated ListView by BoxLayout
Goffi <goffi@goffi.org>
parents: 126
diff changeset
64
6a288d4a493f widget selector: replaced deprecated ListView by BoxLayout
Goffi <goffi@goffi.org>
parents: 126
diff changeset
65 def adjust_width(self, label, texture_size):
6a288d4a493f widget selector: replaced deprecated ListView by BoxLayout
Goffi <goffi@goffi.org>
parents: 126
diff changeset
66 width = max([i.minimum_width for i in self.items])
6a288d4a493f widget selector: replaced deprecated ListView by BoxLayout
Goffi <goffi@goffi.org>
parents: 126
diff changeset
67 for i in self.items:
6a288d4a493f widget selector: replaced deprecated ListView by BoxLayout
Goffi <goffi@goffi.org>
parents: 126
diff changeset
68 i.width = width
12
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
69
357
4d3a0c4f2430 core: better back key (ESC) management:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
70 def key_input(self, window, key, scancode, codepoint, modifier):
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
71 # we pass to avoid default LiberviaDesktopKivyWidget which is going back to default widget
357
4d3a0c4f2430 core: better back key (ESC) management:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
72 # (which is this one)
4d3a0c4f2430 core: better back key (ESC) management:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
73 pass
4d3a0c4f2430 core: better back key (ESC) management:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
74
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
75 @classmethod
16
ba14b596b90e host can now be get as a global value:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
76 def factory(cls, plugin_info, target, profiles):
ba14b596b90e host can now be get as a global value:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
77 return cls()
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
78
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
79
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
80 PLUGIN_INFO["factory"] = WidgetSelector.factory