Mercurial > libervia-desktop-kivy
comparison 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 |
comparison
equal
deleted
inserted
replaced
492:5114bbb5daa3 | 493:b3cedbee561d |
---|---|
1 #!/usr/bin/env python3 | |
2 | |
3 #Libervia Desktop-Kivy | |
4 # Copyright (C) 2016-2021 Jérôme Poisson (goffi@goffi.org) | |
5 | |
6 # This program is free software: you can redistribute it and/or modify | |
7 # it under the terms of the GNU Affero General Public License as published by | |
8 # the Free Software Foundation, either version 3 of the License, or | |
9 # (at your option) any later version. | |
10 | |
11 # This program is distributed in the hope that it will be useful, | |
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 # GNU Affero General Public License for more details. | |
15 | |
16 # You should have received a copy of the GNU Affero General Public License | |
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | |
19 | |
20 from libervia.backend.core import log as logging | |
21 log = logging.getLogger(__name__) | |
22 from libervia.backend.core.i18n import _ | |
23 from libervia.desktop_kivy.core.constants import Const as C | |
24 from kivy.uix.widget import Widget | |
25 from kivy.uix.boxlayout import BoxLayout | |
26 from kivy import properties | |
27 from kivy.uix.behaviors import ButtonBehavior | |
28 from libervia.desktop_kivy.core import cagou_widget | |
29 from libervia.desktop_kivy import G | |
30 | |
31 | |
32 PLUGIN_INFO = { | |
33 "name": _("widget selector"), | |
34 "import_name": C.WID_SELECTOR, | |
35 "main": "WidgetSelector", | |
36 "description": _("show available widgets and allow to select one"), | |
37 "icon_medium": "{media}/icons/muchoslava/png/selector_no_border_blue_44.png" | |
38 } | |
39 | |
40 | |
41 class WidgetSelItem(ButtonBehavior, BoxLayout): | |
42 plugin_info = properties.DictProperty() | |
43 item = properties.ObjectProperty() | |
44 | |
45 def on_release(self, *args): | |
46 log.debug("widget selection: {}".format(self.plugin_info["name"])) | |
47 factory = self.plugin_info["factory"] | |
48 G.host.switch_widget( | |
49 self, factory(self.plugin_info, None, profiles=iter(G.host.profiles))) | |
50 | |
51 | |
52 class WidgetSelector(cagou_widget.LiberviaDesktopKivyWidget): | |
53 container = properties.ObjectProperty() | |
54 | |
55 def __init__(self): | |
56 super(WidgetSelector, self).__init__() | |
57 self.items = [] | |
58 for plugin_info in G.host.get_plugged_widgets(except_cls=self.__class__): | |
59 item = WidgetSelItem(plugin_info=plugin_info) | |
60 self.items.append(item.item) | |
61 item.item.bind(minimum_width=self.adjust_width) | |
62 self.container.add_widget(item) | |
63 self.container.add_widget(Widget()) | |
64 | |
65 def adjust_width(self, label, texture_size): | |
66 width = max([i.minimum_width for i in self.items]) | |
67 for i in self.items: | |
68 i.width = width | |
69 | |
70 def key_input(self, window, key, scancode, codepoint, modifier): | |
71 # we pass to avoid default LiberviaDesktopKivyWidget which is going back to default widget | |
72 # (which is this one) | |
73 pass | |
74 | |
75 @classmethod | |
76 def factory(cls, plugin_info, target, profiles): | |
77 return cls() | |
78 | |
79 | |
80 PLUGIN_INFO["factory"] = WidgetSelector.factory |