annotate src/cagou/core/cagou_main.py @ 61:0b7f10de416e

android: android build first draft: - added buildozer.spec - added src/sat.conf which is the configuration used on android (FIXME: need to rename/move it) - small hack to change loading paths on android - sys.platform is set to android when kivy_utils.platform is set to android - softinput_mode is set to "below_target", so field are not hidden when virtual keyboard appears Note: using org.goffi.cagou instead of org.salut-a-toi.cagou for package domain because the dash ("-") is causing trouble to buildozer. This need to be fixed.
author Goffi <goffi@goffi.org>
date Sun, 04 Dec 2016 18:21:23 +0100
parents 35abe494e6c7
children af4f986d86f0
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 _
48
028a98983e46 core: avoid kivy arguments hijacking so QuickApp arguments parsing can be used
Goffi <goffi@goffi.org>
parents: 44
diff changeset
22 import kivy_hack
028a98983e46 core: avoid kivy arguments hijacking so QuickApp arguments parsing can be used
Goffi <goffi@goffi.org>
parents: 44
diff changeset
23 kivy_hack.do_hack()
6
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__)
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
27 from sat.core import exceptions
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 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
29 from sat_frontends.quick_frontend import quick_widgets
43
12fdc7d1feb1 core: newWidget implementation, it only display a not when a MUC room has been joined
Goffi <goffi@goffi.org>
parents: 41
diff changeset
30 from sat_frontends.quick_frontend import quick_chat
48
028a98983e46 core: avoid kivy arguments hijacking so QuickApp arguments parsing can be used
Goffi <goffi@goffi.org>
parents: 44
diff changeset
31 from sat_frontends.quick_frontend import quick_utils
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
32 from sat.tools import config
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
33 from sat.tools.common import dynamic_import
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 import kivy
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 kivy.require('1.9.1')
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 import kivy.support
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
37 bridge_name = config.getConfig(config.parseMainConf(), '', 'bridge', 'dbus')
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
38 # FIXME: event loop is choosen according to bridge_name, a better way should be used
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
39 if bridge_name == 'embedded':
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
40 kivy.support.install_twisted_reactor()
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
41 else:
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
42 kivy.support.install_gobject_iteration()
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 from kivy.app import App
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
44 from kivy.lang import Builder
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
45 from kivy import properties
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 import xmlui
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 from profile_manager import ProfileManager
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
48 from widgets_handler import WidgetsHandler
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
49 from kivy.clock import Clock
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
50 from kivy.uix.label import Label
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
51 from kivy.uix.boxlayout import BoxLayout
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
52 from kivy.uix.screenmanager import ScreenManager, Screen, FallOutTransition, RiseInTransition
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
53 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
54 from cagou_widget import CagouWidget
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
55 from . import widgets_handler
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
56 from .common import IconButton
51
3f8599d9a766 core: menus first draft:
Goffi <goffi@goffi.org>
parents: 49
diff changeset
57 from .menu import MenusWidget
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
58 from importlib import import_module
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
59 import os.path
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
60 import glob
15
56838ad5c84b files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents: 14
diff changeset
61 import cagou.plugins
56838ad5c84b files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents: 14
diff changeset
62 import cagou.kv
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
63 from sat.core import sat_main
61
0b7f10de416e android: android build first draft:
Goffi <goffi@goffi.org>
parents: 60
diff changeset
64 from kivy import utils as kivy_utils
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
65 import sys
61
0b7f10de416e android: android build first draft:
Goffi <goffi@goffi.org>
parents: 60
diff changeset
66 if kivy_utils.platform == "android":
0b7f10de416e android: android build first draft:
Goffi <goffi@goffi.org>
parents: 60
diff changeset
67 # FIXME: move to separate android module
0b7f10de416e android: android build first draft:
Goffi <goffi@goffi.org>
parents: 60
diff changeset
68 kivy.support.install_android()
0b7f10de416e android: android build first draft:
Goffi <goffi@goffi.org>
parents: 60
diff changeset
69 # sys.platform is "linux" on android by default
0b7f10de416e android: android build first draft:
Goffi <goffi@goffi.org>
parents: 60
diff changeset
70 # so we change it to allow backend to detect android
0b7f10de416e android: android build first draft:
Goffi <goffi@goffi.org>
parents: 60
diff changeset
71 sys.platform = "android"
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
72
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
73
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
74 class NotifsIcon(IconButton):
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
75 notifs = properties.ListProperty()
29
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 on_release(self):
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
78 callback, args, kwargs = self.notifs.pop(0)
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
79 callback(*args, **kwargs)
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
80
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
81 def addNotif(self, callback, *args, **kwargs):
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
82 self.notifs.append((callback, args, kwargs))
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
83
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
84
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
85 class Note(Label):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
86 title = properties.StringProperty()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
87 message = properties.StringProperty()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
88 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
89
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
90
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
91 class NoteDrop(Note):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
92 pass
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
93
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 class NotesDrop(DropDown):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
96 clear_btn = properties.ObjectProperty()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
97
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
98 def __init__(self, notes):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
99 super(NotesDrop, self).__init__()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
100 self.notes = notes
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
101
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
102 def open(self, widget):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
103 self.clear_widgets()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
104 for n in self.notes:
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
105 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
106 self.add_widget(self.clear_btn)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
107 super(NotesDrop, self).open(widget)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
108
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
109
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
110 class RootHeadWidget(BoxLayout):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
111 """Notifications widget"""
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
112 manager = properties.ObjectProperty()
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
113 notifs_icon = properties.ObjectProperty()
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
114 notes = properties.ListProperty()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
115
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
116 def __init__(self):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
117 super(RootHeadWidget, self).__init__()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
118 self.notes_last = None
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
119 self.notes_event = None
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
120 self.notes_drop = NotesDrop(self.notes)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
121
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
122 def addNotif(self, callback, *args, **kwargs):
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
123 self.notifs_icon.addNotif(callback, *args, **kwargs)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
124
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
125 def addNote(self, title, message, level):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
126 note = Note(title=title, message=message, level=level)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
127 self.notes.append(note)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
128 if len(self.notes) > 10:
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
129 del self.notes[:-10]
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
130 if self.notes_event is None:
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
131 self.notes_event = Clock.schedule_interval(self._displayNextNote, 5)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
132 self._displayNextNote()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
133
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
134 def addNotifUI(self, ui):
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
135 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
136
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
137 def _displayNextNote(self, dummy=None):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
138 screen = Screen()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
139 try:
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
140 idx = self.notes.index(self.notes_last) + 1
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
141 except ValueError:
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
142 idx = 0
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
143 try:
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
144 note = self.notes_last = self.notes[idx]
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
145 except IndexError:
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
146 self.notes_event.cancel()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
147 self.notes_event = None
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
148 else:
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
149 screen.add_widget(note)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
150 self.manager.switch_to(screen)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
151
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
152
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
153 class CagouRootWidget(BoxLayout):
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
154
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
155 def __init__(self, main_widget):
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
156 super(CagouRootWidget, self).__init__(orientation=("vertical"))
51
3f8599d9a766 core: menus first draft:
Goffi <goffi@goffi.org>
parents: 49
diff changeset
157 # general menus
3f8599d9a766 core: menus first draft:
Goffi <goffi@goffi.org>
parents: 49
diff changeset
158 self.menus_widget = MenusWidget()
3f8599d9a766 core: menus first draft:
Goffi <goffi@goffi.org>
parents: 49
diff changeset
159 self.add_widget(self.menus_widget)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
160 # header
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
161 self._head_widget = RootHeadWidget()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
162 self.add_widget(self._head_widget)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
163 # body
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
164 self._manager = ScreenManager()
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
165 # main widgets
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
166 main_screen = Screen(name='main')
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
167 main_screen.add_widget(main_widget)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
168 self._manager.add_widget(main_screen)
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
169 # backend XMLUI (popups, forms, etc)
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
170 xmlui_screen = Screen(name='xmlui')
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
171 self._manager.add_widget(xmlui_screen)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
172 self.add_widget(self._manager)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
173
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
174 def changeWidget(self, widget, screen_name="main"):
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
175 """change main widget"""
52
647f32d0a004 core: workaround issue happening when root widget is changed too quickly (during a transition)
Goffi <goffi@goffi.org>
parents: 51
diff changeset
176 if self._manager.transition.is_active:
647f32d0a004 core: workaround issue happening when root widget is changed too quickly (during a transition)
Goffi <goffi@goffi.org>
parents: 51
diff changeset
177 # FIXME: workaround for what seems a Kivy bug
647f32d0a004 core: workaround issue happening when root widget is changed too quickly (during a transition)
Goffi <goffi@goffi.org>
parents: 51
diff changeset
178 # TODO: report this upstream
647f32d0a004 core: workaround issue happening when root widget is changed too quickly (during a transition)
Goffi <goffi@goffi.org>
parents: 51
diff changeset
179 self._manager.transition.stop()
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
180 screen = self._manager.get_screen(screen_name)
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
181 screen.clear_widgets()
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
182 screen.add_widget(widget)
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
183
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
184 def show(self, screen="main"):
52
647f32d0a004 core: workaround issue happening when root widget is changed too quickly (during a transition)
Goffi <goffi@goffi.org>
parents: 51
diff changeset
185 if self._manager.transition.is_active:
647f32d0a004 core: workaround issue happening when root widget is changed too quickly (during a transition)
Goffi <goffi@goffi.org>
parents: 51
diff changeset
186 # FIXME: workaround for what seems a Kivy bug
647f32d0a004 core: workaround issue happening when root widget is changed too quickly (during a transition)
Goffi <goffi@goffi.org>
parents: 51
diff changeset
187 # TODO: report this upstream
647f32d0a004 core: workaround issue happening when root widget is changed too quickly (during a transition)
Goffi <goffi@goffi.org>
parents: 51
diff changeset
188 self._manager.transition.stop()
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
189 if self._manager.current == screen:
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
190 return
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
191 if screen == "main":
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
192 self._manager.transition = FallOutTransition()
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
193 else:
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
194 self._manager.transition = RiseInTransition()
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
195 self._manager.current = screen
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
196
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
197 def newAction(self, handler, action_data, id_, security_limit, profile):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
198 """Add a notification for an action"""
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
199 self._head_widget.addNotif(handler, action_data, id_, security_limit, profile)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
200
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
201 def addNote(self, title, message, level):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
202 self._head_widget.addNote(title, message, level)
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
203
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
204 def addNotifUI(self, ui):
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
205 self._head_widget.addNotifUI(ui)
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
206
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
207
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
208 class CagouApp(App):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
209 """Kivy App for Cagou"""
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
210
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
211 def build(self):
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
212 return CagouRootWidget(Label(text=u"Loading please wait"))
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
213
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
214 def showWidget(self):
49
fd9cbf6ae663 core: postInit() is now called, allowing automatic profile connection
Goffi <goffi@goffi.org>
parents: 48
diff changeset
215 self._profile_manager = ProfileManager()
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
216 self.root.changeWidget(self._profile_manager)
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
217
31
4f9e701d76b4 core: expand now accepts extra arguments, which will be used in format
Goffi <goffi@goffi.org>
parents: 29
diff changeset
218 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
219 """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
220
32
fdaf914e2729 minor docstring fix
Goffi <goffi@goffi.org>
parents: 31
diff changeset
221 useful in kv. Values which can be used:
fdaf914e2729 minor docstring fix
Goffi <goffi@goffi.org>
parents: 31
diff changeset
222 - {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
223 @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
224 @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
225 @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
226 """
31
4f9e701d76b4 core: expand now accepts extra arguments, which will be used in format
Goffi <goffi@goffi.org>
parents: 29
diff changeset
227 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
228
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
229
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
230 class Cagou(QuickApp):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
231 MB_HANDLE = False
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
232
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
233 def __init__(self):
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
234 if bridge_name == 'embedded':
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
235 self.sat = sat_main.SAT()
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
236 bridge_module = dynamic_import.bridge(bridge_name, 'sat_frontends.bridge')
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
237 if bridge_module is None:
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
238 log.error(u"Can't import {} bridge".format(bridge_name))
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
239 sys.exit(1)
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
240 else:
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
241 log.info(u"Loading {} bridge".format(bridge_name))
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
242 super(Cagou, self).__init__(create_bridge=bridge_module.Bridge, xmlui=xmlui, check_options=quick_utils.check_options)
15
56838ad5c84b files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents: 14
diff changeset
243 self._import_kv()
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
244 self.app = CagouApp()
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
245 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
246 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
247 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
248 self._plg_wids = [] # widget plugins
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
249 self._import_plugins()
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
250 self._visible_widgets = {} # visible widgets by classes
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
251
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
252 @property
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
253 def visible_widgets(self):
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
254 for w_list in self._visible_widgets.itervalues():
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
255 for w in w_list:
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
256 yield w
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
257
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
258 def run(self):
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
259 self.bridge.getReady(self.onBackendReady)
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
260 self.app.bind(on_stop=self.onStop)
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
261 self.app.run()
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
262
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
263 def onStop(self, obj):
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
264 try:
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
265 sat_instance = self.sat
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
266 except AttributeError:
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
267 pass
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
268 else:
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
269 sat_instance.stopService()
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
270
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
271 def onBackendReady(self):
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
272 self.app.showWidget()
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
273 self.postInit()
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
274
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
275 def postInit(self, dummy=None):
61
0b7f10de416e android: android build first draft:
Goffi <goffi@goffi.org>
parents: 60
diff changeset
276 # FIXME: resize seem to bug on android, so we use below_target for now
0b7f10de416e android: android build first draft:
Goffi <goffi@goffi.org>
parents: 60
diff changeset
277 self.app.root_window.softinput_mode = "below_target"
49
fd9cbf6ae663 core: postInit() is now called, allowing automatic profile connection
Goffi <goffi@goffi.org>
parents: 48
diff changeset
278 profile_manager = self.app._profile_manager
fd9cbf6ae663 core: postInit() is now called, allowing automatic profile connection
Goffi <goffi@goffi.org>
parents: 48
diff changeset
279 del self.app._profile_manager
fd9cbf6ae663 core: postInit() is now called, allowing automatic profile connection
Goffi <goffi@goffi.org>
parents: 48
diff changeset
280 super(Cagou, self).postInit(profile_manager)
fd9cbf6ae663 core: postInit() is now called, allowing automatic profile connection
Goffi <goffi@goffi.org>
parents: 48
diff changeset
281
16
ba14b596b90e host can now be get as a global value:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
282 def _defaultFactory(self, plugin_info, target, profiles):
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
283 """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
284 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
285 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
286
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
287 ## plugins & kv import ##
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
288
15
56838ad5c84b files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents: 14
diff changeset
289 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
290 """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
291 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
292 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
293 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
294 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
295
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
296 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
297 """import all plugins"""
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
298 self.default_wid = None
61
0b7f10de416e android: android build first draft:
Goffi <goffi@goffi.org>
parents: 60
diff changeset
299 if sys.platform == "android":
0b7f10de416e android: android build first draft:
Goffi <goffi@goffi.org>
parents: 60
diff changeset
300 # FIXME: android hack, need to be moved to separate file
0b7f10de416e android: android build first draft:
Goffi <goffi@goffi.org>
parents: 60
diff changeset
301 plugins_path = "/data/data/org.goffi.cagou.cagou/files/cagou/plugins"
0b7f10de416e android: android build first draft:
Goffi <goffi@goffi.org>
parents: 60
diff changeset
302 plugin_glob = "plugin*.pyo"
0b7f10de416e android: android build first draft:
Goffi <goffi@goffi.org>
parents: 60
diff changeset
303 else:
0b7f10de416e android: android build first draft:
Goffi <goffi@goffi.org>
parents: 60
diff changeset
304 plugins_path = os.path.dirname(cagou.plugins.__file__)
0b7f10de416e android: android build first draft:
Goffi <goffi@goffi.org>
parents: 60
diff changeset
305 plugin_glob = "plugin*.py"
0b7f10de416e android: android build first draft:
Goffi <goffi@goffi.org>
parents: 60
diff changeset
306 plug_lst = [os.path.splitext(p)[0] for p in map(os.path.basename, glob.glob(os.path.join(plugins_path, plugin_glob)))]
0b7f10de416e android: android build first draft:
Goffi <goffi@goffi.org>
parents: 60
diff changeset
307
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
308 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
309 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
310 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
311 mod = import_module(plugin_path)
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
312 try:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
313 plugin_info = mod.PLUGIN_INFO
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
314 except AttributeError:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
315 plugin_info = {}
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
316
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
317 # import name is used to differentiate plugins
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
318 if 'import_name' not in plugin_info:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
319 plugin_info['import_name'] = plug
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
320 if 'import_name' in imported_names:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
321 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
322 continue
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
323 if plugin_info['import_name'] == C.WID_SELECTOR:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
324 # if WidgetSelector exists, it will be our default widget
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
325 self.default_wid = plugin_info
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
326
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
327 # we want everything optional, so we use plugin file name
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
328 # if actual name is not found
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
329 if 'name' not in plugin_info:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
330 plugin_info['name'] = plug[plug.rfind('_')+1:]
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
331
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
332 # we need to load the kv file
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
333 if 'kv_file' not in plugin_info:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
334 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
335 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
336 Builder.load_file(kv_path)
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
337
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
338 # what is the main class ?
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
339 main_cls = getattr(mod, plugin_info['main'])
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
340 plugin_info['main'] = main_cls
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
341
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
342 # factory is used to create the instance
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
343 # if not found, we use a defaut one with getOrCreateWidget
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
344 if 'factory' not in plugin_info:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
345 plugin_info['factory'] = self._defaultFactory
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
346
25
d09bd16dbbe2 code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents: 19
diff changeset
347 # icons
d09bd16dbbe2 code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents: 19
diff changeset
348 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
349 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
350 try:
d09bd16dbbe2 code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents: 19
diff changeset
351 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
352 except KeyError:
d09bd16dbbe2 code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents: 19
diff changeset
353 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
354 else:
d09bd16dbbe2 code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents: 19
diff changeset
355 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
356 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
357 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
358 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
359
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
360 self._plg_wids.append(plugin_info)
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
361 if not self._plg_wids:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
362 log.error(_(u"no widget plugin found"))
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
363 return
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
364
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
365 # we want widgets sorted by names
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
366 self._plg_wids.sort(key=lambda p: p['name'].lower())
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
367
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
368 if self.default_wid is None:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
369 # 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
370 self.default_wid = self._plg_wids[0]
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
371
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
372 def getPluggedWidgets(self, except_cls=None):
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
373 """get available widgets plugin infos
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
374
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
375 @param except_cls(None, class): if not None,
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
376 widgets from this class will be excluded
41
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
377 @return (iter[dict]): available widgets plugin infos
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
378 """
19
c58b522607f4 main: fixed profiles value in _defaultFactory + getPluggedWidgets is now a generator
Goffi <goffi@goffi.org>
parents: 16
diff changeset
379 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
380 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
381 continue
c58b522607f4 main: fixed profiles value in _defaultFactory + getPluggedWidgets is now a generator
Goffi <goffi@goffi.org>
parents: 16
diff changeset
382 yield plugin_data
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
383
41
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
384 def getPluginInfo(self, **kwargs):
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
385 """get first plugin info corresponding to filters
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
386
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
387 @param **kwargs: filter(s) to use, each key present here must also
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
388 exist and be of the same value in requested plugin info
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
389 @return (dict, None): found plugin info or None
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
390 """
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
391 for plugin_info in self._plg_wids:
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
392 for k, w in kwargs.iteritems():
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
393 try:
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
394 if plugin_info[k] != w:
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
395 continue
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
396 except KeyError:
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
397 continue
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
398 return plugin_info
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
399
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
400 ## widgets handling
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
401
43
12fdc7d1feb1 core: newWidget implementation, it only display a not when a MUC room has been joined
Goffi <goffi@goffi.org>
parents: 41
diff changeset
402 def newWidget(self, widget):
12fdc7d1feb1 core: newWidget implementation, it only display a not when a MUC room has been joined
Goffi <goffi@goffi.org>
parents: 41
diff changeset
403 log.debug(u"new widget created: {}".format(widget))
12fdc7d1feb1 core: newWidget implementation, it only display a not when a MUC room has been joined
Goffi <goffi@goffi.org>
parents: 41
diff changeset
404 if isinstance(widget, quick_chat.QuickChat) and widget.type == C.CHAT_GROUP:
12fdc7d1feb1 core: newWidget implementation, it only display a not when a MUC room has been joined
Goffi <goffi@goffi.org>
parents: 41
diff changeset
405 self.addNote(u"", _(u"room {} has been joined").format(widget.target))
12fdc7d1feb1 core: newWidget implementation, it only display a not when a MUC room has been joined
Goffi <goffi@goffi.org>
parents: 41
diff changeset
406
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
407 def getParentHandler(self, widget):
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
408 """Return handler holding this widget
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
409
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
410 @return (WidgetsHandler): handler
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
411 """
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
412 w_handler = widget.parent
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
413 while w_handler and not(isinstance(w_handler, widgets_handler.WidgetsHandler)):
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
414 w_handler = w_handler.parent
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
415 return w_handler
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
416
11
49d30fc15884 core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents: 9
diff changeset
417 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
418 """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
419
49d30fc15884 core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents: 9
diff changeset
420 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
421 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
422 """
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
423 to_change = None
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
424 if isinstance(old, CagouWidget):
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
425 to_change = old
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
426 else:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
427 for w in old.walk_reverse():
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
428 if isinstance(w, CagouWidget):
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
429 to_change = w
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
430 break
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
431
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
432 if to_change is None:
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
433 raise exceptions.InternalError(u"no CagouWidget found when trying to switch widget")
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
434 handler = self.getParentHandler(to_change)
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
435 handler.changeWidget(new)
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
436
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
437 def addVisibleWidget(self, widget):
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
438 """declare a widget visible
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
439
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
440 for internal use only!
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
441 """
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
442 assert isinstance(widget, quick_widgets.QuickWidget)
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
443 self._visible_widgets.setdefault(widget.__class__, []).append(widget)
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
444
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
445 def removeVisibleWidget(self, widget):
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
446 """declare a widget not visible anymore
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
447
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
448 for internal use only!
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
449 """
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
450 self._visible_widgets[widget.__class__].remove(widget)
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
451 self.widgets.deleteWidget(widget)
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
452
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
453 def getVisibleList(self, cls):
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
454 """get list of visible widgets for a given class
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
455
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
456 @param cls(QuickWidget class): type of widgets to get
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
457 @return (list[QuickWidget class]): visible widgets of this class
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
458 """
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
459 try:
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
460 return self._visible_widgets[cls]
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
461 except KeyError:
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
462 return []
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
463
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
464 def getOrClone(self, widget):
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
465 """Get a QuickWidget if it has not parent set else clone it"""
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
466 if widget.parent is None:
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
467 return widget
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
468 targets = list(widget.targets)
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
469 w = self.widgets.getOrCreateWidget(widget.__class__, targets[0], on_new_widget=None, on_existing_widget=C.WIDGET_RECREATE, profiles=widget.profiles)
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
470 for t in targets[1:]:
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
471 w.addTarget(t)
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
472 return w
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
473
51
3f8599d9a766 core: menus first draft:
Goffi <goffi@goffi.org>
parents: 49
diff changeset
474 ## menus ##
3f8599d9a766 core: menus first draft:
Goffi <goffi@goffi.org>
parents: 49
diff changeset
475
3f8599d9a766 core: menus first draft:
Goffi <goffi@goffi.org>
parents: 49
diff changeset
476 def _getMenusCb(self, backend_menus):
3f8599d9a766 core: menus first draft:
Goffi <goffi@goffi.org>
parents: 49
diff changeset
477 main_menu = self.app.root.menus_widget
3f8599d9a766 core: menus first draft:
Goffi <goffi@goffi.org>
parents: 49
diff changeset
478 self.menus.addMenus(backend_menus)
3f8599d9a766 core: menus first draft:
Goffi <goffi@goffi.org>
parents: 49
diff changeset
479 self.menus.addMenu(C.MENU_GLOBAL, (_(u"Help"), _(u"About")), callback=main_menu.onAbout)
3f8599d9a766 core: menus first draft:
Goffi <goffi@goffi.org>
parents: 49
diff changeset
480 main_menu.update(C.MENU_GLOBAL)
3f8599d9a766 core: menus first draft:
Goffi <goffi@goffi.org>
parents: 49
diff changeset
481
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
482 ## misc ##
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
483
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
484 def plugging_profiles(self):
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
485 self.app.root.changeWidget(WidgetsHandler())
51
3f8599d9a766 core: menus first draft:
Goffi <goffi@goffi.org>
parents: 49
diff changeset
486 self.bridge.getMenus("", C.NO_SECURITY_LIMIT, callback=self._getMenusCb)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
487
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
488 def setPresenceStatus(self, show='', status=None, profile=C.PROF_KEY_NONE):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
489 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
490
43
12fdc7d1feb1 core: newWidget implementation, it only display a not when a MUC room has been joined
Goffi <goffi@goffi.org>
parents: 41
diff changeset
491 def addNote(self, title, message, level=C.XMLUI_DATA_LVL_INFO):
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
492 """add a note (message which disappear) to root widget's header"""
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
493 self.app.root.addNote(title, message, level)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
494
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
495 def addNotifUI(self, ui):
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
496 """add a notification with a XMLUI attached
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
497
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
498 @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
499 """
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
500 self.app.root.addNotifUI(ui)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
501
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
502 def showUI(self, ui):
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
503 self.app.root.changeWidget(ui, "xmlui")
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
504 self.app.root.show("xmlui")
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
505
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
506 def closeUI(self):
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
507 self.app.root.show()
44
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 43
diff changeset
508
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 43
diff changeset
509 def getDefaultAvatar(self, entity=None):
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 43
diff changeset
510 return self.app.default_avatar
61
0b7f10de416e android: android build first draft:
Goffi <goffi@goffi.org>
parents: 60
diff changeset
511
0b7f10de416e android: android build first draft:
Goffi <goffi@goffi.org>
parents: 60
diff changeset
512 def showDialog(self, message, title, type="info", answer_cb=None, answer_data=None):
0b7f10de416e android: android build first draft:
Goffi <goffi@goffi.org>
parents: 60
diff changeset
513 # TODO
0b7f10de416e android: android build first draft:
Goffi <goffi@goffi.org>
parents: 60
diff changeset
514 log.info(u"FIXME: showDialog not implemented")
0b7f10de416e android: android build first draft:
Goffi <goffi@goffi.org>
parents: 60
diff changeset
515 log.info(u"message: {} -- {}".format(title, message))