annotate src/cagou.py @ 13:12a189fbb9ba

widget handler first draft: This widget handle other widgets location and size. It is currently loosely inspired from Blender's UI, and the implementation is currenlty naïve. It should be updated in the future to have a behaviour more close to Blender one.
author Goffi <goffi@goffi.org>
date Fri, 08 Jul 2016 20:18:43 +0200
parents 30f6586f904b
children 21a432afd06d
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
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
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from sat.core import log as logging
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 log = logging.getLogger(__name__)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from sat_frontends.quick_frontend.quick_app import QuickApp
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from sat_frontends.bridge.DBus import DBusBridgeFrontend
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 # from sat_frontends.quick_frontend import quick_utils
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
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 import xmlui
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 from profile_manager import ProfileManager
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
36 from widgets_handler import WidgetsHandler
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
37 from kivy.uix.boxlayout import BoxLayout
12
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents: 11
diff changeset
38 from widget_selector import WidgetSelector
11
49d30fc15884 core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents: 9
diff changeset
39 from cagou_widget import CagouWidget
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
40 import os.path
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
41
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
42
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
43 class CagouRootWidget(BoxLayout):
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
44
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
45 def __init__(self, widgets):
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
46 super(CagouRootWidget, self).__init__(orientation=("vertical"))
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
47 for wid in widgets:
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
48 self.add_widget(wid)
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
49
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
50 def change_widgets(self, widgets):
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
51 self.clear_widgets()
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
52 for wid in widgets:
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
53 self.add_widget(wid)
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
54
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
55
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 class CagouApp(App):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 """Kivy App for Cagou"""
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
58
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 def build(self):
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
60 return CagouRootWidget([ProfileManager(self.host)])
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
61
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
62
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 class Cagou(QuickApp):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 MB_HANDLE = False
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
65
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 def __init__(self):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 super(Cagou, self).__init__(create_bridge=DBusBridgeFrontend, xmlui=xmlui)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 self.app = CagouApp()
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 self.app.host = self
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
70 media_dir = self.app.media_dir = self.bridge.getConfig("", "media_dir")
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
71 self.app.default_avatar = os.path.join(media_dir, "misc/default_avatar.png")
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
72
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 def run(self):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 self.app.run()
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
75
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
76 def plugging_profiles(self):
12
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents: 11
diff changeset
77 widget_selector = WidgetSelector(self)
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
78 self.app.root.change_widgets([WidgetsHandler(self, widget_selector)])
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
79
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
80 def setPresenceStatus(self, show='', status=None, profile=C.PROF_KEY_NONE):
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
81 log.info(u"Profile presence status set to {show}/{status}".format(show=show, status=status))
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
82
11
49d30fc15884 core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents: 9
diff changeset
83 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
84 """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
85
49d30fc15884 core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents: 9
diff changeset
86 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
87 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
88 """
49d30fc15884 core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents: 9
diff changeset
89 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
90 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
91 parent = w.parent
49d30fc15884 core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents: 9
diff changeset
92 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
93 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
94 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
95 break
49d30fc15884 core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents: 9
diff changeset
96
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
97
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 if __name__ == '__main__':
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 Cagou().run()