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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 # Copyright (C) 2016 Jérôme Poisson (goffi@goffi.org)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
20
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
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
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from sat.core import log as logging
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 log = logging.getLogger(__name__)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from sat_frontends.quick_frontend.quick_app import QuickApp
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from sat_frontends.bridge.DBus import DBusBridgeFrontend
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 import kivy
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 kivy.require('1.9.1')
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 import kivy.support
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 kivy.support.install_gobject_iteration()
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 from kivy.app import App
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
34 from kivy.lang import Builder
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
35 from kivy import properties
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 import xmlui
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 from profile_manager import ProfileManager
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
38 from widgets_handler import WidgetsHandler
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
39 from kivy.clock import Clock
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
40 from kivy.uix.label import Label
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
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
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
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
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
45 from .common import IconButton
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
46 from importlib import import_module
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
47 import os.path
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
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
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
51
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
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
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
55
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
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
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
62
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
63
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
64 class Note(Label):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
65 title = properties.StringProperty()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
66 message = properties.StringProperty()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
67 level = properties.OptionProperty(C.XMLUI_DATA_LVL_DEFAULT, options=list(C.XMLUI_DATA_LVLS))
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
68
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
69
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
70 class NoteDrop(Note):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
71 pass
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
72
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
73
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
74 class NotesDrop(DropDown):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
75 clear_btn = properties.ObjectProperty()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
76
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
77 def __init__(self, notes):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
78 super(NotesDrop, self).__init__()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
79 self.notes = notes
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
80
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
81 def open(self, widget):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
82 self.clear_widgets()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
83 for n in self.notes:
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
84 self.add_widget(NoteDrop(title=n.title, message=n.message, level=n.level))
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
85 self.add_widget(self.clear_btn)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
86 super(NotesDrop, self).open(widget)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
87
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
88
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
89 class RootHeadWidget(BoxLayout):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
90 """Notifications widget"""
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
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
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
93 notes = properties.ListProperty()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
94
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
95 def __init__(self):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
96 super(RootHeadWidget, self).__init__()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
97 self.notes_last = None
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
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
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
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
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
103
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
104 def addNote(self, title, message, level):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
105 note = Note(title=title, message=message, level=level)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
106 self.notes.append(note)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
107 if len(self.notes) > 10:
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
108 del self.notes[:-10]
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
109 if self.notes_event is None:
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
110 self.notes_event = Clock.schedule_interval(self._displayNextNote, 5)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
111 self._displayNextNote()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
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
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
116 def _displayNextNote(self, dummy=None):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
117 screen = Screen()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
118 try:
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
119 idx = self.notes.index(self.notes_last) + 1
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
120 except ValueError:
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
121 idx = 0
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
122 try:
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
123 note = self.notes_last = self.notes[idx]
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
124 except IndexError:
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
125 self.notes_event.cancel()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
126 self.notes_event = None
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
127 else:
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
128 screen.add_widget(note)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
129 self.manager.switch_to(screen)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
130
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
131
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
132 class CagouRootWidget(BoxLayout):
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
133
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
134 def __init__(self, main_widget):
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
135 super(CagouRootWidget, self).__init__(orientation=("vertical"))
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
136 # header
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
137 self._head_widget = RootHeadWidget()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
138 self.add_widget(self._head_widget)
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
139
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
140 # body
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
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
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
143 main_screen = Screen(name='main')
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
144 main_screen.add_widget(main_widget)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
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
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
149 self.add_widget(self._manager)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
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
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
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
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
165
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
166 def newAction(self, handler, action_data, id_, security_limit, profile):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
167 """Add a notification for an action"""
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
168 self._head_widget.addNotif(handler, action_data, id_, security_limit, profile)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
169
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
170 def addNote(self, title, message, level):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
171 self._head_widget.addNote(title, message, level)
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
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
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
176
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 class CagouApp(App):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 """Kivy App for Cagou"""
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
179
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
180 def build(self):
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
181 return CagouRootWidget(ProfileManager())
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
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
fdaf914e2729 minor docstring fix
Goffi <goffi@goffi.org>
parents: 31
diff changeset
186 useful in kv. Values which can be used:
fdaf914e2729 minor docstring fix
Goffi <goffi@goffi.org>
parents: 31
diff changeset
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
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
194
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
195 class Cagou(QuickApp):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
196 MB_HANDLE = False
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
197
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
198 def __init__(self):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
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
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
201 self.app = CagouApp()
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
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
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
205 self._plg_wids = [] # widget plugins
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
206 self._import_plugins()
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
207
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
208 def run(self):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
209 self.app.run()
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
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
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
212 """factory used to create widget instance when PLUGIN_INFO["factory"] is not set"""
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
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
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
215
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
216 ## plugins & kv import ##
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
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
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
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
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
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
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
229 plug_lst = [os.path.splitext(p)[0] for p in map(os.path.basename, glob.glob(os.path.join(plugins_path, "plugin*.py")))]
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
230 imported_names = set() # use to avoid loading 2 times plugin with same import name
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
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
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
234 try:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
235 plugin_info = mod.PLUGIN_INFO
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
236 except AttributeError:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
237 plugin_info = {}
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
238
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
239 # import name is used to differentiate plugins
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
240 if 'import_name' not in plugin_info:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
241 plugin_info['import_name'] = plug
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
242 if 'import_name' in imported_names:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
243 log.warning(_(u"there is already a plugin named {}, ignoring new one").format(plugin_info['import_name']))
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
244 continue
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
245 if plugin_info['import_name'] == C.WID_SELECTOR:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
246 # if WidgetSelector exists, it will be our default widget
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
247 self.default_wid = plugin_info
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
248
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
249 # we want everything optional, so we use plugin file name
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
250 # if actual name is not found
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
251 if 'name' not in plugin_info:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
252 plugin_info['name'] = plug[plug.rfind('_')+1:]
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
253
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
254 # we need to load the kv file
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
255 if 'kv_file' not in plugin_info:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
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
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
259
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
260 # what is the main class ?
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
261 main_cls = getattr(mod, plugin_info['main'])
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
262 plugin_info['main'] = main_cls
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
263
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
264 # factory is used to create the instance
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
265 # if not found, we use a defaut one with getOrCreateWidget
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
266 if 'factory' not in plugin_info:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
267 plugin_info['factory'] = self._defaultFactory
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
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
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
282 self._plg_wids.append(plugin_info)
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
283 if not self._plg_wids:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
284 log.error(_(u"no widget plugin found"))
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
285 return
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
286
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
287 # we want widgets sorted by names
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
288 self._plg_wids.sort(key=lambda p: p['name'].lower())
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
289
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
290 if self.default_wid is None:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
291 # we have no selector widget, we use the first widget as default
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
292 self.default_wid = self._plg_wids[0]
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
293
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
294 def getPluggedWidgets(self, except_cls=None):
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
295 """get available widgets plugin infos
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
296
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
297 @param except_cls(None, class): if not None,
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
298 widgets from this class will be excluded
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
299 @return (list[dict]): available widgets plugin infos
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
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
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
305
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
306 ## widgets handling
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
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
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
314 to_change = None
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
315 if isinstance(old, CagouWidget):
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
316 to_change = old
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
317 else:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
318 for w in old.walk_reverse():
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
319 if isinstance(w, CagouWidget):
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
320 to_change = w
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
321 break
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
322
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
323 if to_change is None:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
324 log.error(u"no CagouWidget found when trying to switch widget")
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
325 else:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
326 parent = to_change.parent
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
327 idx = parent.children.index(to_change)
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
328 parent.remove_widget(to_change)
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
329 parent.add_widget(new, index=idx)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
330
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
331 ## misc ##
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
332
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
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
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
335
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
336 def setPresenceStatus(self, show='', status=None, profile=C.PROF_KEY_NONE):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
337 log.info(u"Profile presence status set to {show}/{status}".format(show=show, status=status))
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
338
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
339 def addNote(self, title, message, level):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
340 """add a note (message which disappear) to root widget's header"""
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
341 self.app.root.addNote(title, message, level)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
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
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
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()