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