Mercurial > libervia-desktop-kivy
annotate src/cagou.py @ 11:49d30fc15884
core: added switchWidget method, to change a CagouWidget for an other one
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 08 Jul 2016 20:17:52 +0200 |
parents | 7b0a53d2afd3 |
children | 30f6586f904b |
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 | |
6
85649eca9f9b
core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
21 import logging_setter |
85649eca9f9b
core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
22 logging_setter.set_logging() |
85649eca9f9b
core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
23 from constants import Const as C |
0 | 24 from sat.core import log as logging |
25 log = logging.getLogger(__name__) | |
26 from sat_frontends.quick_frontend.quick_app import QuickApp | |
27 from sat_frontends.bridge.DBus import DBusBridgeFrontend | |
28 # from sat_frontends.quick_frontend import quick_utils | |
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 | |
34 import xmlui | |
35 from profile_manager import ProfileManager | |
9 | 36 from contact_list import ContactList |
37 from kivy.uix.boxlayout import BoxLayout | |
11
49d30fc15884
core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
38 from cagou_widget import CagouWidget |
9 | 39 import os.path |
40 | |
41 | |
42 class CagouRootWidget(BoxLayout): | |
43 | |
44 def __init__(self, widgets): | |
45 super(CagouRootWidget, self).__init__(orientation=("vertical")) | |
46 for wid in widgets: | |
47 self.add_widget(wid) | |
48 | |
49 def change_widgets(self, widgets): | |
50 self.clear_widgets() | |
51 for wid in widgets: | |
52 self.add_widget(wid) | |
0 | 53 |
54 | |
55 class CagouApp(App): | |
56 """Kivy App for Cagou""" | |
57 | |
58 def build(self): | |
9 | 59 return CagouRootWidget([ProfileManager(self.host)]) |
0 | 60 |
61 | |
62 class Cagou(QuickApp): | |
63 MB_HANDLE = False | |
64 | |
65 def __init__(self): | |
66 super(Cagou, self).__init__(create_bridge=DBusBridgeFrontend, xmlui=xmlui) | |
67 self.app = CagouApp() | |
68 self.app.host = self | |
9 | 69 media_dir = self.app.media_dir = self.bridge.getConfig("", "media_dir") |
70 self.app.default_avatar = os.path.join(media_dir, "misc/default_avatar.png") | |
0 | 71 |
72 def run(self): | |
73 self.app.run() | |
74 | |
9 | 75 def plugging_profiles(self): |
76 contact_list = self.widgets.getOrCreateWidget(ContactList, None, on_new_widget=None) | |
77 self.app.root.change_widgets([contact_list]) | |
78 | |
79 def setPresenceStatus(self, show='', status=None, profile=C.PROF_KEY_NONE): | |
80 log.info(u"Profile presence status set to {show}/{status}".format(show=show, status=status)) | |
81 | |
11
49d30fc15884
core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
82 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
|
83 """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
|
84 |
49d30fc15884
core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
85 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
|
86 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
|
87 """ |
49d30fc15884
core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
88 for w in old.walk_reverse(): |
49d30fc15884
core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
89 if isinstance(w, CagouWidget): |
49d30fc15884
core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
90 parent = w.parent |
49d30fc15884
core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
91 idx = parent.children.index(w) |
49d30fc15884
core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
92 parent.remove_widget(w) |
49d30fc15884
core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
93 parent.add_widget(new, index=idx) |
49d30fc15884
core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
94 break |
49d30fc15884
core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
95 |
0 | 96 |
97 if __name__ == '__main__': | |
98 Cagou().run() |