Mercurial > libervia-desktop-kivy
annotate cagou/plugins/plugin_wid_widget_selector.py @ 360:a77386b73e55
core: change selected_widget when root screen widget is changed
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 18 Jan 2020 23:12:52 +0100 |
parents | 4d3a0c4f2430 |
children | 9c6fe392d623 |
rev | line source |
---|---|
353
19422bbd9c8e
core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents:
312
diff
changeset
|
1 #!/usr/bin/env python3 |
12 | 2 |
3 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client | |
282 | 4 # Copyright (C) 2016-2019 Jérôme Poisson (goffi@goffi.org) |
12 | 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 sat.core import log as logging | |
21 log = logging.getLogger(__name__) | |
14 | 22 from sat.core.i18n import _ |
15
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
23 from cagou.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 | 25 from kivy.uix.boxlayout import BoxLayout |
26 from kivy import properties | |
27 from kivy.uix.behaviors import ButtonBehavior | |
15
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
28 from cagou.core import cagou_widget |
16
ba14b596b90e
host can now be get as a global value:
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
29 from cagou import G |
12 | 30 |
31 | |
14 | 32 PLUGIN_INFO = { |
312 | 33 "name": _("widget selector"), |
14 | 34 "import_name": C.WID_SELECTOR, |
35 "main": "WidgetSelector", | |
312 | 36 "description": _("show available widgets and allow to select one"), |
37 "icon_medium": "{media}/icons/muchoslava/png/selector_no_border_blue_44.png" | |
14 | 38 } |
39 | |
40 | |
12 | 41 class WidgetSelItem(ButtonBehavior, BoxLayout): |
14 | 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 | 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 | 46 log.debug("widget selection: {}".format(self.plugin_info["name"])) |
14 | 47 factory = self.plugin_info["factory"] |
18
790dbc5c4e89
plugin widget selector: display improvment + host profiles are now used by default
Goffi <goffi@goffi.org>
parents:
16
diff
changeset
|
48 G.host.switchWidget(self, factory(self.plugin_info, None, profiles=iter(G.host.profiles))) |
12 | 49 |
50 | |
15
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
51 class WidgetSelector(cagou_widget.CagouWidget): |
267
896f78760b63
core: fixed crash when calling deleteUnusedWidgetInstances on widgets not inheriting from QuickWidget
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
52 # TODO: should inherit from QuickWidget |
12 | 53 |
16
ba14b596b90e
host can now be get as a global value:
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
54 def __init__(self): |
ba14b596b90e
host can now be get as a global value:
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
55 super(WidgetSelector, self).__init__() |
169
6a288d4a493f
widget selector: replaced deprecated ListView by BoxLayout
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
56 self.items = [] |
6a288d4a493f
widget selector: replaced deprecated ListView by BoxLayout
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
57 for plugin_info in G.host.getPluggedWidgets(except_cls=self.__class__): |
6a288d4a493f
widget selector: replaced deprecated ListView by BoxLayout
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
58 item = WidgetSelItem(plugin_info=plugin_info) |
6a288d4a493f
widget selector: replaced deprecated ListView by BoxLayout
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
59 self.items.append(item.item) |
6a288d4a493f
widget selector: replaced deprecated ListView by BoxLayout
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
60 item.item.bind(minimum_width=self.adjust_width) |
6a288d4a493f
widget selector: replaced deprecated ListView by BoxLayout
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
61 self.add_widget(item) |
6a288d4a493f
widget selector: replaced deprecated ListView by BoxLayout
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
62 self.add_widget(Widget()) |
6a288d4a493f
widget selector: replaced deprecated ListView by BoxLayout
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
63 |
6a288d4a493f
widget selector: replaced deprecated ListView by BoxLayout
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
64 def adjust_width(self, label, texture_size): |
6a288d4a493f
widget selector: replaced deprecated ListView by BoxLayout
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
65 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
|
66 for i in self.items: |
6a288d4a493f
widget selector: replaced deprecated ListView by BoxLayout
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
67 i.width = width |
12 | 68 |
357
4d3a0c4f2430
core: better back key (ESC) management:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
69 def key_input(self, window, key, scancode, codepoint, modifier): |
4d3a0c4f2430
core: better back key (ESC) management:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
70 # we pass to avoid default CagouWidget which is going back to default widget |
4d3a0c4f2430
core: better back key (ESC) management:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
71 # (which is this one) |
4d3a0c4f2430
core: better back key (ESC) management:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
72 pass |
4d3a0c4f2430
core: better back key (ESC) management:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
73 |
14 | 74 @classmethod |
16
ba14b596b90e
host can now be get as a global value:
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
75 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
|
76 return cls() |
14 | 77 |
78 | |
79 PLUGIN_INFO["factory"] = WidgetSelector.factory |