Mercurial > libervia-desktop-kivy
annotate src/cagou/plugins/plugin_wid_chat.py @ 58:7aa2ffff9067
chat: <img/> tag handling first draft:
We need to have several widgets to handle <img/> (label(s) + image(s)), which make sizing and positioning complicated.
To make things simpler, we use a simple trick when several widgets are present: we split the labels in as many labels as there are words, so we can take profit of the StackLayout.
The split is done after the XHTML is parsed, so after all the widgets are present, and is done only once. This means that label need to be reparsed to be splitted.
This is not perfect, but should be a reasonable solutions until we implement a real XHTML engine (probably CEF widget and Webview).
image sizing and alignment is not handled correcly now, should be fixed soon.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 28 Sep 2016 22:02:36 +0200 |
parents | a51ea7874e43 |
children | 2aa44a82d0e7 |
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 | |
45 | 25 from kivy.uix.gridlayout import GridLayout |
57 | 26 from kivy.uix.stacklayout import StackLayout |
22 | 27 from kivy.uix.scrollview import ScrollView |
28 from kivy.uix.textinput import TextInput | |
57 | 29 from kivy.uix.label import Label |
58
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
30 from kivy.uix.image import AsyncImage |
45 | 31 from kivy.metrics import dp |
57 | 32 from kivy.utils import escape_markup |
22 | 33 from kivy import properties |
34 from sat_frontends.quick_frontend import quick_widgets | |
35 from sat_frontends.quick_frontend import quick_chat | |
57 | 36 from sat_frontends.tools import jid, css_color |
22 | 37 from cagou.core import cagou_widget |
44
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
38 from cagou.core.image import Image |
22 | 39 from cagou import G |
57 | 40 from xml.etree import ElementTree as ET |
22 | 41 |
42 | |
43 PLUGIN_INFO = { | |
44 "name": _(u"chat"), | |
45 "main": "Chat", | |
46 "description": _(u"instant messaging with one person or a group"), | |
25
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
24
diff
changeset
|
47 "icon_small": u"{media}/icons/muchoslava/png/chat_rouge_32.png", |
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
24
diff
changeset
|
48 "icon_medium": u"{media}/icons/muchoslava/png/chat_rouge_44.png" |
22 | 49 } |
50 | |
51 | |
44
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
52 class MessAvatar(Image): |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
53 pass |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
54 |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
55 |
57 | 56 class Escape(unicode): |
57 """Class used to mark that a message need to be escaped""" | |
58 | |
59 def __init__(self, text): | |
60 super(Escape, self).__init__(text) | |
61 | |
62 | |
58
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
63 class SimpleXHTMLWidgetEscapedText(Label): |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
64 pass |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
65 |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
66 class SimpleXHTMLWidgetText(Label): |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
67 pass |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
68 |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
69 class SimpleXHTMLWidgetImage(AsyncImage): |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
70 pass |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
71 |
57 | 72 class SimpleXHTMLWidget(StackLayout): |
73 """widget handling simple XHTML parsing""" | |
74 xhtml = properties.StringProperty() | |
75 color = properties.ListProperty([1, 1, 1, 1]) | |
76 # XXX: bold is only used for escaped text | |
77 bold = properties.BooleanProperty(False) | |
58
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
78 content_width = properties.NumericProperty(0) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
79 |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
80 # text/XHTML input |
57 | 81 |
82 def on_xhtml(self, instance, xhtml): | |
83 """parse xhtml and set content accordingly | |
84 | |
85 if xhtml is an instance of Escape, a Label with not markup | |
86 will be used | |
87 """ | |
88 self.clear_widgets() | |
89 if isinstance(xhtml, Escape): | |
58
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
90 label = SimpleXHTMLWidgetEscapedText(text=xhtml, color=self.color) |
57 | 91 self.bind(color=label.setter('color')) |
92 self.bind(bold=label.setter('bold')) | |
93 self.add_widget(label) | |
94 else: | |
95 xhtml = ET.fromstring(xhtml.encode('utf-8')) | |
96 self.current_wid = None | |
97 self.styles = [] | |
98 self._callParseMethod(xhtml) | |
99 | |
100 def escape(self, text): | |
101 """mark that a text need to be escaped (i.e. no markup)""" | |
102 return Escape(text) | |
103 | |
58
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
104 # sizing |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
105 |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
106 def on_width(self, instance, width): |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
107 if len(self.children) == 1: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
108 wid = self.children[0] |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
109 if isinstance(wid, Label): |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
110 try: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
111 full_width = wid._full_width |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
112 except AttributeError: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
113 wid.size_hint = (None, None) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
114 wid.texture_update() |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
115 full_width = wid._full_width = wid.texture_size[0] |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
116 if full_width > width: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
117 wid.text_size = width, None |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
118 else: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
119 wid.text_size = None, None |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
120 self.content_width = wid.width + self.padding[0] + self.padding[2] |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
121 else: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
122 wid.size_hint(1, None) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
123 wid.height = 100 |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
124 self.content_width = self.width |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
125 else: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
126 self._do_complexe_sizing(width) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
127 |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
128 def _do_complexe_sizing(self, width): |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
129 try: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
130 self.splitted |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
131 except AttributeError: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
132 # XXX: to make things easier, we split labels in words |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
133 log.debug(u"split start") |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
134 children = self.children[::-1] |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
135 self.clear_widgets() |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
136 for child in children: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
137 if isinstance(child, Label): |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
138 log.debug(u"label before split: {}".format(child.text)) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
139 styles = [] |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
140 tag = False |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
141 new_text = [] |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
142 current_tag = [] |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
143 current_value = [] |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
144 current_wid = self._createText() |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
145 value = False |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
146 close = False |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
147 # we will parse the text and create a new widget |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
148 # on each new word (actually each space) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
149 # FIXME: handle '\n' and other white chars |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
150 for c in child.text: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
151 if tag: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
152 # we are parsing a markup tag |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
153 if c == u']': |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
154 current_tag_s = u''.join(current_tag) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
155 current_style = (current_tag_s, u''.join(current_value)) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
156 if close: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
157 for idx, s in enumerate(reversed(styles)): |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
158 if s[0] == current_tag_s: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
159 del styles[len(styles) - idx - 1] |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
160 break |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
161 else: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
162 styles.append(current_style) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
163 current_tag = [] |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
164 current_value = [] |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
165 tag = False |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
166 value = False |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
167 close = False |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
168 elif c == u'/': |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
169 close = True |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
170 elif c == u'=': |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
171 value = True |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
172 elif value: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
173 current_value.append(c) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
174 else: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
175 current_tag.append(c) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
176 new_text.append(c) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
177 else: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
178 # we are parsing regular text |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
179 if c == u'[': |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
180 new_text.append(c) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
181 tag = True |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
182 elif c == u' ': |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
183 # new word, we do a new widget |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
184 new_text.append(u' ') |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
185 for t, v in reversed(styles): |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
186 new_text.append(u'[/{}]'.format(t)) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
187 current_wid.text = u''.join(new_text) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
188 new_text = [] |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
189 self.add_widget(current_wid) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
190 log.debug(u"new widget: {}".format(current_wid.text)) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
191 current_wid = self._createText() |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
192 for t, v in styles: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
193 new_text.append(u'[{tag}{value}]'.format( |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
194 tag = t, |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
195 value = u'={}'.format(v) if v else u'')) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
196 else: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
197 new_text.append(c) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
198 if current_wid.text: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
199 # we may have a remaining widget after the parsing |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
200 close_styles = [] |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
201 for t, v in reversed(styles): |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
202 close_styles.append(u'[/{}]'.format(t)) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
203 current_wid.text = u''.join(close_styles) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
204 self.add_widget(current_wid) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
205 log.debug(u"new widget: {}".format(current_wid.text)) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
206 else: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
207 # non Label widgets, we just add them |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
208 self.add_widget(child) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
209 self.splitted = True |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
210 log.debug(u"split OK") |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
211 |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
212 # we now set the content width |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
213 # FIXME: for now we just use the full width |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
214 self.content_width = width |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
215 |
57 | 216 # XHTML parsing methods |
217 | |
218 def _callParseMethod(self, e): | |
219 """call the suitable method to parse the element | |
220 | |
221 self.xhtml_[tag] will be called if it exists, else | |
222 self.xhtml_generic will be used | |
223 @param e(ET.Element): element to parse | |
224 """ | |
225 try: | |
226 method = getattr(self, "xhtml_{}".format(e.tag)) | |
227 except AttributeError: | |
228 log.warning(u"Unhandled XHTML tag: {}".format(e.tag)) | |
229 method = self.xhtml_generic | |
230 method(e) | |
231 | |
232 def _addStyle(self, tag, value=None, append_to_list=True): | |
233 """add a markup style to label | |
234 | |
235 @param tag(unicode): markup tag | |
236 @param value(unicode): markup value if suitable | |
237 @param append_to_list(bool): if True style we be added to self.styles | |
238 self.styles is needed to keep track of styles to remove | |
239 should most probably be set to True | |
240 """ | |
241 label = self._getLabel() | |
242 label.text += u'[{tag}{value}]'.format( | |
243 tag = tag, | |
244 value = u'={}'.format(value) if value else '' | |
245 ) | |
58
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
246 if append_to_list: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
247 self.styles.append((tag, value)) |
57 | 248 |
249 def _removeStyle(self, tag, remove_from_list=True): | |
250 """remove a markup style from the label | |
251 | |
252 @param tag(unicode): markup tag to remove | |
253 @param remove_from_list(bool): if True, remove from self.styles too | |
254 should most probably be set to True | |
255 """ | |
256 label = self._getLabel() | |
257 label.text += u'[/{tag}]'.format( | |
258 tag = tag | |
259 ) | |
260 if remove_from_list: | |
261 for rev_idx, style in enumerate(reversed(self.styles)): | |
262 if style[0] == tag: | |
263 tag_idx = len(self.styles) - 1 - rev_idx | |
264 del self.styles[tag_idx] | |
265 break | |
266 | |
267 def _getLabel(self): | |
268 """get current Label if it exists, or create a new one""" | |
269 if not isinstance(self.current_wid, Label): | |
270 self._addLabel() | |
271 return self.current_wid | |
272 | |
273 def _addLabel(self): | |
274 """add a new Label | |
275 | |
276 current styles will be closed and reopened if needed | |
277 """ | |
278 self._closeLabel() | |
58
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
279 self.current_wid = self._createText() |
57 | 280 for tag, value in self.styles: |
281 self._addStyle(tag, value, append_to_list=False) | |
282 self.add_widget(self.current_wid) | |
283 | |
58
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
284 def _createText(self): |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
285 label = SimpleXHTMLWidgetText(color=self.color, markup=True) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
286 self.bind(color=label.setter('color')) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
287 label.bind(texture_size=label.setter('size')) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
288 return label |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
289 |
57 | 290 def _closeLabel(self): |
291 """close current style tags in current label | |
292 | |
293 needed when you change label to keep style between | |
294 different widgets | |
295 """ | |
296 if isinstance(self.current_wid, Label): | |
297 for tag, value in reversed(self.styles): | |
298 self._removeStyle(tag, remove_from_list=False) | |
299 | |
300 def _parseCSS(self, e): | |
301 """parse CSS found in "style" attribute of element | |
302 | |
303 self._css_styles will be created and contained markup styles added by this method | |
304 @param e(ET.Element): element which may have a "style" attribute | |
305 """ | |
306 styles_limit = len(self.styles) | |
307 styles = e.attrib['style'].split(u';') | |
308 for style in styles: | |
309 try: | |
310 prop, value = style.split(u':') | |
311 except ValueError: | |
312 log.warning(u"can't parse style: {}".format(style)) | |
313 continue | |
314 prop = prop.strip().replace(u'-', '_') | |
315 value = value.strip() | |
316 try: | |
317 method = getattr(self, "css_{}".format(prop)) | |
318 except AttributeError: | |
319 log.warning(u"Unhandled CSS: {}".format(prop)) | |
320 else: | |
321 method(e, value) | |
322 self._css_styles = self.styles[styles_limit:] | |
323 | |
324 def _closeCSS(self): | |
325 """removed CSS styles | |
326 | |
327 styles in self._css_styles will be removed | |
328 and the attribute will be deleted | |
329 """ | |
330 for tag, dummy in reversed(self._css_styles): | |
331 self._removeStyle(tag) | |
332 del self._css_styles | |
333 | |
334 def xhtml_generic(self, elem, style=True, markup=None): | |
335 """generic method for adding HTML elements | |
336 | |
337 this method handle content, style and children parsing | |
338 @param elem(ET.Element): element to add | |
339 @param style(bool): if True handle style attribute (CSS) | |
340 @param markup(tuple[unicode, (unicode, None)], None): kivy markup to use | |
341 """ | |
342 # we first add markup and CSS style | |
343 if markup is not None: | |
344 if isinstance(markup, basestring): | |
345 tag, value = markup, None | |
346 else: | |
347 tag, value = markup | |
348 self._addStyle(tag, value) | |
349 style_ = 'style' in elem.attrib and style | |
350 if style_: | |
351 self._parseCSS(elem) | |
352 | |
353 # then content | |
354 if elem.text: | |
355 self._getLabel().text += escape_markup(elem.text) | |
356 | |
357 # we parse the children | |
358 for child in elem: | |
359 self._callParseMethod(child) | |
360 | |
361 # closing CSS style and markup | |
362 if style_: | |
363 self._closeCSS() | |
364 if markup is not None: | |
365 self._removeStyle(tag) | |
366 | |
367 # and the tail, which is regular text | |
368 if elem.tail: | |
369 self._getLabel().text += escape_markup(elem.tail) | |
370 | |
371 # method handling XHTML elements | |
372 | |
373 def xhtml_br(self, elem): | |
374 label = self._getLabel() | |
375 label.text+='\n' | |
376 self.xhtml_generic(style=False) | |
377 | |
378 def xhtml_em(self, elem): | |
379 self.xhtml_generic(elem, markup='i') | |
380 | |
58
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
381 def xhtml_img(self, elem): |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
382 try: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
383 src = elem.attrib['src'] |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
384 except KeyError: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
385 log.warning(u"<img> element without src: {}".format(ET.tostring(elem))) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
386 return |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
387 img = SimpleXHTMLWidgetImage(source=src) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
388 self.current_wid = img |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
389 self.add_widget(img) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
390 |
57 | 391 def xhtml_p(self, elem): |
58
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
392 if isinstance(self.current_wid, Label): |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
393 self.current_wid.text+="\n\n" |
57 | 394 self.xhtml_generic(elem) |
395 | |
396 def xhtml_span(self, elem): | |
397 self.xhtml_generic(elem) | |
398 | |
399 def xhtml_strong(self, elem): | |
400 self.xhtml_generic(elem, markup='b') | |
401 | |
402 # methods handling CSS properties | |
403 | |
404 def css_color(self, elem, value): | |
405 self._addStyle(u"color", css_color.parse(value)) | |
406 | |
407 def css_text_decoration(self, elem, value): | |
408 if value == u'underline': | |
409 log.warning(u"{} not handled yet, it needs Kivy 1.9.2 to be released".format(value)) | |
410 # FIXME: activate when 1.9.2 is out | |
411 # self._addStyle('u') | |
412 elif value == u'line-through': | |
413 log.warning(u"{} not handled yet, it needs Kivy 1.9.2 to be released".format(value)) | |
414 # FIXME: activate when 1.9.2 is out | |
415 # self._addStyle('s') | |
416 else: | |
417 log.warning(u"unhandled text decoration: {}".format(value)) | |
418 | |
419 | |
45 | 420 class MessageWidget(GridLayout): |
22 | 421 mess_data = properties.ObjectProperty() |
57 | 422 mess_xhtml = properties.ObjectProperty() |
45 | 423 mess_padding = (dp(5), dp(5)) |
47
abb81efef3bb
chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents:
46
diff
changeset
|
424 avatar = properties.ObjectProperty() |
abb81efef3bb
chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents:
46
diff
changeset
|
425 |
abb81efef3bb
chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents:
46
diff
changeset
|
426 def __init__(self, **kwargs): |
abb81efef3bb
chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents:
46
diff
changeset
|
427 super(MessageWidget, self).__init__(**kwargs) |
abb81efef3bb
chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents:
46
diff
changeset
|
428 self.mess_data.widgets.add(self) |
44
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
429 |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
430 @property |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
431 def chat(self): |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
432 """return parent Chat instance""" |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
433 return self.mess_data.parent |
22 | 434 |
435 @property | |
436 def message(self): | |
437 """Return currently displayed message""" | |
438 return self.mess_data.main_message | |
439 | |
57 | 440 @property |
441 def message_xhtml(self): | |
442 """Return currently displayed message""" | |
443 return self.mess_data.main_message_xhtml | |
444 | |
45 | 445 def widthAdjust(self): |
22 | 446 """this widget grows up with its children""" |
57 | 447 pass |
448 # parent = self.mess_xhtml.parent | |
449 # padding_x = self.mess_padding[0] | |
450 # text_width, text_height = self.mess_xhtml.texture_size | |
451 # if text_width > parent.width: | |
452 # self.mess_xhtml.text_size = (parent.width - padding_x, None) | |
453 # self.text_max = text_width | |
454 # elif self.mess_xhtml.text_size[0] is not None and text_width < parent.width - padding_x: | |
455 # if text_width < self.text_max: | |
456 # self.mess_xhtml.text_size = (None, None) | |
457 # else: | |
458 # self.mess_xhtml.text_size = (parent.width - padding_x, None) | |
22 | 459 |
54
514c187afebc
chat: changed udpate to use dict instead of single key/value
Goffi <goffi@goffi.org>
parents:
47
diff
changeset
|
460 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
|
461 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
|
462 self.avatar.source = update_dict['avatar'] |
47
abb81efef3bb
chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents:
46
diff
changeset
|
463 |
22 | 464 |
465 class MessageInputWidget(TextInput): | |
466 | |
467 def _key_down(self, key, repeat=False): | |
468 displayed_str, internal_str, internal_action, scale = key | |
469 if internal_action == 'enter': | |
470 self.dispatch('on_text_validate') | |
471 else: | |
472 super(MessageInputWidget, self)._key_down(key, repeat) | |
473 | |
474 | |
45 | 475 class MessagesWidget(GridLayout): |
476 pass | |
22 | 477 |
478 | |
479 class Chat(quick_chat.QuickChat, cagou_widget.CagouWidget): | |
480 | |
46
d6a63942d5ad
chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
481 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
|
482 quick_chat.QuickChat.__init__(self, host, target, type_, nick, occupants, subject, profiles=profiles) |
22 | 483 cagou_widget.CagouWidget.__init__(self) |
484 self.header_input.hint_text = u"You are talking with {}".format(target) | |
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
|
485 scroll_view = ScrollView(size_hint=(1,0.8), scroll_y=0, do_scroll_x=False) |
22 | 486 self.messages_widget = MessagesWidget() |
487 scroll_view.add_widget(self.messages_widget) | |
488 self.add_widget(scroll_view) | |
489 message_input = MessageInputWidget() | |
490 message_input.bind(on_text_validate=self.onSend) | |
491 self.add_widget(message_input) | |
492 self.postInit() | |
493 | |
494 @classmethod | |
495 def factory(cls, plugin_info, target, profiles): | |
496 profiles = list(profiles) | |
497 if len(profiles) > 1: | |
498 raise NotImplementedError(u"Multi-profiles is not available yet for chat") | |
499 if target is None: | |
500 target = G.host.profiles[profiles[0]].whoami | |
501 return G.host.widgets.getOrCreateWidget(cls, target, on_new_widget=None, on_existing_widget=C.WIDGET_RECREATE, profiles=profiles) | |
502 | |
503 def messageDataConverter(self, idx, mess_id): | |
504 return {"mess_data": self.messages[mess_id]} | |
505 | |
506 def _onHistoryPrinted(self): | |
507 """Refresh or scroll down the focus after the history is printed""" | |
508 # self.adapter.data = self.messages | |
509 for mess_data in self.messages.itervalues(): | |
510 self.appendMessage(mess_data) | |
511 super(Chat, self)._onHistoryPrinted() | |
512 | |
513 def createMessage(self, message): | |
514 self.appendMessage(message) | |
515 | |
516 def appendMessage(self, mess_data): | |
517 self.messages_widget.add_widget(MessageWidget(mess_data=mess_data)) | |
518 | |
519 def onSend(self, input_widget): | |
520 G.host.messageSend( | |
521 self.target, | |
522 {'': input_widget.text}, # TODO: handle language | |
523 mess_type = C.MESS_TYPE_GROUPCHAT if self.type == C.CHAT_GROUP else C.MESS_TYPE_CHAT, # TODO: put this in QuickChat | |
524 profile_key=self.profile | |
525 ) | |
526 input_widget.text = '' | |
527 | |
46
d6a63942d5ad
chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
528 def _mucJoinCb(self, joined_data): |
d6a63942d5ad
chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
529 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
|
530 self.host.mucRoomJoinedHandler(*joined_data[1:]) |
d6a63942d5ad
chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
531 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
|
532 self.changeWidget(jid_) |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
533 |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
534 def _mucJoinEb(self, failure): |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
535 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
|
536 |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
537 def changeWidget(self, jid_): |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
538 """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
|
539 |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
540 @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
|
541 """ |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
542 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
|
543 factory = plugin_info['factory'] |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
544 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
|
545 self.header_input.text = '' |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
546 |
22 | 547 def onHeaderInput(self): |
548 text = self.header_input.text.strip() | |
549 try: | |
550 if text.count(u'@') != 1 or text.count(u' '): | |
551 raise ValueError | |
552 jid_ = jid.JID(text) | |
553 except ValueError: | |
554 log.info(u"entered text is not a jid") | |
555 return | |
556 | |
557 def discoCb(disco): | |
558 # TODO: check if plugin XEP-0045 is activated | |
559 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
|
560 G.host.bridge.mucJoin(unicode(jid_), "", "", self.profile, callback=self._mucJoinCb, errback=self._mucJoinEb) |
22 | 561 else: |
42
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
562 self.changeWidget(jid_) |
22 | 563 |
564 def discoEb(failure): | |
565 log.warning(u"Disco failure, ignore this text: {}".format(failure)) | |
566 | |
567 G.host.bridge.discoInfos(jid_.domain, self.profile, callback=discoCb, errback=discoEb) | |
568 | |
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
|
569 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
|
570 if force==True: |
47
abb81efef3bb
chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents:
46
diff
changeset
|
571 return super(Chat, 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
|
572 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
|
573 # we don't keep duplicate widgets |
47
abb81efef3bb
chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents:
46
diff
changeset
|
574 return super(Chat, 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
|
575 return False |
22 | 576 |
577 | |
578 PLUGIN_INFO["factory"] = Chat.factory | |
579 quick_widgets.register(quick_chat.QuickChat, Chat) |