Mercurial > libervia-desktop-kivy
annotate cagou/plugins/plugin_wid_chat.kv @ 325:5868a5575e01
chat: cleaning + some improvments:
- code cleaning, removed some dead code
- some improvments on the way size is calculated, removed unnecessary sizing methods which
were linked to properties
- image have now a max size, this avoid gigantic image in the whole screen
- in SimpleXHTMLWidget, Label are now splitted when xhtml is set
- use a DelayedBoxLayout for messages, as they are really slow to be resized
- use of RecycleView has been investigated, but it is not currently usable as dynamic
contents are not propertly handled (see https://github.com/kivy/kivy/issues/6580 and
https://github.com/kivy/kivy/issues/6582). Furthermore, some tests with RecycleView on
Android don't give the expected speed boost, so BoxLayout still seems like the way to go
for the moment. To be re-investigated at a later point if necessary.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 06 Dec 2019 13:25:31 +0100 |
parents | e2b51663d8b8 |
children | d9d2b56f46db |
rev | line source |
---|---|
22 | 1 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client |
282 | 2 # Copyright (C) 2016-2019 Jérôme Poisson (goffi@goffi.org) |
22 | 3 |
4 # This program is free software: you can redistribute it and/or modify | |
5 # it under the terms of the GNU Affero General Public License as published by | |
6 # the Free Software Foundation, either version 3 of the License, or | |
7 # (at your option) any later version. | |
8 | |
9 # This program is distributed in the hope that it will be useful, | |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 # GNU Affero General Public License for more details. | |
13 | |
14 # You should have received a copy of the GNU Affero General Public License | |
15 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | |
104
663e44f30092
chat: added gettext call for hint_text in input
Goffi <goffi@goffi.org>
parents:
103
diff
changeset
|
17 #:import _ sat.core.i18n._ |
116
8576d70ff803
chat: message header is hidden for info messages
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
18 #:import C cagou.core.constants.Const |
133
c3aa71daceb8
plugin chat: use bold for nicknames in messages headers
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
19 #:import escape kivy.utils.escape_markup |
325 | 20 #:import SimpleXHTMLWidget cagou.core.simple_xhtml.SimpleXHTMLWidget |
21 #:import DelayedBoxLayout cagou.core.common_widgets.DelayedBoxLayout | |
97
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
86
diff
changeset
|
22 |
44
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
31
diff
changeset
|
23 |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
31
diff
changeset
|
24 <MessAvatar>: |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
31
diff
changeset
|
25 size_hint: None, None |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
31
diff
changeset
|
26 size: dp(30), dp(30) |
132
7ad965999d47
plugin chat: draw a background for avatars
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
27 canvas.before: |
7ad965999d47
plugin chat: draw a background for avatars
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
28 Color: |
7ad965999d47
plugin chat: draw a background for avatars
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
29 rgba: (0.87,0.87,0.87,1) |
7ad965999d47
plugin chat: draw a background for avatars
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
30 RoundedRectangle: |
7ad965999d47
plugin chat: draw a background for avatars
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
31 radius: [dp(5)] |
7ad965999d47
plugin chat: draw a background for avatars
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
32 pos: self.pos |
7ad965999d47
plugin chat: draw a background for avatars
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
33 size: self.size |
44
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
31
diff
changeset
|
34 |
22 | 35 |
36 <MessageWidget>: | |
24
bc15b55a4114
chat: better bubble and time resizing
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
37 size_hint: 1, None |
47
abb81efef3bb
chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
38 avatar: avatar |
103
c601e3d40342
chat: display delivery receipt (with a green check mark)
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
39 delivery: delivery |
138 | 40 mess_xhtml: mess_xhtml |
325 | 41 right_part: right_part |
42 header_box: header_box | |
43 height: self.minimum_height | |
45 | 44 BoxLayout: |
138 | 45 orientation: 'vertical' |
46 width: avatar.width | |
47 size_hint: None, 1 | |
45 | 48 MessAvatar: |
49 id: avatar | |
325 | 50 source: (root.mess_data.avatar or '') if root.mess_data else '' |
138 | 51 Widget: |
52 # use to push the avatar on the top | |
53 size_hint: 1, 1 | |
22 | 54 BoxLayout: |
325 | 55 size_hint: 1, None |
138 | 56 orientation: 'vertical' |
57 id: right_part | |
325 | 58 height: header_box.height + mess_xhtml.height |
138 | 59 BoxLayout: |
60 id: header_box | |
61 size_hint: 1, None | |
325 | 62 height: time_label.height if root.mess_type != C.MESS_TYPE_INFO else 0 |
63 opacity: 1 if root.mess_type != C.MESS_TYPE_INFO else 0 | |
138 | 64 Label: |
65 id: time_label | |
325 | 66 color: (0, 0, 0, 1) if root.own_mess else (0.55,0.55,0.55,1) |
185
ab3f5173ef5c
chat, simple XHTML: font size adjustement
Goffi <goffi@goffi.org>
parents:
167
diff
changeset
|
67 font_size: root.font_size |
138 | 68 text_size: None, None |
69 size_hint: None, None | |
70 size: self.texture_size | |
71 padding: dp(5), 0 | |
72 markup: True | |
73 valign: 'middle' | |
325 | 74 text: u"[b]{}[/b], {}".format(escape(root.nick), root.time_text) |
138 | 75 Label: |
76 id: delivery | |
274 | 77 color: C.COLOR_BTN_LIGHT |
185
ab3f5173ef5c
chat, simple XHTML: font size adjustement
Goffi <goffi@goffi.org>
parents:
167
diff
changeset
|
78 font_size: root.font_size |
138 | 79 text_size: None, None |
80 size_hint: None, None | |
81 size: self.texture_size | |
82 padding: dp(5), 0 | |
83 # XXX: DejaVuSans font is needed as check mark is not in Roboto | |
84 # this can be removed when Kivy will be able to handle fallback mechanism | |
85 # which will allow us to use fonts with more unicode characters | |
86 font_name: "DejaVuSans" | |
87 text: u'' | |
57 | 88 SimpleXHTMLWidget: |
89 id: mess_xhtml | |
138 | 90 size_hint: 1, None |
58
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
91 height: self.minimum_height |
57 | 92 xhtml: root.message_xhtml or self.escape(root.message or u' ') |
325 | 93 color: (0.74,0.74,0.24,1) if root.mess_type == "info" else (0, 0, 0, 1) |
45 | 94 padding: root.mess_padding |
325 | 95 bold: True if root.mess_type == "info" else False |
96 | |
45 | 97 |
86 | 98 <Chat>: |
325 | 99 message_input: message_input |
86 | 100 messages_widget: messages_widget |
101 ScrollView: | |
102 scroll_y: 0 | |
103 do_scroll_x: False | |
167
ffef21fd97a2
chat: allow to scroll using side bar + increased bar size
Goffi <goffi@goffi.org>
parents:
153
diff
changeset
|
104 scroll_type: ['bars', 'content'] |
ffef21fd97a2
chat: allow to scroll using side bar + increased bar size
Goffi <goffi@goffi.org>
parents:
153
diff
changeset
|
105 bar_width: dp(6) |
325 | 106 DelayedBoxLayout: |
86 | 107 id: messages_widget |
325 | 108 size_hint_y: None |
109 padding: [app.MARGIN_LEFT, 0, app.MARGIN_RIGHT, dp(10)] | |
110 spacing: dp(10) | |
111 height: self.minimum_height | |
112 orientation: 'vertical' | |
86 | 113 MessageInputBox: |
78 | 114 size_hint: 1, None |
276 | 115 height: self.minimum_height |
252
fdda914a298b
chat: added some padding in MessageInputBox
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
116 spacing: dp(10) |
274 | 117 padding: [app.MARGIN_LEFT, 0, app.MARGIN_RIGHT, dp(10)] |
86 | 118 message_input: message_input |
119 MessageInputWidget: | |
120 id: message_input | |
276 | 121 size_hint: 1, None |
122 height: min(self.minimum_height, dp(250)) | |
123 multiline: True | |
104
663e44f30092
chat: added gettext call for hint_text in input
Goffi <goffi@goffi.org>
parents:
103
diff
changeset
|
124 hint_text: _(u"Enter your message here") |
86 | 125 on_text_validate: root.onSend(args[0]) |
117 | 126 |
276 | 127 |
128 <SendButton>: | |
129 # SendButton is only shown on touch devices | |
130 symbol: "forward" | |
131 size_hint: None, 1 | |
132 width: dp(30) | |
133 font_size: dp(25) | |
134 on_release: self.message_input_box.send_text() | |
135 | |
278
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
136 # Buttons added in header |
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
137 |
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
138 <TransferButton>: |
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
139 size_hint: None, 1 |
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
140 symbol: "plus-circled" |
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
141 width: dp(30) |
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
142 font_size: dp(25) |
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
143 color: 0.4, 0.4, 0.4, 1 |
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
144 |
287
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
145 <MenuButton@Button> |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
146 size_hint_y: None |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
147 height: dp(30) |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
148 on_texture_size: self.parent.parent.width = max(self.parent.parent.width, self.texture_size[0] + dp(10)) |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
149 |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
150 <ExtraMenu>: |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
151 auto_width: False |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
152 MenuButton: |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
153 text: _("Bookmarks") |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
154 on_release: root.select("bookmark") |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
155 |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
156 <ExtraButton>: |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
157 size_hint: None, 1 |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
158 symbol: "dot-3-vert" |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
159 width: dp(30) |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
160 font_size: dp(25) |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
161 color: 0.4, 0.4, 0.4, 1 |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
162 on_release: self.chat.extra_menu.open(self) |
276 | 163 |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
164 <EncryptionMainButton>: |
117 | 165 size_hint: None, 1 |
166 width: dp(30) | |
135
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
133
diff
changeset
|
167 color: self.getColor() |
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
133
diff
changeset
|
168 symbol: self.getSymbol() |
117 | 169 |
242
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
170 <TrustManagementButton>: |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
171 symbol: "shield" |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
172 padding: dp(5), dp(10) |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
173 bg_color: app.c_prim_dark |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
174 size_hint: None, 1 |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
175 width: dp(30) |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
176 on_release: self.parent.dispatch("on_trust_release") |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
177 |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
178 <EncryptionButton>: |
117 | 179 size_hint: None, None |
242
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
180 width: self.parent.parent.best_width if self.parent is not None else 30 |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
181 height: dp(30) |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
182 on_best_width: self.parent.parent.best_width = max(self.parent.parent.best_width, args[1]) |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
183 Button: |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
184 text: root.text |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
185 size_hint: 1, 1 |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
186 padding: dp(5), dp(10) |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
187 color: 0, 0, 0, 1 |
312 | 188 bold: root.bold |
242
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
189 background_normal: app.expand('{media}/misc/borders/border_filled_black.png') |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
190 background_color: app.c_sec if root.selected else app.c_prim_dark |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
191 on_release: root.dispatch("on_release") |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
192 on_texture_size: root.best_width = self.texture_size[0] + (dp(30) if root.trust_button else 0) |
117 | 193 |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
194 <EncryptionMenu>: |
117 | 195 size_hint_x: None |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
196 width: self.container.minimum_width |
117 | 197 auto_width: False |
198 canvas.before: | |
199 Color: | |
200 rgba: 0, 0, 0, 1 | |
201 Rectangle: | |
202 pos: self.pos | |
203 size: self.size |