annotate cagou/core/cagou_main.py @ 353:19422bbd9c8e

core (widgets handler): refactoring: - CagouWidget now has class properties (to be overridden when needed) which indicate how if the widget handle must add a wrapping ScreenManager (global_screen_manager) or show all instances of the class in a Carousel (collection_carousel). If none of those options is used, a ScrollView will be wrapping the widget, to be sure that the widget will be resized correctly when necessary (without it, the widget could still be drawn in the backround when the size is too small and overflow on the WidgetWrapper, this would be the case with WidgetSelector) - some helper methods/properties have been added to CagouWidget. Check docstrings for details - better handling of (in)visible widget in WidgetsHandler - thanks to the new wrapping ScrollView, WidgetSelect will show scroll bars if the available space is too small. - bugs fixes
author Goffi <goffi@goffi.org>
date Fri, 17 Jan 2020 18:44:35 +0100
parents 434f770fe55b
children 307c2501d8b2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1 #!/usr/bin/env python3
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client
282
1b835bcfa663 date update
Goffi <goffi@goffi.org>
parents: 281
diff changeset
4 # Copyright (C) 2016-2019 Jérôme Poisson (goffi@goffi.org)
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
5
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
285
3f7e227aab00 core: disable multitouch emulation with mouse
Goffi <goffi@goffi.org>
parents: 284
diff changeset
20 import os.path
3f7e227aab00 core: disable multitouch emulation with mouse
Goffi <goffi@goffi.org>
parents: 284
diff changeset
21 import glob
3f7e227aab00 core: disable multitouch emulation with mouse
Goffi <goffi@goffi.org>
parents: 284
diff changeset
22 import sys
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
23 from sat.core.i18n import _
119
1bbbe26846f4 buildozer: moved sat.conf in a specific dir (platform/android), so it's not used on desktop
Goffi <goffi@goffi.org>
parents: 112
diff changeset
24 from . import kivy_hack
48
028a98983e46 core: avoid kivy arguments hijacking so QuickApp arguments parsing can be used
Goffi <goffi@goffi.org>
parents: 44
diff changeset
25 kivy_hack.do_hack()
323
5bd583d00594 backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
26 from cagou.backport import do_backport
5bd583d00594 backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
27 do_backport()
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
28 from .constants import Const as C
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from sat.core import log as logging
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
30 from sat.core import exceptions
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 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
32 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
33 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
34 from sat_frontends.quick_frontend import quick_utils
244
5bd94bc08f5c plugin chat: fixed OTR State filtering + removed some legacy code
Goffi <goffi@goffi.org>
parents: 240
diff changeset
35 from sat_frontends.tools import jid
302
f55b60659ec1 core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents: 298
diff changeset
36 from sat.tools import utils as sat_utils
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
37 from sat.tools import config
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
38 from sat.tools.common import dynamic_import
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 import kivy
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
40 kivy.require('1.11.0')
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 import kivy.support
63
af4f986d86f0 core: pb bridge implementation:
Goffi <goffi@goffi.org>
parents: 61
diff changeset
42 main_config = config.parseMainConf()
af4f986d86f0 core: pb bridge implementation:
Goffi <goffi@goffi.org>
parents: 61
diff changeset
43 bridge_name = config.getConfig(main_config, '', 'bridge', 'dbus')
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
44 # FIXME: event loop is choosen according to bridge_name, a better way should be used
63
af4f986d86f0 core: pb bridge implementation:
Goffi <goffi@goffi.org>
parents: 61
diff changeset
45 if 'dbus' in bridge_name:
af4f986d86f0 core: pb bridge implementation:
Goffi <goffi@goffi.org>
parents: 61
diff changeset
46 kivy.support.install_gobject_iteration()
af4f986d86f0 core: pb bridge implementation:
Goffi <goffi@goffi.org>
parents: 61
diff changeset
47 elif bridge_name in ('pb', 'embedded'):
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
48 kivy.support.install_twisted_reactor()
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 from kivy.app import App
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
50 from kivy.lang import Builder
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
51 from kivy import properties
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
52 from . import xmlui
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
53 from .profile_manager import ProfileManager
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
54 from kivy.clock import Clock
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
55 from kivy.uix.label import Label
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
56 from kivy.uix.boxlayout import BoxLayout
85
c2a7234d13d2 menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents: 78
diff changeset
57 from kivy.uix.floatlayout import FloatLayout
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
58 from kivy.uix.screenmanager import (ScreenManager, Screen,
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
59 FallOutTransition, RiseInTransition)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
60 from kivy.uix.dropdown import DropDown
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
61 from kivy.uix.behaviors import ButtonBehavior
166
37220459e93d core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents: 165
diff changeset
62 from kivy.core.window import Window
37220459e93d core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents: 165
diff changeset
63 from kivy.animation import Animation
37220459e93d core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents: 165
diff changeset
64 from kivy.metrics import dp
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
65 from .cagou_widget import CagouWidget
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
66 from .share_widget import ShareWidget
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
67 from . import widgets_handler
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
68 from .common import IconButton
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
69 from . import menu
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
70 from . import dialog
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
71 from importlib import import_module
302
f55b60659ec1 core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents: 298
diff changeset
72 import sat
f55b60659ec1 core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents: 298
diff changeset
73 import cagou
15
56838ad5c84b files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents: 14
diff changeset
74 import cagou.plugins
56838ad5c84b files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents: 14
diff changeset
75 import cagou.kv
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
76
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
77
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
78 log = logging.getLogger(__name__)
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
79
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
80
184
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 176
diff changeset
81 try:
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 176
diff changeset
82 from plyer import notification
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 176
diff changeset
83 except ImportError:
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 176
diff changeset
84 notification = None
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
85 log.warning(_("Can't import plyer, some features disabled"))
131
36fc269e2a32 core: changed default background color to white
Goffi <goffi@goffi.org>
parents: 130
diff changeset
86
286
4772ba26623f xmlui: many improvments:
Goffi <goffi@goffi.org>
parents: 285
diff changeset
87
4772ba26623f xmlui: many improvments:
Goffi <goffi@goffi.org>
parents: 285
diff changeset
88 ## platform specific settings ##
4772ba26623f xmlui: many improvments:
Goffi <goffi@goffi.org>
parents: 285
diff changeset
89
342
89799148f894 core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents: 331
diff changeset
90 from . import platform_
89799148f894 core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents: 331
diff changeset
91 local_platform = platform_.create()
89799148f894 core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents: 331
diff changeset
92 local_platform.init_platform()
259
4601793b0dee core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents: 250
diff changeset
93
4601793b0dee core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents: 250
diff changeset
94
286
4772ba26623f xmlui: many improvments:
Goffi <goffi@goffi.org>
parents: 285
diff changeset
95 ## General Configuration ##
4772ba26623f xmlui: many improvments:
Goffi <goffi@goffi.org>
parents: 285
diff changeset
96
259
4601793b0dee core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents: 250
diff changeset
97 # we want white background by default
4601793b0dee core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents: 250
diff changeset
98 Window.clearcolor = (1, 1, 1, 1)
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
99
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
100
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
101 class NotifsIcon(IconButton):
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
102 notifs = properties.ListProperty()
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
103
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
104 def on_release(self):
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
105 callback, args, kwargs = self.notifs.pop(0)
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
106 callback(*args, **kwargs)
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
107
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
108 def addNotif(self, callback, *args, **kwargs):
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
109 self.notifs.append((callback, args, kwargs))
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
110
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
111
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
112 class Note(Label):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
113 title = properties.StringProperty()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
114 message = properties.StringProperty()
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
115 level = properties.OptionProperty(C.XMLUI_DATA_LVL_DEFAULT,
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
116 options=list(C.XMLUI_DATA_LVLS))
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
117 symbol = properties.StringProperty()
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
118 action = properties.ObjectProperty()
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
119
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
120
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
121 class NoteDrop(ButtonBehavior, BoxLayout):
208
c5c1dd7f88e1 root widget: improved notes:
Goffi <goffi@goffi.org>
parents: 190
diff changeset
122 title = properties.StringProperty()
c5c1dd7f88e1 root widget: improved notes:
Goffi <goffi@goffi.org>
parents: 190
diff changeset
123 message = properties.StringProperty()
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
124 level = properties.OptionProperty(C.XMLUI_DATA_LVL_DEFAULT,
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
125 options=list(C.XMLUI_DATA_LVLS))
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
126 symbol = properties.StringProperty()
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
127 action = properties.ObjectProperty()
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
128
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
129 def on_press(self):
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
130 if self.action is not None:
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
131 self.parent.parent.select(self.action)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
132
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
133
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
134 class NotesDrop(DropDown):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
135 clear_btn = properties.ObjectProperty()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
136
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
137 def __init__(self, notes):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
138 super(NotesDrop, self).__init__()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
139 self.notes = notes
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
140
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
141 def open(self, widget):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
142 self.clear_widgets()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
143 for n in self.notes:
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
144 kwargs = {
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
145 'title': n.title,
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
146 'message': n.message,
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
147 'level': n.level
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
148 }
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
149 if n.symbol is not None:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
150 kwargs['symbol'] = n.symbol
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
151 if n.action is not None:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
152 kwargs['action'] = n.action
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
153 self.add_widget(NoteDrop(title=n.title, message=n.message, level=n.level,
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
154 symbol=n.symbol, action=n.action))
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
155 self.add_widget(self.clear_btn)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
156 super(NotesDrop, self).open(widget)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
157
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
158 def on_select(self, action_kwargs):
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
159 app = App.get_running_app()
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
160 app.host.doAction(**action_kwargs)
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
161
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
162
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
163 class RootHeadWidget(BoxLayout):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
164 """Notifications widget"""
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
165 manager = properties.ObjectProperty()
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
166 notifs_icon = properties.ObjectProperty()
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
167 notes = properties.ListProperty()
172
7103655647aa core: hide notifications header on M-n
Goffi <goffi@goffi.org>
parents: 166
diff changeset
168 HEIGHT = dp(35)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
169
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
170 def __init__(self):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
171 super(RootHeadWidget, self).__init__()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
172 self.notes_last = None
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
173 self.notes_event = None
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
174 self.notes_drop = NotesDrop(self.notes)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
175
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
176 def addNotif(self, callback, *args, **kwargs):
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
177 """add a notification with a callback attached
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
178
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
179 when notification is pressed, callback is called
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
180 @param *args, **kwargs: arguments of callback
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
181 """
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
182 self.notifs_icon.addNotif(callback, *args, **kwargs)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
183
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
184 def addNote(self, title, message, level, symbol, action):
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
185 kwargs = {
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
186 'title': title,
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
187 'message': message,
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
188 'level': level
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
189 }
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
190 if symbol is not None:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
191 kwargs['symbol'] = symbol
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
192 if action is not None:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
193 kwargs['action'] = action
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
194 note = Note(**kwargs)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
195 self.notes.append(note)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
196 if self.notes_event is None:
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
197 self.notes_event = Clock.schedule_interval(self._displayNextNote, 5)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
198 self._displayNextNote()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
199
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
200 def addNotifUI(self, ui):
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
201 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
202
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
203 def addNotifWidget(self, widget):
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
204 app = App.get_running_app()
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
205 self.notifs_icon.addNotif(app.host.showExtraUI, widget=widget)
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
206
284
ca4daced4638 misc: replaced "dummy" by "__"
Goffi <goffi@goffi.org>
parents: 282
diff changeset
207 def _displayNextNote(self, __=None):
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
208 screen = Screen()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
209 try:
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
210 idx = self.notes.index(self.notes_last) + 1
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
211 except ValueError:
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
212 idx = 0
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
213 try:
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
214 note = self.notes_last = self.notes[idx]
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
215 except IndexError:
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
216 self.notes_event.cancel()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
217 self.notes_event = None
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
218 else:
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
219 screen.add_widget(note)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
220 self.manager.switch_to(screen)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
221
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
222
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
223 class RootMenus(menu.MenusWidget):
166
37220459e93d core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents: 165
diff changeset
224 HEIGHT = dp(30)
85
c2a7234d13d2 menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents: 78
diff changeset
225
c2a7234d13d2 menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents: 78
diff changeset
226
c2a7234d13d2 menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents: 78
diff changeset
227 class RootBody(BoxLayout):
c2a7234d13d2 menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents: 78
diff changeset
228 pass
c2a7234d13d2 menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents: 78
diff changeset
229
c2a7234d13d2 menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents: 78
diff changeset
230
c2a7234d13d2 menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents: 78
diff changeset
231 class CagouRootWidget(FloatLayout):
c2a7234d13d2 menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents: 78
diff changeset
232 root_menus = properties.ObjectProperty()
c2a7234d13d2 menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents: 78
diff changeset
233 root_body = properties.ObjectProperty
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
234
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
235 def __init__(self, main_widget):
85
c2a7234d13d2 menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents: 78
diff changeset
236 super(CagouRootWidget, self).__init__()
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
237 # header
172
7103655647aa core: hide notifications header on M-n
Goffi <goffi@goffi.org>
parents: 166
diff changeset
238 self.head_widget = RootHeadWidget()
7103655647aa core: hide notifications header on M-n
Goffi <goffi@goffi.org>
parents: 166
diff changeset
239 self.root_body.add_widget(self.head_widget)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
240 # body
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
241 self._manager = ScreenManager()
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
242 # main widgets
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
243 main_screen = Screen(name='main')
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
244 main_screen.add_widget(main_widget)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
245 self._manager.add_widget(main_screen)
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
246 # backend XMLUI (popups, forms, etc)
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
247 xmlui_screen = Screen(name='xmlui')
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
248 self._manager.add_widget(xmlui_screen)
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 77
diff changeset
249 # extra (file chooser, audio record, etc)
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 77
diff changeset
250 extra_screen = Screen(name='extra')
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 77
diff changeset
251 self._manager.add_widget(extra_screen)
85
c2a7234d13d2 menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents: 78
diff changeset
252 self.root_body.add_widget(self._manager)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
253
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
254 def changeWidget(self, widget, screen_name="main"):
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
255 """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
256 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
257 # 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
258 # 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
259 self._manager.transition.stop()
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
260 screen = self._manager.get_screen(screen_name)
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
261 screen.clear_widgets()
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
262 screen.add_widget(widget)
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
263
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
264 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
265 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
266 # 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
267 # 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
268 self._manager.transition.stop()
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
269 if self._manager.current == screen:
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
270 return
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
271 if screen == "main":
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
272 self._manager.transition = FallOutTransition()
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
273 else:
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
274 self._manager.transition = RiseInTransition()
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
275 self._manager.current = screen
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
276
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
277 def newAction(self, handler, action_data, id_, security_limit, profile):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
278 """Add a notification for an action"""
172
7103655647aa core: hide notifications header on M-n
Goffi <goffi@goffi.org>
parents: 166
diff changeset
279 self.head_widget.addNotif(handler, action_data, id_, security_limit, profile)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
280
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
281 def addNote(self, title, message, level, symbol, action):
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
282 self.head_widget.addNote(title, message, level, symbol, action)
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
283
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
284 def addNotifUI(self, ui):
172
7103655647aa core: hide notifications header on M-n
Goffi <goffi@goffi.org>
parents: 166
diff changeset
285 self.head_widget.addNotifUI(ui)
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
286
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
287 def addNotifWidget(self, widget):
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
288 self.head_widget.addNotifWidget(widget)
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
289
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
290
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
291 class CagouApp(App):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
292 """Kivy App for Cagou"""
176
2cfef8fbfd4e core: moved main colors to constants
Goffi <goffi@goffi.org>
parents: 174
diff changeset
293 c_prim = properties.ListProperty(C.COLOR_PRIM)
2cfef8fbfd4e core: moved main colors to constants
Goffi <goffi@goffi.org>
parents: 174
diff changeset
294 c_prim_light = properties.ListProperty(C.COLOR_PRIM_LIGHT)
2cfef8fbfd4e core: moved main colors to constants
Goffi <goffi@goffi.org>
parents: 174
diff changeset
295 c_prim_dark = properties.ListProperty(C.COLOR_PRIM_DARK)
2cfef8fbfd4e core: moved main colors to constants
Goffi <goffi@goffi.org>
parents: 174
diff changeset
296 c_sec = properties.ListProperty(C.COLOR_SEC)
2cfef8fbfd4e core: moved main colors to constants
Goffi <goffi@goffi.org>
parents: 174
diff changeset
297 c_sec_light = properties.ListProperty(C.COLOR_SEC_LIGHT)
2cfef8fbfd4e core: moved main colors to constants
Goffi <goffi@goffi.org>
parents: 174
diff changeset
298 c_sec_dark = properties.ListProperty(C.COLOR_SEC_DARK)
346
7b9a0e57df53 core: new "connected" property in CagouApp
Goffi <goffi@goffi.org>
parents: 342
diff changeset
299 connected = properties.BooleanProperty(False)
274
7d5297984191 core, chat: UI improvments:
Goffi <goffi@goffi.org>
parents: 272
diff changeset
300 # we have to put those constants here and not in core/constants.py
7d5297984191 core, chat: UI improvments:
Goffi <goffi@goffi.org>
parents: 272
diff changeset
301 # because of the use of dp(), which would import Kivy too early
7d5297984191 core, chat: UI improvments:
Goffi <goffi@goffi.org>
parents: 272
diff changeset
302 # and prevent the log hack
7d5297984191 core, chat: UI improvments:
Goffi <goffi@goffi.org>
parents: 272
diff changeset
303 MARGIN_LEFT = MARGIN_RIGHT = dp(10)
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
304
152
b9fd83292fc4 core: disabled Kivy's default behaviour of displaying settings on F1
Goffi <goffi@goffi.org>
parents: 143
diff changeset
305 def _install_settings_keys(self, window):
b9fd83292fc4 core: disabled Kivy's default behaviour of displaying settings on F1
Goffi <goffi@goffi.org>
parents: 143
diff changeset
306 # we don't want default Kivy's behaviour of displaying
b9fd83292fc4 core: disabled Kivy's default behaviour of displaying settings on F1
Goffi <goffi@goffi.org>
parents: 143
diff changeset
307 # a settings screen when pressing F1 or platform specific key
b9fd83292fc4 core: disabled Kivy's default behaviour of displaying settings on F1
Goffi <goffi@goffi.org>
parents: 143
diff changeset
308 return
b9fd83292fc4 core: disabled Kivy's default behaviour of displaying settings on F1
Goffi <goffi@goffi.org>
parents: 143
diff changeset
309
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
310 def build(self):
143
05d602be0120 core: [esc] key handling is disabled (for now)
Goffi <goffi@goffi.org>
parents: 142
diff changeset
311 Window.bind(on_keyboard=self.key_input)
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
312 wid = CagouRootWidget(Label(text="Loading please wait"))
342
89799148f894 core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents: 331
diff changeset
313 local_platform.on_app_build(wid)
166
37220459e93d core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents: 165
diff changeset
314 return wid
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
315
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
316 def showWidget(self):
49
fd9cbf6ae663 core: postInit() is now called, allowing automatic profile connection
Goffi <goffi@goffi.org>
parents: 48
diff changeset
317 self._profile_manager = ProfileManager()
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
318 self.root.changeWidget(self._profile_manager)
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
319
31
4f9e701d76b4 core: expand now accepts extra arguments, which will be used in format
Goffi <goffi@goffi.org>
parents: 29
diff changeset
320 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
321 """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
322
32
fdaf914e2729 minor docstring fix
Goffi <goffi@goffi.org>
parents: 31
diff changeset
323 useful in kv. Values which can be used:
fdaf914e2729 minor docstring fix
Goffi <goffi@goffi.org>
parents: 31
diff changeset
324 - {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
325 @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
326 @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
327 @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
328 """
31
4f9e701d76b4 core: expand now accepts extra arguments, which will be used in format
Goffi <goffi@goffi.org>
parents: 29
diff changeset
329 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
330
259
4601793b0dee core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents: 250
diff changeset
331 def initFrontendState(self):
4601793b0dee core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents: 250
diff changeset
332 """Init state to handle paused/stopped/running on mobile OSes"""
342
89799148f894 core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents: 331
diff changeset
333 local_platform.on_initFrontendState()
73
674b1fa3c945 core: use memory map on a file to indicate pause/resume status, so backend can now it
Goffi <goffi@goffi.org>
parents: 72
diff changeset
334
65
1c738621bc8d core: on_pause/on_resume handling (needed for Android)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
335 def on_pause(self):
342
89799148f894 core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents: 331
diff changeset
336 return local_platform.on_pause()
65
1c738621bc8d core: on_pause/on_resume handling (needed for Android)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
337
1c738621bc8d core: on_pause/on_resume handling (needed for Android)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
338 def on_resume(self):
342
89799148f894 core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents: 331
diff changeset
339 return local_platform.on_resume()
73
674b1fa3c945 core: use memory map on a file to indicate pause/resume status, so backend can now it
Goffi <goffi@goffi.org>
parents: 72
diff changeset
340
674b1fa3c945 core: use memory map on a file to indicate pause/resume status, so backend can now it
Goffi <goffi@goffi.org>
parents: 72
diff changeset
341 def on_stop(self):
342
89799148f894 core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents: 331
diff changeset
342 return local_platform.on_stop()
65
1c738621bc8d core: on_pause/on_resume handling (needed for Android)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
343
143
05d602be0120 core: [esc] key handling is disabled (for now)
Goffi <goffi@goffi.org>
parents: 142
diff changeset
344 def key_input(self, window, key, scancode, codepoint, modifier):
349
33244f944bd8 core: "key_input" method is now checked and used if suitable in selected widget.
Goffi <goffi@goffi.org>
parents: 346
diff changeset
345
33244f944bd8 core: "key_input" method is now checked and used if suitable in selected widget.
Goffi <goffi@goffi.org>
parents: 346
diff changeset
346 # we first check if selected widget handles the key
33244f944bd8 core: "key_input" method is now checked and used if suitable in selected widget.
Goffi <goffi@goffi.org>
parents: 346
diff changeset
347 if ((self.host.selected_widget is not None
33244f944bd8 core: "key_input" method is now checked and used if suitable in selected widget.
Goffi <goffi@goffi.org>
parents: 346
diff changeset
348 and hasattr(self.host.selected_widget, 'key_input')
33244f944bd8 core: "key_input" method is now checked and used if suitable in selected widget.
Goffi <goffi@goffi.org>
parents: 346
diff changeset
349 and self.host.selected_widget.key_input(window, key, scancode, codepoint,
33244f944bd8 core: "key_input" method is now checked and used if suitable in selected widget.
Goffi <goffi@goffi.org>
parents: 346
diff changeset
350 modifier))):
33244f944bd8 core: "key_input" method is now checked and used if suitable in selected widget.
Goffi <goffi@goffi.org>
parents: 346
diff changeset
351 return True
33244f944bd8 core: "key_input" method is now checked and used if suitable in selected widget.
Goffi <goffi@goffi.org>
parents: 346
diff changeset
352
143
05d602be0120 core: [esc] key handling is disabled (for now)
Goffi <goffi@goffi.org>
parents: 142
diff changeset
353 if key == 27:
166
37220459e93d core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents: 165
diff changeset
354 # we disable [esc] handling, because default action is to quit app
143
05d602be0120 core: [esc] key handling is disabled (for now)
Goffi <goffi@goffi.org>
parents: 142
diff changeset
355 return True
165
e6ec8ff62d87 core: toggle fullscreen on F11
Goffi <goffi@goffi.org>
parents: 154
diff changeset
356 elif key == 292:
166
37220459e93d core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents: 165
diff changeset
357 # F11: full screen
165
e6ec8ff62d87 core: toggle fullscreen on F11
Goffi <goffi@goffi.org>
parents: 154
diff changeset
358 if not Window.fullscreen:
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
359 Window.fullscreen = 'auto'
165
e6ec8ff62d87 core: toggle fullscreen on F11
Goffi <goffi@goffi.org>
parents: 154
diff changeset
360 else:
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
361 Window.fullscreen = False
165
e6ec8ff62d87 core: toggle fullscreen on F11
Goffi <goffi@goffi.org>
parents: 154
diff changeset
362 return True
166
37220459e93d core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents: 165
diff changeset
363 elif key == 109 and modifier == ['alt']:
37220459e93d core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents: 165
diff changeset
364 # M-m we hide/show menu
37220459e93d core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents: 165
diff changeset
365 menu = self.root.root_menus
37220459e93d core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents: 165
diff changeset
366 if menu.height:
37220459e93d core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents: 165
diff changeset
367 Animation(height=0, duration=0.3).start(menu)
37220459e93d core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents: 165
diff changeset
368 else:
37220459e93d core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents: 165
diff changeset
369 Animation(height=menu.HEIGHT, duration=0.3).start(menu)
37220459e93d core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents: 165
diff changeset
370 return True
172
7103655647aa core: hide notifications header on M-n
Goffi <goffi@goffi.org>
parents: 166
diff changeset
371 elif key == 110 and modifier == ['alt']:
7103655647aa core: hide notifications header on M-n
Goffi <goffi@goffi.org>
parents: 166
diff changeset
372 # M-n we hide/show notifications
7103655647aa core: hide notifications header on M-n
Goffi <goffi@goffi.org>
parents: 166
diff changeset
373 head = self.root.head_widget
7103655647aa core: hide notifications header on M-n
Goffi <goffi@goffi.org>
parents: 166
diff changeset
374 if head.height:
7103655647aa core: hide notifications header on M-n
Goffi <goffi@goffi.org>
parents: 166
diff changeset
375 Animation(height=0, opacity=0, duration=0.3).start(head)
7103655647aa core: hide notifications header on M-n
Goffi <goffi@goffi.org>
parents: 166
diff changeset
376 else:
7103655647aa core: hide notifications header on M-n
Goffi <goffi@goffi.org>
parents: 166
diff changeset
377 Animation(height=head.HEIGHT, opacity=1, duration=0.3).start(head)
7103655647aa core: hide notifications header on M-n
Goffi <goffi@goffi.org>
parents: 166
diff changeset
378 return True
143
05d602be0120 core: [esc] key handling is disabled (for now)
Goffi <goffi@goffi.org>
parents: 142
diff changeset
379 else:
05d602be0120 core: [esc] key handling is disabled (for now)
Goffi <goffi@goffi.org>
parents: 142
diff changeset
380 return False
05d602be0120 core: [esc] key handling is disabled (for now)
Goffi <goffi@goffi.org>
parents: 142
diff changeset
381
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
382
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
383 class Cagou(QuickApp):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
384 MB_HANDLE = False
265
805c4103dac5 core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents: 264
diff changeset
385 AUTO_RESYNC = False
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
386
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
387 def __init__(self):
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
388 if bridge_name == 'embedded':
63
af4f986d86f0 core: pb bridge implementation:
Goffi <goffi@goffi.org>
parents: 61
diff changeset
389 from sat.core import sat_main
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
390 self.sat = sat_main.SAT()
64
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents: 63
diff changeset
391
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
392 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
393 if bridge_module is None:
316
86566968837a android (p4a): updated P4A option to use Python 3:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
394 log.error(f"Can't import {bridge_name} bridge")
72
1a324c682d8a core: use onBridgeConnected and exit code 3 when bridge can't be imported
Goffi <goffi@goffi.org>
parents: 65
diff changeset
395 sys.exit(3)
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
396 else:
316
86566968837a android (p4a): updated P4A option to use Python 3:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
397 log.debug(f"Loading {bridge_name} bridge")
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
398 super(Cagou, self).__init__(bridge_factory=bridge_module.Bridge,
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
399 xmlui=xmlui,
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
400 check_options=quick_utils.check_options,
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
401 connect_bridge=False)
15
56838ad5c84b files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents: 14
diff changeset
402 self._import_kv()
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
403 self.app = CagouApp()
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
404 self.app.host = self
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
405 self.media_dir = self.app.media_dir = config.getConfig(main_config, '',
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
406 'media_dir')
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
407 self.downloads_dir = self.app.downloads_dir = config.getConfig(main_config, '',
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
408 'downloads_dir')
188
0abd24ab81b1 core: retrieve downloads_dir on startup
Goffi <goffi@goffi.org>
parents: 184
diff changeset
409 if not os.path.exists(self.downloads_dir):
0abd24ab81b1 core: retrieve downloads_dir on startup
Goffi <goffi@goffi.org>
parents: 184
diff changeset
410 try:
0abd24ab81b1 core: retrieve downloads_dir on startup
Goffi <goffi@goffi.org>
parents: 184
diff changeset
411 os.makedirs(self.downloads_dir)
0abd24ab81b1 core: retrieve downloads_dir on startup
Goffi <goffi@goffi.org>
parents: 184
diff changeset
412 except OSError as e:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
413 log.warnings(_("Can't create downloads dir: {reason}").format(reason=e))
25
d09bd16dbbe2 code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents: 19
diff changeset
414 self.app.default_avatar = os.path.join(self.media_dir, "misc/default_avatar.png")
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
415 self.app.icon = os.path.join(self.media_dir,
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
416 "icons/muchoslava/png/cagou_profil_bleu_96.png")
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
417 self._plg_wids = [] # main widgets plugins
97
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 91
diff changeset
418 self._plg_wids_transfer = [] # transfer widgets plugins
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
419 self._import_plugins()
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
420 self._visible_widgets = {} # visible widgets by classes
302
f55b60659ec1 core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents: 298
diff changeset
421 self.backend_version = sat.__version__ # will be replaced by getVersion()
f55b60659ec1 core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents: 298
diff changeset
422 if C.APP_VERSION.endswith('D'):
f55b60659ec1 core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents: 298
diff changeset
423 self.version = "{} {}".format(
f55b60659ec1 core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents: 298
diff changeset
424 C.APP_VERSION,
f55b60659ec1 core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents: 298
diff changeset
425 sat_utils.getRepositoryData(cagou)
f55b60659ec1 core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents: 298
diff changeset
426 )
f55b60659ec1 core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents: 298
diff changeset
427 else:
f55b60659ec1 core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents: 298
diff changeset
428 self.version = C.APP_VERSION
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
429
281
ef77423ce500 core: store tls_validation flag in host and use if for file upload.
Goffi <goffi@goffi.org>
parents: 280
diff changeset
430 self.tls_validation = not C.bool(config.getConfig(main_config,
ef77423ce500 core: store tls_validation flag in host and use if for file upload.
Goffi <goffi@goffi.org>
parents: 280
diff changeset
431 C.CONFIG_SECTION,
ef77423ce500 core: store tls_validation flag in host and use if for file upload.
Goffi <goffi@goffi.org>
parents: 280
diff changeset
432 'no_certificate_validation',
ef77423ce500 core: store tls_validation flag in host and use if for file upload.
Goffi <goffi@goffi.org>
parents: 280
diff changeset
433 C.BOOL_FALSE))
ef77423ce500 core: store tls_validation flag in host and use if for file upload.
Goffi <goffi@goffi.org>
parents: 280
diff changeset
434 if not self.tls_validation:
280
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents: 276
diff changeset
435 from cagou.core import patches
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents: 276
diff changeset
436 patches.apply()
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
437 log.warning("SSL certificate validation is disabled, this is unsecure!")
280
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents: 276
diff changeset
438
342
89799148f894 core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents: 331
diff changeset
439 local_platform.on_host_init(self)
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
440
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
441 @property
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
442 def visible_widgets(self):
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
443 for w_list in self._visible_widgets.values():
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
444 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
445 yield w
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
446
265
805c4103dac5 core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents: 264
diff changeset
447 @QuickApp.sync.setter
805c4103dac5 core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents: 264
diff changeset
448 def sync(self, state):
805c4103dac5 core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents: 264
diff changeset
449 QuickApp.sync.fset(self, state)
805c4103dac5 core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents: 264
diff changeset
450 # widget are resynchronised in onVisible event,
805c4103dac5 core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents: 264
diff changeset
451 # so we must call resync for widgets which are already visible
805c4103dac5 core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents: 264
diff changeset
452 if state:
805c4103dac5 core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents: 264
diff changeset
453 for w in self.visible_widgets:
272
c4990a7d5dbd core: check if resync exist in widget before calling it
Goffi <goffi@goffi.org>
parents: 267
diff changeset
454 try:
c4990a7d5dbd core: check if resync exist in widget before calling it
Goffi <goffi@goffi.org>
parents: 267
diff changeset
455 resync = w.resync
c4990a7d5dbd core: check if resync exist in widget before calling it
Goffi <goffi@goffi.org>
parents: 267
diff changeset
456 except AttributeError:
c4990a7d5dbd core: check if resync exist in widget before calling it
Goffi <goffi@goffi.org>
parents: 267
diff changeset
457 pass
c4990a7d5dbd core: check if resync exist in widget before calling it
Goffi <goffi@goffi.org>
parents: 267
diff changeset
458 else:
c4990a7d5dbd core: check if resync exist in widget before calling it
Goffi <goffi@goffi.org>
parents: 267
diff changeset
459 resync()
291
04e4cd7c9351 core: refill contact lists on resync
Goffi <goffi@goffi.org>
parents: 290
diff changeset
460 self.contact_lists.fill()
265
805c4103dac5 core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents: 264
diff changeset
461
72
1a324c682d8a core: use onBridgeConnected and exit code 3 when bridge can't be imported
Goffi <goffi@goffi.org>
parents: 65
diff changeset
462 def onBridgeConnected(self):
189
a91abcd6d9a5 core: call QuickApp.onBridgeConnected (so ns_map is filled)
Goffi <goffi@goffi.org>
parents: 188
diff changeset
463 super(Cagou, self).onBridgeConnected()
122
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 119
diff changeset
464 self.registerSignal("otrState", iface="plugin")
63
af4f986d86f0 core: pb bridge implementation:
Goffi <goffi@goffi.org>
parents: 61
diff changeset
465 self.bridge.getReady(self.onBackendReady)
af4f986d86f0 core: pb bridge implementation:
Goffi <goffi@goffi.org>
parents: 61
diff changeset
466
64
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents: 63
diff changeset
467 def _bridgeEb(self, failure):
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents: 63
diff changeset
468 if bridge_name == "pb" and sys.platform == "android":
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents: 63
diff changeset
469 try:
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents: 63
diff changeset
470 self.retried += 1
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents: 63
diff changeset
471 except AttributeError:
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents: 63
diff changeset
472 self.retried = 1
317
4b0fa73caad4 core: bridge are now raising generic BridgeExceptionNoService
Goffi <goffi@goffi.org>
parents: 316
diff changeset
473 if ((isinstance(failure, exceptions.BridgeExceptionNoService)
4b0fa73caad4 core: bridge are now raising generic BridgeExceptionNoService
Goffi <goffi@goffi.org>
parents: 316
diff changeset
474 and self.retried < 100)):
64
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents: 63
diff changeset
475 if self.retried % 20 == 0:
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents: 63
diff changeset
476 log.debug("backend not ready, retrying ({})".format(self.retried))
284
ca4daced4638 misc: replaced "dummy" by "__"
Goffi <goffi@goffi.org>
parents: 282
diff changeset
477 Clock.schedule_once(lambda __: self.connectBridge(), 0.05)
64
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents: 63
diff changeset
478 return
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents: 63
diff changeset
479 super(Cagou, self)._bridgeEb(failure)
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents: 63
diff changeset
480
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
481 def run(self):
63
af4f986d86f0 core: pb bridge implementation:
Goffi <goffi@goffi.org>
parents: 61
diff changeset
482 self.connectBridge()
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
483 self.app.bind(on_stop=self.onStop)
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
484 self.app.run()
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
485
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
486 def onStop(self, obj):
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
487 try:
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
488 sat_instance = self.sat
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
489 except AttributeError:
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
490 pass
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
491 else:
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
492 sat_instance.stopService()
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
493
246
15e47bbb192c about: show full version of SàT
Goffi <goffi@goffi.org>
parents: 244
diff changeset
494 def _getVersionCb(self, version):
302
f55b60659ec1 core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents: 298
diff changeset
495 self.backend_version = version
246
15e47bbb192c about: show full version of SàT
Goffi <goffi@goffi.org>
parents: 244
diff changeset
496
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
497 def onBackendReady(self):
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
498 self.app.showWidget()
246
15e47bbb192c about: show full version of SàT
Goffi <goffi@goffi.org>
parents: 244
diff changeset
499 self.bridge.getVersion(callback=self._getVersionCb)
259
4601793b0dee core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents: 250
diff changeset
500 self.app.initFrontendState()
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
501 self.postInit()
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
502
284
ca4daced4638 misc: replaced "dummy" by "__"
Goffi <goffi@goffi.org>
parents: 282
diff changeset
503 def postInit(self, __=None):
276
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 274
diff changeset
504 # FIXME: resize doesn't work with SDL2 on android, so we use below_target for now
61
0b7f10de416e android: android build first draft:
Goffi <goffi@goffi.org>
parents: 60
diff changeset
505 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
506 profile_manager = self.app._profile_manager
fd9cbf6ae663 core: postInit() is now called, allowing automatic profile connection
Goffi <goffi@goffi.org>
parents: 48
diff changeset
507 del self.app._profile_manager
fd9cbf6ae663 core: postInit() is now called, allowing automatic profile connection
Goffi <goffi@goffi.org>
parents: 48
diff changeset
508 super(Cagou, self).postInit(profile_manager)
fd9cbf6ae663 core: postInit() is now called, allowing automatic profile connection
Goffi <goffi@goffi.org>
parents: 48
diff changeset
509
346
7b9a0e57df53 core: new "connected" property in CagouApp
Goffi <goffi@goffi.org>
parents: 342
diff changeset
510 def profilePlugged(self, profile):
7b9a0e57df53 core: new "connected" property in CagouApp
Goffi <goffi@goffi.org>
parents: 342
diff changeset
511 super().profilePlugged(profile)
7b9a0e57df53 core: new "connected" property in CagouApp
Goffi <goffi@goffi.org>
parents: 342
diff changeset
512 # FIXME: this won't work with multiple profiles
7b9a0e57df53 core: new "connected" property in CagouApp
Goffi <goffi@goffi.org>
parents: 342
diff changeset
513 self.app.connected = self.profiles[profile].connected
7b9a0e57df53 core: new "connected" property in CagouApp
Goffi <goffi@goffi.org>
parents: 342
diff changeset
514
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
515 def _defaultFactoryMain(self, plugin_info, target, profiles):
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
516 """default factory used to create main widgets instances
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
517
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
518 used when PLUGIN_INFO["factory"] is not set
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
519 @param plugin_info(dict): plugin datas
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
520 @param target: QuickWidget target
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
521 @param profiles(iterable): list of profiles
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
522 """
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
523 main_cls = plugin_info['main']
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
524 return self.widgets.getOrCreateWidget(main_cls,
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
525 target,
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
526 on_new_widget=None,
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
527 profiles=iter(self.profiles))
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
528
97
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 91
diff changeset
529 def _defaultFactoryTransfer(self, plugin_info, callback, cancel_cb, profiles):
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 91
diff changeset
530 """default factory used to create transfer widgets instances
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
531
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
532 @param plugin_info(dict): plugin datas
97
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 91
diff changeset
533 @param callback(callable): method to call with path to file to transfer
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 91
diff changeset
534 @param cancel_cb(callable): call when transfer is cancelled
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 91
diff changeset
535 transfer widget must be used as first argument
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
536 @param profiles(iterable): list of profiles
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
537 None if not specified
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
538 """
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
539 main_cls = plugin_info['main']
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
540 return main_cls(callback=callback, cancel_cb=cancel_cb)
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
541
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
542 ## plugins & kv import ##
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
543
15
56838ad5c84b files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents: 14
diff changeset
544 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
545 """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
546 path = os.path.dirname(cagou.kv.__file__)
130
0ec3c3c0ed92 core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents: 126
diff changeset
547 kv_files = glob.glob(os.path.join(path, "*.kv"))
0ec3c3c0ed92 core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents: 126
diff changeset
548 # we want to be sure that base.kv is loaded first
0ec3c3c0ed92 core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents: 126
diff changeset
549 # as it override some Kivy widgets properties
0ec3c3c0ed92 core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents: 126
diff changeset
550 for kv_file in kv_files:
0ec3c3c0ed92 core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents: 126
diff changeset
551 if kv_file.endswith('base.kv'):
0ec3c3c0ed92 core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents: 126
diff changeset
552 kv_files.remove(kv_file)
0ec3c3c0ed92 core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents: 126
diff changeset
553 kv_files.insert(0, kv_file)
0ec3c3c0ed92 core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents: 126
diff changeset
554 break
0ec3c3c0ed92 core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents: 126
diff changeset
555 else:
0ec3c3c0ed92 core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents: 126
diff changeset
556 raise exceptions.InternalError("base.kv is missing")
0ec3c3c0ed92 core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents: 126
diff changeset
557
0ec3c3c0ed92 core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents: 126
diff changeset
558 for kv_file in kv_files:
0ec3c3c0ed92 core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents: 126
diff changeset
559 Builder.load_file(kv_file)
316
86566968837a android (p4a): updated P4A option to use Python 3:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
560 log.debug(f"kv file {kv_file} loaded")
15
56838ad5c84b files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents: 14
diff changeset
561
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
562 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
563 """import all plugins"""
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
564 self.default_wid = None
87
17094a075fd2 core: use C.PLUGIN_EXT to know which plugin extension to use
Goffi <goffi@goffi.org>
parents: 86
diff changeset
565 plugins_path = os.path.dirname(cagou.plugins.__file__)
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
566 plugin_glob = "plugin*." + C.PLUGIN_EXT
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
567 plug_lst = [os.path.splitext(p)[0] for p in
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
568 map(os.path.basename, glob.glob(os.path.join(plugins_path,
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
569 plugin_glob)))]
61
0b7f10de416e android: android build first draft:
Goffi <goffi@goffi.org>
parents: 60
diff changeset
570
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
571 imported_names_main = set() # used to avoid loading 2 times
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
572 # plugin with same import name
97
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 91
diff changeset
573 imported_names_transfer = set()
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
574 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
575 plugin_path = 'cagou.plugins.' + plug
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
576
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
577 # we get type from plugin name
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
578 suff = plug[7:]
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
579 if '_' not in suff:
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
580 log.error("invalid plugin name: {}, skipping".format(plug))
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
581 continue
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
582 plugin_type = suff[:suff.find('_')]
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
583
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
584 # and select the variable to use according to type
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
585 if plugin_type == C.PLUG_TYPE_WID:
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
586 imported_names = imported_names_main
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
587 default_factory = self._defaultFactoryMain
97
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 91
diff changeset
588 elif plugin_type == C.PLUG_TYPE_TRANSFER:
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 91
diff changeset
589 imported_names = imported_names_transfer
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 91
diff changeset
590 default_factory = self._defaultFactoryTransfer
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
591 else:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
592 log.error("unknown plugin type {type_} for plugin {file_}, skipping"
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
593 .format(
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
594 type_ = plugin_type,
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
595 file_ = plug
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
596 ))
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
597 continue
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
598 plugins_set = self._getPluginsSet(plugin_type)
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
599
15
56838ad5c84b files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents: 14
diff changeset
600 mod = import_module(plugin_path)
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
601 try:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
602 plugin_info = mod.PLUGIN_INFO
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
603 except AttributeError:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
604 plugin_info = {}
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
605
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
606 plugin_info['plugin_file'] = plug
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
607 plugin_info['plugin_type'] = plugin_type
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
608
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
609 if 'platforms' in plugin_info:
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
610 if sys.platform not in plugin_info['platforms']:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
611 log.info("{plugin_file} is not used on this platform, skipping"
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
612 .format(**plugin_info))
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
613 continue
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
614
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
615 # import name is used to differentiate plugins
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
616 if 'import_name' not in plugin_info:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
617 plugin_info['import_name'] = plug
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
618 if plugin_info['import_name'] in imported_names:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
619 log.warning(_("there is already a plugin named {}, "
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
620 "ignoring new one").format(plugin_info['import_name']))
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
621 continue
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
622 if plugin_info['import_name'] == C.WID_SELECTOR:
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
623 if plugin_type != C.PLUG_TYPE_WID:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
624 log.error("{import_name} import name can only be used with {type_} "
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
625 "type, skipping {name}".format(type_=C.PLUG_TYPE_WID,
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
626 **plugin_info))
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
627 continue
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
628 # if WidgetSelector exists, it will be our default widget
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
629 self.default_wid = plugin_info
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
630
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
631 # we want everything optional, so we use plugin file name
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
632 # if actual name is not found
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
633 if 'name' not in plugin_info:
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
634 name_start = 8 + len(plugin_type)
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
635 plugin_info['name'] = plug[name_start:]
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
636
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
637 # we need to load the kv file
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
638 if 'kv_file' not in plugin_info:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
639 plugin_info['kv_file'] = '{}.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
640 kv_path = os.path.join(plugins_path, plugin_info['kv_file'])
89
d249df379fa3 core: kv files are not mandatory anymore for plugins
Goffi <goffi@goffi.org>
parents: 87
diff changeset
641 if not os.path.exists(kv_path):
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
642 log.debug("no kv found for {plugin_file}".format(**plugin_info))
89
d249df379fa3 core: kv files are not mandatory anymore for plugins
Goffi <goffi@goffi.org>
parents: 87
diff changeset
643 else:
d249df379fa3 core: kv files are not mandatory anymore for plugins
Goffi <goffi@goffi.org>
parents: 87
diff changeset
644 Builder.load_file(kv_path)
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
645
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
646 # what is the main class ?
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
647 main_cls = getattr(mod, plugin_info['main'])
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
648 plugin_info['main'] = main_cls
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
649
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
650 # factory is used to create the instance
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
651 # if not found, we use a defaut one with getOrCreateWidget
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
652 if 'factory' not in plugin_info:
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
653 plugin_info['factory'] = default_factory
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
654
25
d09bd16dbbe2 code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents: 19
diff changeset
655 # icons
d09bd16dbbe2 code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents: 19
diff changeset
656 for size in ('small', 'medium'):
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
657 key = 'icon_{}'.format(size)
25
d09bd16dbbe2 code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents: 19
diff changeset
658 try:
d09bd16dbbe2 code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents: 19
diff changeset
659 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
660 except KeyError:
d09bd16dbbe2 code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents: 19
diff changeset
661 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
662 else:
d09bd16dbbe2 code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents: 19
diff changeset
663 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
664 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
665 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
666 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
667
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
668 plugins_set.append(plugin_info)
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
669 if not self._plg_wids:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
670 log.error(_("no widget plugin found"))
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
671 return
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
672
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
673 # we want widgets sorted by names
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
674 self._plg_wids.sort(key=lambda p: p['name'].lower())
97
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 91
diff changeset
675 self._plg_wids_transfer.sort(key=lambda p: p['name'].lower())
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
676
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
677 if self.default_wid is None:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
678 # 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
679 self.default_wid = self._plg_wids[0]
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
680
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
681 def _getPluginsSet(self, type_):
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
682 if type_ == C.PLUG_TYPE_WID:
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
683 return self._plg_wids
97
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 91
diff changeset
684 elif type_ == C.PLUG_TYPE_TRANSFER:
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 91
diff changeset
685 return self._plg_wids_transfer
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
686 else:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
687 raise KeyError("{} plugin type is unknown".format(type_))
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
688
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
689 def getPluggedWidgets(self, type_=C.PLUG_TYPE_WID, except_cls=None):
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
690 """get available widgets plugin infos
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
691
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
692 @param type_(unicode): type of widgets to get
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
693 one of C.PLUG_TYPE_* constant
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
694 @param except_cls(None, class): if not None,
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
695 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
696 @return (iter[dict]): available widgets plugin infos
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
697 """
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
698 plugins_set = self._getPluginsSet(type_)
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
699 for plugin_data in plugins_set:
19
c58b522607f4 main: fixed profiles value in _defaultFactory + getPluggedWidgets is now a generator
Goffi <goffi@goffi.org>
parents: 16
diff changeset
700 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
701 continue
c58b522607f4 main: fixed profiles value in _defaultFactory + getPluggedWidgets is now a generator
Goffi <goffi@goffi.org>
parents: 16
diff changeset
702 yield plugin_data
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
703
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
704 def getPluginInfo(self, type_=C.PLUG_TYPE_WID, **kwargs):
41
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
705 """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
706
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
707 @param type_(unicode): type of widgets to get
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
708 one of C.PLUG_TYPE_* constant
41
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
709 @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
710 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
711 @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
712 """
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
713 plugins_set = self._getPluginsSet(type_)
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
714 for plugin_info in plugins_set:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
715 for k, w in kwargs.items():
41
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
716 try:
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
717 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
718 continue
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
719 except KeyError:
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
720 continue
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
721 return plugin_info
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
722
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
723 ## widgets handling
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
724
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
725 def newWidget(self, widget):
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
726 log.debug("new widget created: {}".format(widget))
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
727 if isinstance(widget, quick_chat.QuickChat) and widget.type == C.CHAT_GROUP:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
728 self.addNote("", _("room {} has been joined").format(widget.target))
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
729
350
1ac40d3121f6 core (Cagou): "new" arg can be None in switchWidget, in which case default widget is used.
Goffi <goffi@goffi.org>
parents: 349
diff changeset
730 def switchWidget(self, old, new=None):
11
49d30fc15884 core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents: 9
diff changeset
731 """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
732
350
1ac40d3121f6 core (Cagou): "new" arg can be None in switchWidget, in which case default widget is used.
Goffi <goffi@goffi.org>
parents: 349
diff changeset
733 old(CagouWidget, None): CagouWidget instance or a child
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
734 None to select automatically widget to switch
11
49d30fc15884 core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents: 9
diff changeset
735 new(CagouWidget): new widget instance
350
1ac40d3121f6 core (Cagou): "new" arg can be None in switchWidget, in which case default widget is used.
Goffi <goffi@goffi.org>
parents: 349
diff changeset
736 None to use default widget
11
49d30fc15884 core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents: 9
diff changeset
737 """
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
738 if old is None:
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
739 old = self.getWidgetToSwitch()
350
1ac40d3121f6 core (Cagou): "new" arg can be None in switchWidget, in which case default widget is used.
Goffi <goffi@goffi.org>
parents: 349
diff changeset
740 if new is None:
1ac40d3121f6 core (Cagou): "new" arg can be None in switchWidget, in which case default widget is used.
Goffi <goffi@goffi.org>
parents: 349
diff changeset
741 factory = self.default_wid['factory']
1ac40d3121f6 core (Cagou): "new" arg can be None in switchWidget, in which case default widget is used.
Goffi <goffi@goffi.org>
parents: 349
diff changeset
742 new = factory(self.default_wid, None, profiles=old.profiles)
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
743 to_change = None
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
744 if isinstance(old, CagouWidget):
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
745 to_change = old
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
746 else:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
747 for w in old.walk_reverse():
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
748 if isinstance(w, CagouWidget):
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
749 to_change = w
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
750 break
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
751
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
752 if to_change is None:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
753 raise exceptions.InternalError("no CagouWidget found when "
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
754 "trying to switch widget")
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 152
diff changeset
755
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
756 to_change.whwrapper.changeWidget(new)
249
5d69e4cab925 core: when switching to a new widget, it becomes the selected one.
Goffi <goffi@goffi.org>
parents: 248
diff changeset
757 self.selected_widget = new
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
758
248
b6e33b35538b core, widgets handler: visible_widgets now keep all CagouWidgets, not only QuickWidgets. visible_quick_widgets can be used if only QuickWidgets are desired.
Goffi <goffi@goffi.org>
parents: 247
diff changeset
759 def _addVisibleWidget(self, widget):
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
760 """declare a widget visible
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
761
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
762 for internal use only!
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
763 """
248
b6e33b35538b core, widgets handler: visible_widgets now keep all CagouWidgets, not only QuickWidgets. visible_quick_widgets can be used if only QuickWidgets are desired.
Goffi <goffi@goffi.org>
parents: 247
diff changeset
764 assert isinstance(widget, CagouWidget)
352
434f770fe55b core (Cagou): add debug log for widget visibility + ignore_missing:
Goffi <goffi@goffi.org>
parents: 351
diff changeset
765 log.debug(f"Visible widget: {widget}")
434f770fe55b core (Cagou): add debug log for widget visibility + ignore_missing:
Goffi <goffi@goffi.org>
parents: 351
diff changeset
766 self._visible_widgets.setdefault(widget.__class__, set()).add(widget)
434f770fe55b core (Cagou): add debug log for widget visibility + ignore_missing:
Goffi <goffi@goffi.org>
parents: 351
diff changeset
767 log.debug(f"visible widgets list: {self.getVisibleList(None)}")
264
3e11b5d923e2 core: call new methods onVisible and onNotVisible when a widget is displayed or hidden + fixed a deletion bug on _removeVisibleWidget
Goffi <goffi@goffi.org>
parents: 262
diff changeset
768 widget.onVisible()
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
769
352
434f770fe55b core (Cagou): add debug log for widget visibility + ignore_missing:
Goffi <goffi@goffi.org>
parents: 351
diff changeset
770 def _removeVisibleWidget(self, widget, ignore_missing=False):
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
771 """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
772
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
773 for internal use only!
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
774 """
352
434f770fe55b core (Cagou): add debug log for widget visibility + ignore_missing:
Goffi <goffi@goffi.org>
parents: 351
diff changeset
775 log.debug(f"Widget not visible anymore: {widget}")
434f770fe55b core (Cagou): add debug log for widget visibility + ignore_missing:
Goffi <goffi@goffi.org>
parents: 351
diff changeset
776 try:
434f770fe55b core (Cagou): add debug log for widget visibility + ignore_missing:
Goffi <goffi@goffi.org>
parents: 351
diff changeset
777 self._visible_widgets[widget.__class__].remove(widget)
434f770fe55b core (Cagou): add debug log for widget visibility + ignore_missing:
Goffi <goffi@goffi.org>
parents: 351
diff changeset
778 except KeyError as e:
434f770fe55b core (Cagou): add debug log for widget visibility + ignore_missing:
Goffi <goffi@goffi.org>
parents: 351
diff changeset
779 if not ignore_missing:
434f770fe55b core (Cagou): add debug log for widget visibility + ignore_missing:
Goffi <goffi@goffi.org>
parents: 351
diff changeset
780 log.error(f"trying to remove a not visible widget ({widget}): {e}")
434f770fe55b core (Cagou): add debug log for widget visibility + ignore_missing:
Goffi <goffi@goffi.org>
parents: 351
diff changeset
781 return
434f770fe55b core (Cagou): add debug log for widget visibility + ignore_missing:
Goffi <goffi@goffi.org>
parents: 351
diff changeset
782 log.debug(f"visible widgets list: {self.getVisibleList(None)}")
264
3e11b5d923e2 core: call new methods onVisible and onNotVisible when a widget is displayed or hidden + fixed a deletion bug on _removeVisibleWidget
Goffi <goffi@goffi.org>
parents: 262
diff changeset
783 if isinstance(widget, CagouWidget):
3e11b5d923e2 core: call new methods onVisible and onNotVisible when a widget is displayed or hidden + fixed a deletion bug on _removeVisibleWidget
Goffi <goffi@goffi.org>
parents: 262
diff changeset
784 widget.onNotVisible()
3e11b5d923e2 core: call new methods onVisible and onNotVisible when a widget is displayed or hidden + fixed a deletion bug on _removeVisibleWidget
Goffi <goffi@goffi.org>
parents: 262
diff changeset
785 if isinstance(widget, quick_widgets.QuickWidget):
248
b6e33b35538b core, widgets handler: visible_widgets now keep all CagouWidgets, not only QuickWidgets. visible_quick_widgets can be used if only QuickWidgets are desired.
Goffi <goffi@goffi.org>
parents: 247
diff changeset
786 self.widgets.deleteWidget(widget)
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
787
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
788 def getVisibleList(self, cls):
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
789 """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
790
248
b6e33b35538b core, widgets handler: visible_widgets now keep all CagouWidgets, not only QuickWidgets. visible_quick_widgets can be used if only QuickWidgets are desired.
Goffi <goffi@goffi.org>
parents: 247
diff changeset
791 @param cls(type): type of widgets to get
351
e9d3c3793f94 core (Cagou): "None" can be used in getVisibleList's cls to get all visible widgets
Goffi <goffi@goffi.org>
parents: 350
diff changeset
792 None to get all visible widgets
e9d3c3793f94 core (Cagou): "None" can be used in getVisibleList's cls to get all visible widgets
Goffi <goffi@goffi.org>
parents: 350
diff changeset
793 @return (set[type]): visible widgets of this class
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
794 """
351
e9d3c3793f94 core (Cagou): "None" can be used in getVisibleList's cls to get all visible widgets
Goffi <goffi@goffi.org>
parents: 350
diff changeset
795 if cls is None:
e9d3c3793f94 core (Cagou): "None" can be used in getVisibleList's cls to get all visible widgets
Goffi <goffi@goffi.org>
parents: 350
diff changeset
796 ret = set()
e9d3c3793f94 core (Cagou): "None" can be used in getVisibleList's cls to get all visible widgets
Goffi <goffi@goffi.org>
parents: 350
diff changeset
797 for widgets in self._visible_widgets.values():
e9d3c3793f94 core (Cagou): "None" can be used in getVisibleList's cls to get all visible widgets
Goffi <goffi@goffi.org>
parents: 350
diff changeset
798 for w in widgets:
e9d3c3793f94 core (Cagou): "None" can be used in getVisibleList's cls to get all visible widgets
Goffi <goffi@goffi.org>
parents: 350
diff changeset
799 ret.add(w)
e9d3c3793f94 core (Cagou): "None" can be used in getVisibleList's cls to get all visible widgets
Goffi <goffi@goffi.org>
parents: 350
diff changeset
800 return ret
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
801 try:
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
802 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
803 except KeyError:
351
e9d3c3793f94 core (Cagou): "None" can be used in getVisibleList's cls to get all visible widgets
Goffi <goffi@goffi.org>
parents: 350
diff changeset
804 return set()
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
805
260
145c29b5f2b5 core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents: 259
diff changeset
806 def deleteUnusedWidgetInstances(self, widget):
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
807 """Delete instance of this widget which are not attached to a WHWrapper
260
145c29b5f2b5 core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents: 259
diff changeset
808
145c29b5f2b5 core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents: 259
diff changeset
809 @param widget(quick_widgets.QuickWidget): reference widget
145c29b5f2b5 core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents: 259
diff changeset
810 other instance of this widget will be deleted if they have no parent
145c29b5f2b5 core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents: 259
diff changeset
811 """
145c29b5f2b5 core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents: 259
diff changeset
812 to_delete = []
267
896f78760b63 core: fixed crash when calling deleteUnusedWidgetInstances on widgets not inheriting from QuickWidget
Goffi <goffi@goffi.org>
parents: 266
diff changeset
813 if isinstance(widget, quick_widgets.QuickWidget):
896f78760b63 core: fixed crash when calling deleteUnusedWidgetInstances on widgets not inheriting from QuickWidget
Goffi <goffi@goffi.org>
parents: 266
diff changeset
814 for w in self.widgets.getWidgetInstances(widget):
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
815 if w.whwrapper is None and w != widget:
267
896f78760b63 core: fixed crash when calling deleteUnusedWidgetInstances on widgets not inheriting from QuickWidget
Goffi <goffi@goffi.org>
parents: 266
diff changeset
816 to_delete.append(w)
896f78760b63 core: fixed crash when calling deleteUnusedWidgetInstances on widgets not inheriting from QuickWidget
Goffi <goffi@goffi.org>
parents: 266
diff changeset
817 for w in to_delete:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
818 log.debug("cleaning widget: {wid}".format(wid=w))
267
896f78760b63 core: fixed crash when calling deleteUnusedWidgetInstances on widgets not inheriting from QuickWidget
Goffi <goffi@goffi.org>
parents: 266
diff changeset
819 self.widgets.deleteWidget(w)
260
145c29b5f2b5 core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents: 259
diff changeset
820
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
821 def getOrClone(self, widget, **kwargs):
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
822 """Get a QuickWidget if it is not in a WHWrapper, else clone it
260
145c29b5f2b5 core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents: 259
diff changeset
823
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
824 if an other instance of this widget exist without being in a WHWrapper
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
825 (i.e. if it is not already in use) it will be used.
260
145c29b5f2b5 core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents: 259
diff changeset
826 """
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
827 if widget.whwrapper is None:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
828 if widget.parent is not None:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
829 widget.parent.remove_widget(widget)
260
145c29b5f2b5 core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents: 259
diff changeset
830 self.deleteUnusedWidgetInstances(widget)
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
831 return widget
260
145c29b5f2b5 core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents: 259
diff changeset
832 for w in self.widgets.getWidgetInstances(widget):
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
833 if w.whwrapper is None:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
834 if w.parent is not None:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
835 w.parent.remove_widget(w)
260
145c29b5f2b5 core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents: 259
diff changeset
836 self.deleteUnusedWidgetInstances(w)
145c29b5f2b5 core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents: 259
diff changeset
837 return w
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
838 targets = list(widget.targets)
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
839 w = self.widgets.getOrCreateWidget(widget.__class__,
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
840 targets[0],
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
841 on_new_widget=None,
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
842 on_existing_widget=C.WIDGET_RECREATE,
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
843 profiles=widget.profiles,
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
844 **kwargs)
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
845 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
846 w.addTarget(t)
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
847 return w
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
848
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
849 def getWidgetToSwitch(self):
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
850 """Choose best candidate when we need to switch widget and old is not specified
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
851
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
852 @return (CagouWidget): widget to switch
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
853 """
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
854 if self.selected_widget is not None:
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
855 return self.selected_widget
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
856 # no widget is selected we check if we have any default widget
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
857 default_cls = self.default_wid['main']
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
858 for w in self.visible_widgets:
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
859 if isinstance(w, default_cls):
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
860 return w
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
861
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
862 # no default widget found, we return the first widget
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
863 return next(iter(self.visible_widgets))
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
864
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
865 def doAction(self, action, target, profiles):
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
866 """Launch an action handler by a plugin
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
867
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
868 @param action(unicode): action to do, can be:
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
869 - chat: open a chat widget
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
870 @param target(unicode): target of the action
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
871 @param profiles(list[unicode]): profiles to use
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
872 """
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
873 try:
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
874 # FIXME: Q&D way to get chat plugin, should be replaced by a clean method
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
875 # in host
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
876 plg_infos = [p for p in self.getPluggedWidgets()
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
877 if action in p['import_name']][0]
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
878 except IndexError:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
879 log.warning("No plugin widget found to do {action}".format(action=action))
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
880 else:
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
881 factory = plg_infos['factory']
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
882 self.switchWidget(None,
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
883 factory(plg_infos, target=target, profiles=profiles))
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
884
51
3f8599d9a766 core: menus first draft:
Goffi <goffi@goffi.org>
parents: 49
diff changeset
885 ## menus ##
3f8599d9a766 core: menus first draft:
Goffi <goffi@goffi.org>
parents: 49
diff changeset
886
112
d654bdfeb404 core: changes menu bridge call, to follow backend
Goffi <goffi@goffi.org>
parents: 97
diff changeset
887 def _menusGetCb(self, backend_menus):
85
c2a7234d13d2 menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents: 78
diff changeset
888 main_menu = self.app.root.root_menus
51
3f8599d9a766 core: menus first draft:
Goffi <goffi@goffi.org>
parents: 49
diff changeset
889 self.menus.addMenus(backend_menus)
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
890 self.menus.addMenu(C.MENU_GLOBAL,
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
891 (_("Help"), _("About")),
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
892 callback=main_menu.onAbout)
51
3f8599d9a766 core: menus first draft:
Goffi <goffi@goffi.org>
parents: 49
diff changeset
893 main_menu.update(C.MENU_GLOBAL)
3f8599d9a766 core: menus first draft:
Goffi <goffi@goffi.org>
parents: 49
diff changeset
894
122
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 119
diff changeset
895 ## bridge handlers ##
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 119
diff changeset
896
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 119
diff changeset
897 def otrStateHandler(self, state, dest_jid, profile):
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 119
diff changeset
898 """OTR state has changed for on destinee"""
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 119
diff changeset
899 # XXX: this method could be in QuickApp but it's here as
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 119
diff changeset
900 # it's only used by Cagou so far
244
5bd94bc08f5c plugin chat: fixed OTR State filtering + removed some legacy code
Goffi <goffi@goffi.org>
parents: 240
diff changeset
901 dest_jid = jid.JID(dest_jid)
5bd94bc08f5c plugin chat: fixed OTR State filtering + removed some legacy code
Goffi <goffi@goffi.org>
parents: 240
diff changeset
902 bare_jid = dest_jid.bare
122
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 119
diff changeset
903 for widget in self.widgets.getWidgets(quick_chat.QuickChat, profiles=(profile,)):
244
5bd94bc08f5c plugin chat: fixed OTR State filtering + removed some legacy code
Goffi <goffi@goffi.org>
parents: 240
diff changeset
904 if widget.type == C.CHAT_ONE2ONE and widget.target == bare_jid:
5bd94bc08f5c plugin chat: fixed OTR State filtering + removed some legacy code
Goffi <goffi@goffi.org>
parents: 240
diff changeset
905 widget.onOTRState(state, dest_jid, profile)
122
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 119
diff changeset
906
266
b3f97729e983 core (debug): added "visible_widgets_dump" action to new _debug signal
Goffi <goffi@goffi.org>
parents: 265
diff changeset
907 def _debugHandler(self, action, parameters, profile):
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
908 if action == "visible_widgets_dump":
266
b3f97729e983 core (debug): added "visible_widgets_dump" action to new _debug signal
Goffi <goffi@goffi.org>
parents: 265
diff changeset
909 from pprint import pformat
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
910 log.info("Visible widgets dump:\n{data}".format(
266
b3f97729e983 core (debug): added "visible_widgets_dump" action to new _debug signal
Goffi <goffi@goffi.org>
parents: 265
diff changeset
911 data=pformat(self._visible_widgets)))
b3f97729e983 core (debug): added "visible_widgets_dump" action to new _debug signal
Goffi <goffi@goffi.org>
parents: 265
diff changeset
912 else:
b3f97729e983 core (debug): added "visible_widgets_dump" action to new _debug signal
Goffi <goffi@goffi.org>
parents: 265
diff changeset
913 return super(Cagou, self)._debugHandler(action, parameters, profile)
b3f97729e983 core (debug): added "visible_widgets_dump" action to new _debug signal
Goffi <goffi@goffi.org>
parents: 265
diff changeset
914
346
7b9a0e57df53 core: new "connected" property in CagouApp
Goffi <goffi@goffi.org>
parents: 342
diff changeset
915 def connectedHandler(self, jid_s, profile):
7b9a0e57df53 core: new "connected" property in CagouApp
Goffi <goffi@goffi.org>
parents: 342
diff changeset
916 # FIXME: this won't work with multiple profiles
7b9a0e57df53 core: new "connected" property in CagouApp
Goffi <goffi@goffi.org>
parents: 342
diff changeset
917 super().connectedHandler(jid_s, profile)
7b9a0e57df53 core: new "connected" property in CagouApp
Goffi <goffi@goffi.org>
parents: 342
diff changeset
918 self.app.connected = True
7b9a0e57df53 core: new "connected" property in CagouApp
Goffi <goffi@goffi.org>
parents: 342
diff changeset
919
7b9a0e57df53 core: new "connected" property in CagouApp
Goffi <goffi@goffi.org>
parents: 342
diff changeset
920 def disconnectedHandler(self, profile):
7b9a0e57df53 core: new "connected" property in CagouApp
Goffi <goffi@goffi.org>
parents: 342
diff changeset
921 # FIXME: this won't work with multiple profiles
7b9a0e57df53 core: new "connected" property in CagouApp
Goffi <goffi@goffi.org>
parents: 342
diff changeset
922 super().disconnectedHandler(profile)
7b9a0e57df53 core: new "connected" property in CagouApp
Goffi <goffi@goffi.org>
parents: 342
diff changeset
923 self.app.connected = False
7b9a0e57df53 core: new "connected" property in CagouApp
Goffi <goffi@goffi.org>
parents: 342
diff changeset
924
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
925 ## misc ##
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
926
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
927 def plugging_profiles(self):
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
928 self._widgets_handler = widgets_handler.WidgetsHandler()
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
929 self.app.root.changeWidget(self._widgets_handler)
112
d654bdfeb404 core: changes menu bridge call, to follow backend
Goffi <goffi@goffi.org>
parents: 97
diff changeset
930 self.bridge.menusGet("", C.NO_SECURITY_LIMIT, callback=self._menusGetCb)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
931
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
932 def setPresenceStatus(self, show='', status=None, profile=C.PROF_KEY_NONE):
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
933 log.info("Profile presence status set to {show}/{status}".format(show=show,
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
934 status=status))
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
935
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
936 def errback(self, failure_, title=_('error'),
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
937 message=_('error while processing: {msg}')):
190
33ac2d2ce5d7 core: new errback method which can be use as a generic way to show error as notes
Goffi <goffi@goffi.org>
parents: 189
diff changeset
938 self.addNote(title, message.format(msg=failure_), level=C.XMLUI_DATA_LVL_WARNING)
33ac2d2ce5d7 core: new errback method which can be use as a generic way to show error as notes
Goffi <goffi@goffi.org>
parents: 189
diff changeset
939
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
940 def addNote(self, title, message, level=C.XMLUI_DATA_LVL_INFO, symbol=None,
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
941 action=None):
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
942 """add a note (message which disappear) to root widget's header"""
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
943 self.app.root.addNote(title, message, level, symbol, action)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
944
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
945 def addNotifUI(self, ui):
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
946 """add a notification with a XMLUI attached
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
947
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
948 @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
949 """
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
950 self.app.root.addNotifUI(ui)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
951
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
952 def addNotifWidget(self, widget):
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
953 """add a notification with a Kivy widget attached
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
954
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
955 @param widget(kivy.uix.Widget): widget to attach to notification
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
956 """
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
957 self.app.root.addNotifWidget(widget)
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
958
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
959 def showUI(self, ui):
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 77
diff changeset
960 """show a XMLUI"""
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
961 self.app.root.changeWidget(ui, "xmlui")
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
962 self.app.root.show("xmlui")
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
963
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 77
diff changeset
964 def showExtraUI(self, widget):
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 77
diff changeset
965 """show any extra widget"""
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 77
diff changeset
966 self.app.root.changeWidget(widget, "extra")
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 77
diff changeset
967 self.app.root.show("extra")
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 77
diff changeset
968
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
969 def closeUI(self):
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
970 self.app.root.show()
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
971 screen = self.app.root._manager.get_screen("extra")
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
972 screen.clear_widgets()
44
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 43
diff changeset
973
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 43
diff changeset
974 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
975 return self.app.default_avatar
61
0b7f10de416e android: android build first draft:
Goffi <goffi@goffi.org>
parents: 60
diff changeset
976
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
977 def _dialog_cb(self, cb, *args, **kwargs):
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
978 """generic dialog callback
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
979
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
980 close dialog then call the callback with given arguments
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
981 """
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
982 def callback():
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
983 self.closeUI()
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
984 cb(*args, **kwargs)
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
985 return callback
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
986
61
0b7f10de416e android: android build first draft:
Goffi <goffi@goffi.org>
parents: 60
diff changeset
987 def showDialog(self, message, title, type="info", answer_cb=None, answer_data=None):
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
988 if type in ('info', 'warning', 'error'):
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
989 self.addNote(title, message, type)
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
990 elif type == "yes/no":
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
991 wid = dialog.ConfirmDialog(title=title, message=message,
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
992 yes_cb=self._dialog_cb(answer_cb,
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
993 True,
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
994 answer_data),
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
995 no_cb=self._dialog_cb(answer_cb,
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
996 False,
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
997 answer_data)
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
998 )
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
999 self.addNotifWidget(wid)
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
1000 else:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
1001 log.warning(_("unknown dialog type: {dialog_type}").format(dialog_type=type))
184
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 176
diff changeset
1002
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1003 def share(self, media_type, data):
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1004 share_wid = ShareWidget(media_type=media_type, data=data)
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1005 try:
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1006 self.showExtraUI(share_wid)
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1007 except Exception as e:
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1008 log.error(e)
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1009 self.closeUI()
184
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 176
diff changeset
1010
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
1011 def desktop_notif(self, message, title='', duration=5000):
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
1012 global notification
184
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 176
diff changeset
1013 if notification is not None:
229
ab523cc967bb core(notification): display a warning and disable notifications if something is going wrong
Goffi <goffi@goffi.org>
parents: 228
diff changeset
1014 try:
ab523cc967bb core(notification): display a warning and disable notifications if something is going wrong
Goffi <goffi@goffi.org>
parents: 228
diff changeset
1015 notification.notify(title=title,
ab523cc967bb core(notification): display a warning and disable notifications if something is going wrong
Goffi <goffi@goffi.org>
parents: 228
diff changeset
1016 message=message,
ab523cc967bb core(notification): display a warning and disable notifications if something is going wrong
Goffi <goffi@goffi.org>
parents: 228
diff changeset
1017 app_name=C.APP_NAME,
ab523cc967bb core(notification): display a warning and disable notifications if something is going wrong
Goffi <goffi@goffi.org>
parents: 228
diff changeset
1018 app_icon=self.app.icon,
ab523cc967bb core(notification): display a warning and disable notifications if something is going wrong
Goffi <goffi@goffi.org>
parents: 228
diff changeset
1019 timeout = duration)
ab523cc967bb core(notification): display a warning and disable notifications if something is going wrong
Goffi <goffi@goffi.org>
parents: 228
diff changeset
1020 except Exception as e:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
1021 log.warning(_("Can't use notifications, disabling: {msg}").format(
229
ab523cc967bb core(notification): display a warning and disable notifications if something is going wrong
Goffi <goffi@goffi.org>
parents: 228
diff changeset
1022 msg = e))
ab523cc967bb core(notification): display a warning and disable notifications if something is going wrong
Goffi <goffi@goffi.org>
parents: 228
diff changeset
1023 notification = None
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1024
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1025 def getParentWHWrapper(self, wid):
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1026 """Retrieve parent WHWrapper instance managing a widget
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1027
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1028 @param wid(Widget): widget to check
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1029 @return (WHWrapper, None): found instance if any, else None
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1030 """
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1031 wh = self.getAncestorWidget(wid, widgets_handler.WHWrapper)
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1032 if wh is None:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1033 # we may have a screen
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1034 try:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1035 sm = wid.screen_manager
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1036 except (exceptions.InternalError, exceptions.NotFound):
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1037 return None
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1038 else:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1039 wh = self.getAncestorWidget(sm, widgets_handler.WHWrapper)
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1040 return wh
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1041
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1042 def getAncestorWidget(self, wid, cls):
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1043 """Retrieve an ancestor of given class
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1044
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1045 @param wid(Widget): current widget
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1046 @param cls(type): class of the ancestor to retrieve
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1047 @return (Widget, None): found instance or None
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1048 """
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1049 parent = wid.parent
331
d36040493434 core: fixed handling of classes with multiple inheritances in getAncestorWidget
Goffi <goffi@goffi.org>
parents: 323
diff changeset
1050 while parent and not isinstance(parent, cls):
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1051 parent = parent.parent
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1052 return parent