Mercurial > libervia-desktop-kivy
annotate src/cagou/plugins/plugin_wid_chat.py @ 106:9909ed7a7a20
moved SimpleXHTMLWidget to a dedicated module
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 15 Jan 2017 21:21:20 +0100 |
parents | ce6ef88f2cff |
children | 7631325e11f4 |
rev | line source |
---|---|
22 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client | |
5 # Copyright (C) 2016 Jérôme Poisson (goffi@goffi.org) | |
6 | |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 | |
21 from sat.core import log as logging | |
22 log = logging.getLogger(__name__) | |
23 from sat.core.i18n import _ | |
24 from cagou.core.constants import Const as C | |
78 | 25 from kivy.uix.boxlayout import BoxLayout |
45 | 26 from kivy.uix.gridlayout import GridLayout |
22 | 27 from kivy.uix.textinput import TextInput |
45 | 28 from kivy.metrics import dp |
22 | 29 from kivy import properties |
30 from sat_frontends.quick_frontend import quick_widgets | |
31 from sat_frontends.quick_frontend import quick_chat | |
106
9909ed7a7a20
moved SimpleXHTMLWidget to a dedicated module
Goffi <goffi@goffi.org>
parents:
105
diff
changeset
|
32 from sat_frontends.tools import jid |
22 | 33 from cagou.core import cagou_widget |
106
9909ed7a7a20
moved SimpleXHTMLWidget to a dedicated module
Goffi <goffi@goffi.org>
parents:
105
diff
changeset
|
34 from cagou.core.image import Image |
22 | 35 from cagou import G |
36 | |
37 | |
38 PLUGIN_INFO = { | |
39 "name": _(u"chat"), | |
40 "main": "Chat", | |
41 "description": _(u"instant messaging with one person or a group"), | |
90
9a6121722669
chat, contact_list, selector: use of new icons from muchoslava
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
42 "icon_small": u"{media}/icons/muchoslava/png/chat_new_32.png", |
9a6121722669
chat, contact_list, selector: use of new icons from muchoslava
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
43 "icon_medium": u"{media}/icons/muchoslava/png/chat_new_44.png" |
22 | 44 } |
45 | |
46 | |
44
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
47 class MessAvatar(Image): |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
48 pass |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
49 |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
50 |
45 | 51 class MessageWidget(GridLayout): |
22 | 52 mess_data = properties.ObjectProperty() |
57 | 53 mess_xhtml = properties.ObjectProperty() |
45 | 54 mess_padding = (dp(5), dp(5)) |
47
abb81efef3bb
chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents:
46
diff
changeset
|
55 avatar = properties.ObjectProperty() |
103
c601e3d40342
chat: display delivery receipt (with a green check mark)
Goffi <goffi@goffi.org>
parents:
102
diff
changeset
|
56 delivery = properties.ObjectProperty() |
47
abb81efef3bb
chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents:
46
diff
changeset
|
57 |
abb81efef3bb
chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents:
46
diff
changeset
|
58 def __init__(self, **kwargs): |
105 | 59 # self must be registered in widgets before kv is parsed |
60 kwargs['mess_data'].widgets.add(self) | |
47
abb81efef3bb
chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents:
46
diff
changeset
|
61 super(MessageWidget, self).__init__(**kwargs) |
105 | 62 avatar_path = self.mess_data.avatar |
63 if avatar_path is not None: | |
64 self.avatar.source = avatar_path | |
44
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
65 |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
66 @property |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
67 def chat(self): |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
68 """return parent Chat instance""" |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
69 return self.mess_data.parent |
22 | 70 |
71 @property | |
72 def message(self): | |
73 """Return currently displayed message""" | |
74 return self.mess_data.main_message | |
75 | |
57 | 76 @property |
77 def message_xhtml(self): | |
78 """Return currently displayed message""" | |
79 return self.mess_data.main_message_xhtml | |
80 | |
45 | 81 def widthAdjust(self): |
22 | 82 """this widget grows up with its children""" |
57 | 83 pass |
84 # parent = self.mess_xhtml.parent | |
85 # padding_x = self.mess_padding[0] | |
86 # text_width, text_height = self.mess_xhtml.texture_size | |
87 # if text_width > parent.width: | |
88 # self.mess_xhtml.text_size = (parent.width - padding_x, None) | |
89 # self.text_max = text_width | |
90 # elif self.mess_xhtml.text_size[0] is not None and text_width < parent.width - padding_x: | |
91 # if text_width < self.text_max: | |
92 # self.mess_xhtml.text_size = (None, None) | |
93 # else: | |
94 # self.mess_xhtml.text_size = (parent.width - padding_x, None) | |
22 | 95 |
54
514c187afebc
chat: changed udpate to use dict instead of single key/value
Goffi <goffi@goffi.org>
parents:
47
diff
changeset
|
96 def update(self, update_dict): |
514c187afebc
chat: changed udpate to use dict instead of single key/value
Goffi <goffi@goffi.org>
parents:
47
diff
changeset
|
97 if 'avatar' in update_dict: |
514c187afebc
chat: changed udpate to use dict instead of single key/value
Goffi <goffi@goffi.org>
parents:
47
diff
changeset
|
98 self.avatar.source = update_dict['avatar'] |
103
c601e3d40342
chat: display delivery receipt (with a green check mark)
Goffi <goffi@goffi.org>
parents:
102
diff
changeset
|
99 if 'status' in update_dict: |
c601e3d40342
chat: display delivery receipt (with a green check mark)
Goffi <goffi@goffi.org>
parents:
102
diff
changeset
|
100 status = update_dict['status'] |
c601e3d40342
chat: display delivery receipt (with a green check mark)
Goffi <goffi@goffi.org>
parents:
102
diff
changeset
|
101 self.delivery.text = u'\u2714' if status == 'delivered' else u'' |
47
abb81efef3bb
chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents:
46
diff
changeset
|
102 |
22 | 103 |
78 | 104 class MessageInputBox(BoxLayout): |
105 pass | |
106 | |
107 | |
22 | 108 class MessageInputWidget(TextInput): |
109 | |
110 def _key_down(self, key, repeat=False): | |
111 displayed_str, internal_str, internal_action, scale = key | |
112 if internal_action == 'enter': | |
113 self.dispatch('on_text_validate') | |
114 else: | |
115 super(MessageInputWidget, self)._key_down(key, repeat) | |
116 | |
117 | |
45 | 118 class MessagesWidget(GridLayout): |
119 pass | |
22 | 120 |
121 | |
122 class Chat(quick_chat.QuickChat, cagou_widget.CagouWidget): | |
78 | 123 message_input = properties.ObjectProperty() |
86 | 124 messages_widget = properties.ObjectProperty() |
22 | 125 |
46
d6a63942d5ad
chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
126 def __init__(self, host, target, type_=C.CHAT_ONE2ONE, nick=None, occupants=None, subject=None, profiles=None): |
d6a63942d5ad
chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
127 quick_chat.QuickChat.__init__(self, host, target, type_, nick, occupants, subject, profiles=profiles) |
22 | 128 cagou_widget.CagouWidget.__init__(self) |
67 | 129 self.header_input.hint_text = u"{}".format(target) |
78 | 130 self.host.addListener('progressError', self.onProgressError, profiles) |
131 self.host.addListener('progressFinished', self.onProgressFinished, profiles) | |
132 self._waiting_pids = {} # waiting progress ids | |
22 | 133 self.postInit() |
134 | |
135 @classmethod | |
136 def factory(cls, plugin_info, target, profiles): | |
137 profiles = list(profiles) | |
138 if len(profiles) > 1: | |
139 raise NotImplementedError(u"Multi-profiles is not available yet for chat") | |
140 if target is None: | |
141 target = G.host.profiles[profiles[0]].whoami | |
142 return G.host.widgets.getOrCreateWidget(cls, target, on_new_widget=None, on_existing_widget=C.WIDGET_RECREATE, profiles=profiles) | |
143 | |
144 def messageDataConverter(self, idx, mess_id): | |
145 return {"mess_data": self.messages[mess_id]} | |
146 | |
147 def _onHistoryPrinted(self): | |
148 """Refresh or scroll down the focus after the history is printed""" | |
149 # self.adapter.data = self.messages | |
150 for mess_data in self.messages.itervalues(): | |
151 self.appendMessage(mess_data) | |
152 super(Chat, self)._onHistoryPrinted() | |
153 | |
154 def createMessage(self, message): | |
155 self.appendMessage(message) | |
156 | |
157 def appendMessage(self, mess_data): | |
158 self.messages_widget.add_widget(MessageWidget(mess_data=mess_data)) | |
159 | |
160 def onSend(self, input_widget): | |
161 G.host.messageSend( | |
162 self.target, | |
163 {'': input_widget.text}, # TODO: handle language | |
164 mess_type = C.MESS_TYPE_GROUPCHAT if self.type == C.CHAT_GROUP else C.MESS_TYPE_CHAT, # TODO: put this in QuickChat | |
165 profile_key=self.profile | |
166 ) | |
167 input_widget.text = '' | |
168 | |
78 | 169 def onProgressFinished(self, progress_id, metadata, profile): |
170 try: | |
88
3dc526bb4a5a
upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents:
86
diff
changeset
|
171 callback, cleaning_cb = self._waiting_pids.pop(progress_id) |
78 | 172 except KeyError: |
173 return | |
88
3dc526bb4a5a
upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents:
86
diff
changeset
|
174 if cleaning_cb is not None: |
3dc526bb4a5a
upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents:
86
diff
changeset
|
175 cleaning_cb() |
78 | 176 callback(metadata, profile) |
177 | |
178 def onProgressError(self, progress_id, err_msg, profile): | |
179 try: | |
88
3dc526bb4a5a
upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents:
86
diff
changeset
|
180 dummy, cleaning_cb = self._waiting_pids[progress_id] |
78 | 181 except KeyError: |
182 return | |
88
3dc526bb4a5a
upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents:
86
diff
changeset
|
183 else: |
3dc526bb4a5a
upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents:
86
diff
changeset
|
184 del self._waiting_pids[progress_id] |
3dc526bb4a5a
upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents:
86
diff
changeset
|
185 if cleaning_cb is not None: |
3dc526bb4a5a
upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents:
86
diff
changeset
|
186 cleaning_cb() |
78 | 187 # TODO: display message to user |
97
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
188 log.warning(u"Can't transfer file: {}".format(err_msg)) |
78 | 189 |
97
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
190 def fileTransferDone(self, metadata, profile): |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
191 log.debug("file transfered: {}".format(metadata)) |
78 | 192 G.host.messageSend( |
193 self.target, | |
194 {'': metadata['url']}, | |
195 mess_type = C.MESS_TYPE_GROUPCHAT if self.type == C.CHAT_GROUP else C.MESS_TYPE_CHAT, | |
196 profile_key=profile | |
197 ) | |
198 | |
97
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
199 def fileTransferCb(self, progress_data, cleaning_cb): |
78 | 200 try: |
201 progress_id = progress_data['progress'] | |
202 except KeyError: | |
203 xmlui = progress_data['xmlui'] | |
204 G.host.showUI(xmlui) | |
205 else: | |
97
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
206 self._waiting_pids[progress_id] = (self.fileTransferDone, cleaning_cb) |
78 | 207 |
98
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
208 def onTransferOK(self, file_path, cleaning_cb, transfer_type): |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
209 if transfer_type == C.TRANSFER_UPLOAD: |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
210 G.host.bridge.fileUpload( |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
211 file_path, |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
212 "", |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
213 "", |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
214 {"ignore_tls_errors": C.BOOL_TRUE}, # FIXME: should not be the default |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
215 self.profile, |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
216 callback = lambda progress_data: self.fileTransferCb(progress_data, cleaning_cb) |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
217 ) |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
218 elif transfer_type == C.TRANSFER_SEND: |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
219 if self.type == C.CHAT_GROUP: |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
220 log.warning(u"P2P transfer is not possible for group chat") |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
221 # TODO: show an error dialog to user, or better hide the send button for MUC |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
222 else: |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
223 jid_ = self.target |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
224 if not jid_.resource: |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
225 jid_ = G.host.contact_lists[self.profile].getFullJid(jid_) |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
226 G.host.bridge.fileSend(jid_, file_path, "", "", profile=self.profile) |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
227 # TODO: notification of sending/failing |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
228 else: |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
229 raise log.error(u"transfer of type {} are not handled".format(transfer_type)) |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
230 |
78 | 231 |
46
d6a63942d5ad
chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
232 def _mucJoinCb(self, joined_data): |
d6a63942d5ad
chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
233 joined, room_jid_s, occupants, user_nick, subject, profile = joined_data |
d6a63942d5ad
chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
234 self.host.mucRoomJoinedHandler(*joined_data[1:]) |
d6a63942d5ad
chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
235 jid_ = jid.JID(room_jid_s) |
42
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
236 self.changeWidget(jid_) |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
237 |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
238 def _mucJoinEb(self, failure): |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
239 log.warning(u"Can't join room: {}".format(failure)) |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
240 |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
241 def changeWidget(self, jid_): |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
242 """change current widget for a new one with given jid |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
243 |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
244 @param jid_(jid.JID): jid of the widget to create |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
245 """ |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
246 plugin_info = G.host.getPluginInfo(main=Chat) |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
247 factory = plugin_info['factory'] |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
248 G.host.switchWidget(self, factory(plugin_info, jid_, profiles=[self.profile])) |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
249 self.header_input.text = '' |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
250 |
22 | 251 def onHeaderInput(self): |
252 text = self.header_input.text.strip() | |
253 try: | |
254 if text.count(u'@') != 1 or text.count(u' '): | |
255 raise ValueError | |
256 jid_ = jid.JID(text) | |
257 except ValueError: | |
258 log.info(u"entered text is not a jid") | |
259 return | |
260 | |
261 def discoCb(disco): | |
262 # TODO: check if plugin XEP-0045 is activated | |
263 if "conference" in [i[0] for i in disco[1]]: | |
42
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
264 G.host.bridge.mucJoin(unicode(jid_), "", "", self.profile, callback=self._mucJoinCb, errback=self._mucJoinEb) |
22 | 265 else: |
42
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
266 self.changeWidget(jid_) |
22 | 267 |
268 def discoEb(failure): | |
269 log.warning(u"Disco failure, ignore this text: {}".format(failure)) | |
270 | |
271 G.host.bridge.discoInfos(jid_.domain, self.profile, callback=discoCb, errback=discoEb) | |
272 | |
78 | 273 def _onDelete(self): |
274 self.host.removeListener('progressFinished', self.onProgressFinished) | |
275 self.host.removeListener('progressError', self.onProgressError) | |
276 return super(Chat, self).onDelete() | |
277 | |
37
6cf08d0ee460
chat: forbid scrolling on X axis + don't delete widget until explicitly requested (with force attribute)
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
278 def onDelete(self, force=False): |
6cf08d0ee460
chat: forbid scrolling on X axis + don't delete widget until explicitly requested (with force attribute)
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
279 if force==True: |
78 | 280 return self._onDelete() |
37
6cf08d0ee460
chat: forbid scrolling on X axis + don't delete widget until explicitly requested (with force attribute)
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
281 if len(list(G.host.widgets.getWidgets(self.__class__, self.target, profiles=self.profiles))) > 1: |
6cf08d0ee460
chat: forbid scrolling on X axis + don't delete widget until explicitly requested (with force attribute)
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
282 # we don't keep duplicate widgets |
78 | 283 return self._onDelete() |
37
6cf08d0ee460
chat: forbid scrolling on X axis + don't delete widget until explicitly requested (with force attribute)
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
284 return False |
22 | 285 |
286 | |
287 PLUGIN_INFO["factory"] = Chat.factory | |
288 quick_widgets.register(quick_chat.QuickChat, Chat) |