Mercurial > libervia-desktop-kivy
annotate src/cagou/core/cagou_main.py @ 33:c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
when a notification from backend is coming, it's added to a notification icon (on the right for important notifications which need user action, while left icon is used for notes).
If user click on the notification icon, the XMLUI replace the main widget with a rise animation. When action is finished, ui is closed with a fall out animation.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 21 Aug 2016 21:41:52 +0200 |
parents | fdaf914e2729 |
children | 02acbb297a61 |
rev | line source |
---|---|
6
85649eca9f9b
core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
1 #!/usr//bin/env python2 |
0 | 2 # -*- coding: utf-8 -*- |
3 | |
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client | |
5 # Copyright (C) 2016 Jérôme Poisson (goffi@goffi.org) | |
6 | |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 | |
14 | 21 from sat.core.i18n import _ |
6
85649eca9f9b
core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
22 import logging_setter |
85649eca9f9b
core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
23 logging_setter.set_logging() |
85649eca9f9b
core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
24 from constants import Const as C |
0 | 25 from sat.core import log as logging |
26 log = logging.getLogger(__name__) | |
27 from sat_frontends.quick_frontend.quick_app import QuickApp | |
28 from sat_frontends.bridge.DBus import DBusBridgeFrontend | |
29 import kivy | |
30 kivy.require('1.9.1') | |
31 import kivy.support | |
32 kivy.support.install_gobject_iteration() | |
33 from kivy.app import App | |
14 | 34 from kivy.lang import Builder |
29 | 35 from kivy import properties |
0 | 36 import xmlui |
37 from profile_manager import ProfileManager | |
13 | 38 from widgets_handler import WidgetsHandler |
29 | 39 from kivy.clock import Clock |
40 from kivy.uix.label import Label | |
9 | 41 from kivy.uix.boxlayout import BoxLayout |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
42 from kivy.uix.screenmanager import ScreenManager, Screen, FallOutTransition, RiseInTransition |
29 | 43 from kivy.uix.dropdown import DropDown |
11
49d30fc15884
core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
44 from cagou_widget import CagouWidget |
29 | 45 from .common import IconButton |
14 | 46 from importlib import import_module |
9 | 47 import os.path |
14 | 48 import glob |
15
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
49 import cagou.plugins |
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
50 import cagou.kv |
9 | 51 |
52 | |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
53 class NotifsIcon(IconButton): |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
54 notifs = properties.ListProperty() |
29 | 55 |
56 def on_release(self): | |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
57 callback, args, kwargs = self.notifs.pop(0) |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
58 callback(*args, **kwargs) |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
59 |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
60 def addNotif(self, callback, *args, **kwargs): |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
61 self.notifs.append((callback, args, kwargs)) |
29 | 62 |
63 | |
64 class Note(Label): | |
65 title = properties.StringProperty() | |
66 message = properties.StringProperty() | |
67 level = properties.OptionProperty(C.XMLUI_DATA_LVL_DEFAULT, options=list(C.XMLUI_DATA_LVLS)) | |
68 | |
69 | |
70 class NoteDrop(Note): | |
71 pass | |
72 | |
73 | |
74 class NotesDrop(DropDown): | |
75 clear_btn = properties.ObjectProperty() | |
76 | |
77 def __init__(self, notes): | |
78 super(NotesDrop, self).__init__() | |
79 self.notes = notes | |
80 | |
81 def open(self, widget): | |
82 self.clear_widgets() | |
83 for n in self.notes: | |
84 self.add_widget(NoteDrop(title=n.title, message=n.message, level=n.level)) | |
85 self.add_widget(self.clear_btn) | |
86 super(NotesDrop, self).open(widget) | |
87 | |
88 | |
89 class RootHeadWidget(BoxLayout): | |
90 """Notifications widget""" | |
91 manager = properties.ObjectProperty() | |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
92 notifs_icon = properties.ObjectProperty() |
29 | 93 notes = properties.ListProperty() |
94 | |
95 def __init__(self): | |
96 super(RootHeadWidget, self).__init__() | |
97 self.notes_last = None | |
98 self.notes_event = None | |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
99 self.notes_drop = NotesDrop(self.notes) |
29 | 100 |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
101 def addNotif(self, callback, *args, **kwargs): |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
102 self.notifs_icon.addNotif(callback, *args, **kwargs) |
29 | 103 |
104 def addNote(self, title, message, level): | |
105 note = Note(title=title, message=message, level=level) | |
106 self.notes.append(note) | |
107 if len(self.notes) > 10: | |
108 del self.notes[:-10] | |
109 if self.notes_event is None: | |
110 self.notes_event = Clock.schedule_interval(self._displayNextNote, 5) | |
111 self._displayNextNote() | |
112 | |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
113 def addNotifUI(self, ui): |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
114 self.notifs_icon.addNotif(ui.show, force=True) |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
115 |
29 | 116 def _displayNextNote(self, dummy=None): |
117 screen = Screen() | |
118 try: | |
119 idx = self.notes.index(self.notes_last) + 1 | |
120 except ValueError: | |
121 idx = 0 | |
122 try: | |
123 note = self.notes_last = self.notes[idx] | |
124 except IndexError: | |
125 self.notes_event.cancel() | |
126 self.notes_event = None | |
127 else: | |
128 screen.add_widget(note) | |
129 self.manager.switch_to(screen) | |
130 | |
131 | |
9 | 132 class CagouRootWidget(BoxLayout): |
133 | |
29 | 134 def __init__(self, main_widget): |
9 | 135 super(CagouRootWidget, self).__init__(orientation=("vertical")) |
29 | 136 # header |
137 self._head_widget = RootHeadWidget() | |
138 self.add_widget(self._head_widget) | |
9 | 139 |
29 | 140 # body |
141 self._manager = ScreenManager() | |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
142 # main widgets |
29 | 143 main_screen = Screen(name='main') |
144 main_screen.add_widget(main_widget) | |
145 self._manager.add_widget(main_screen) | |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
146 # backend XMLUI (popups, forms, etc) |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
147 xmlui_screen = Screen(name='xmlui') |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
148 self._manager.add_widget(xmlui_screen) |
29 | 149 self.add_widget(self._manager) |
150 | |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
151 def changeWidget(self, widget, screen_name="main"): |
29 | 152 """change main widget""" |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
153 screen = self._manager.get_screen(screen_name) |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
154 screen.clear_widgets() |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
155 screen.add_widget(widget) |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
156 |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
157 def show(self, screen="main"): |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
158 if self._manager.current == screen: |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
159 return |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
160 if screen == "main": |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
161 self._manager.transition = FallOutTransition() |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
162 else: |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
163 self._manager.transition = RiseInTransition() |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
164 self._manager.current = screen |
29 | 165 |
166 def newAction(self, handler, action_data, id_, security_limit, profile): | |
167 """Add a notification for an action""" | |
168 self._head_widget.addNotif(handler, action_data, id_, security_limit, profile) | |
169 | |
170 def addNote(self, title, message, level): | |
171 self._head_widget.addNote(title, message, level) | |
0 | 172 |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
173 def addNotifUI(self, ui): |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
174 self._head_widget.addNotifUI(ui) |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
175 |
0 | 176 |
177 class CagouApp(App): | |
178 """Kivy App for Cagou""" | |
179 | |
180 def build(self): | |
29 | 181 return CagouRootWidget(ProfileManager()) |
0 | 182 |
31
4f9e701d76b4
core: expand now accepts extra arguments, which will be used in format
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
183 def expand(self, path, *args, **kwargs): |
28
9f9532eb835f
core: added expand method to expand filename with magic values, specially useful in kv
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
184 """expand path and replace known values |
9f9532eb835f
core: added expand method to expand filename with magic values, specially useful in kv
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
185 |
32 | 186 useful in kv. Values which can be used: |
187 - {media}: media dir | |
31
4f9e701d76b4
core: expand now accepts extra arguments, which will be used in format
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
188 @param path(unicode): path to expand |
4f9e701d76b4
core: expand now accepts extra arguments, which will be used in format
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
189 @param *args: additional arguments used in format |
4f9e701d76b4
core: expand now accepts extra arguments, which will be used in format
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
190 @param **kwargs: additional keyword arguments used in format |
28
9f9532eb835f
core: added expand method to expand filename with magic values, specially useful in kv
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
191 """ |
31
4f9e701d76b4
core: expand now accepts extra arguments, which will be used in format
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
192 return os.path.expanduser(path).format(*args, media=self.host.media_dir, **kwargs) |
28
9f9532eb835f
core: added expand method to expand filename with magic values, specially useful in kv
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
193 |
0 | 194 |
195 class Cagou(QuickApp): | |
196 MB_HANDLE = False | |
197 | |
198 def __init__(self): | |
199 super(Cagou, self).__init__(create_bridge=DBusBridgeFrontend, xmlui=xmlui) | |
15
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
200 self._import_kv() |
0 | 201 self.app = CagouApp() |
29 | 202 self.app.host = self |
25
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
203 self.media_dir = self.app.media_dir = self.bridge.getConfig("", "media_dir") |
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
204 self.app.default_avatar = os.path.join(self.media_dir, "misc/default_avatar.png") |
14 | 205 self._plg_wids = [] # widget plugins |
206 self._import_plugins() | |
0 | 207 |
208 def run(self): | |
209 self.app.run() | |
210 | |
16
ba14b596b90e
host can now be get as a global value:
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
211 def _defaultFactory(self, plugin_info, target, profiles): |
14 | 212 """factory used to create widget instance when PLUGIN_INFO["factory"] is not set""" |
213 main_cls = plugin_info['main'] | |
19
c58b522607f4
main: fixed profiles value in _defaultFactory + getPluggedWidgets is now a generator
Goffi <goffi@goffi.org>
parents:
16
diff
changeset
|
214 return self.widgets.getOrCreateWidget(main_cls, target, on_new_widget=None, profiles=iter(self.profiles)) |
14 | 215 |
29 | 216 ## plugins & kv import ## |
217 | |
15
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
218 def _import_kv(self): |
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
219 """import all kv files in cagou.kv""" |
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
220 path = os.path.dirname(cagou.kv.__file__) |
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
221 for kv_path in glob.glob(os.path.join(path, "*.kv")): |
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
222 Builder.load_file(kv_path) |
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
223 log.debug(u"kv file {} loaded".format(kv_path)) |
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
224 |
14 | 225 def _import_plugins(self): |
15
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
226 """import all plugins""" |
14 | 227 self.default_wid = None |
15
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
228 plugins_path = os.path.dirname(cagou.plugins.__file__) |
14 | 229 plug_lst = [os.path.splitext(p)[0] for p in map(os.path.basename, glob.glob(os.path.join(plugins_path, "plugin*.py")))] |
230 imported_names = set() # use to avoid loading 2 times plugin with same import name | |
231 for plug in plug_lst: | |
15
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
232 plugin_path = 'cagou.plugins.' + plug |
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
233 mod = import_module(plugin_path) |
14 | 234 try: |
235 plugin_info = mod.PLUGIN_INFO | |
236 except AttributeError: | |
237 plugin_info = {} | |
238 | |
239 # import name is used to differentiate plugins | |
240 if 'import_name' not in plugin_info: | |
241 plugin_info['import_name'] = plug | |
242 if 'import_name' in imported_names: | |
243 log.warning(_(u"there is already a plugin named {}, ignoring new one").format(plugin_info['import_name'])) | |
244 continue | |
245 if plugin_info['import_name'] == C.WID_SELECTOR: | |
246 # if WidgetSelector exists, it will be our default widget | |
247 self.default_wid = plugin_info | |
248 | |
249 # we want everything optional, so we use plugin file name | |
250 # if actual name is not found | |
251 if 'name' not in plugin_info: | |
252 plugin_info['name'] = plug[plug.rfind('_')+1:] | |
253 | |
254 # we need to load the kv file | |
255 if 'kv_file' not in plugin_info: | |
256 plugin_info['kv_file'] = u'{}.kv'.format(plug) | |
15
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
257 kv_path = os.path.join(plugins_path, plugin_info['kv_file']) |
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
258 Builder.load_file(kv_path) |
14 | 259 |
260 # what is the main class ? | |
261 main_cls = getattr(mod, plugin_info['main']) | |
262 plugin_info['main'] = main_cls | |
263 | |
264 # factory is used to create the instance | |
265 # if not found, we use a defaut one with getOrCreateWidget | |
266 if 'factory' not in plugin_info: | |
267 plugin_info['factory'] = self._defaultFactory | |
268 | |
25
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
269 # icons |
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
270 for size in ('small', 'medium'): |
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
271 key = u'icon_{}'.format(size) |
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
272 try: |
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
273 path = plugin_info[key] |
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
274 except KeyError: |
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
275 path = C.DEFAULT_WIDGET_ICON.format(media=self.media_dir) |
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
276 else: |
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
277 path = path.format(media=self.media_dir) |
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
278 if not os.path.isfile(path): |
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
279 path = C.DEFAULT_WIDGET_ICON.format(media=self.media_dir) |
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
280 plugin_info[key] = path |
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
281 |
14 | 282 self._plg_wids.append(plugin_info) |
283 if not self._plg_wids: | |
284 log.error(_(u"no widget plugin found")) | |
285 return | |
286 | |
287 # we want widgets sorted by names | |
288 self._plg_wids.sort(key=lambda p: p['name'].lower()) | |
289 | |
290 if self.default_wid is None: | |
291 # we have no selector widget, we use the first widget as default | |
292 self.default_wid = self._plg_wids[0] | |
293 | |
294 def getPluggedWidgets(self, except_cls=None): | |
295 """get available widgets plugin infos | |
296 | |
297 @param except_cls(None, class): if not None, | |
298 widgets from this class will be excluded | |
299 @return (list[dict]): available widgets plugin infos | |
300 """ | |
19
c58b522607f4
main: fixed profiles value in _defaultFactory + getPluggedWidgets is now a generator
Goffi <goffi@goffi.org>
parents:
16
diff
changeset
|
301 for plugin_data in self._plg_wids: |
c58b522607f4
main: fixed profiles value in _defaultFactory + getPluggedWidgets is now a generator
Goffi <goffi@goffi.org>
parents:
16
diff
changeset
|
302 if plugin_data['main'] == except_cls: |
c58b522607f4
main: fixed profiles value in _defaultFactory + getPluggedWidgets is now a generator
Goffi <goffi@goffi.org>
parents:
16
diff
changeset
|
303 continue |
c58b522607f4
main: fixed profiles value in _defaultFactory + getPluggedWidgets is now a generator
Goffi <goffi@goffi.org>
parents:
16
diff
changeset
|
304 yield plugin_data |
14 | 305 |
29 | 306 ## widgets handling |
9 | 307 |
11
49d30fc15884
core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
308 def switchWidget(self, old, new): |
49d30fc15884
core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
309 """Replace old widget by new one |
49d30fc15884
core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
310 |
49d30fc15884
core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
311 old(CagouWidget): CagouWidget instance or a child |
49d30fc15884
core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
312 new(CagouWidget): new widget instance |
49d30fc15884
core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
313 """ |
14 | 314 to_change = None |
315 if isinstance(old, CagouWidget): | |
316 to_change = old | |
317 else: | |
318 for w in old.walk_reverse(): | |
319 if isinstance(w, CagouWidget): | |
320 to_change = w | |
321 break | |
322 | |
323 if to_change is None: | |
324 log.error(u"no CagouWidget found when trying to switch widget") | |
325 else: | |
326 parent = to_change.parent | |
327 idx = parent.children.index(to_change) | |
328 parent.remove_widget(to_change) | |
329 parent.add_widget(new, index=idx) | |
29 | 330 |
331 ## misc ## | |
332 | |
333 def plugging_profiles(self): | |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
334 self.app.root.changeWidget(WidgetsHandler()) |
29 | 335 |
336 def setPresenceStatus(self, show='', status=None, profile=C.PROF_KEY_NONE): | |
337 log.info(u"Profile presence status set to {show}/{status}".format(show=show, status=status)) | |
338 | |
339 def addNote(self, title, message, level): | |
340 """add a note (message which disappear) to root widget's header""" | |
341 self.app.root.addNote(title, message, level) | |
342 | |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
343 def addNotifUI(self, ui): |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
344 """add a notification with a XMLUI attached |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
345 |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
346 @param ui(xmlui.XMLUIPanel): XMLUI instance to show when notification is selected |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
347 """ |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
348 self.app.root.addNotifUI(ui) |
29 | 349 |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
350 def showUI(self, ui): |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
351 self.app.root.changeWidget(ui, "xmlui") |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
352 self.app.root.show("xmlui") |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
353 |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
354 def closeUI(self): |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
355 self.app.root.show() |