Mercurial > libervia-desktop-kivy
comparison cagou/plugins/plugin_wid_chat.py @ 276:a0835f0212d8
chat: multi-lines input:
- text input is now multi-lines and grows with the text (up to a max)
- on touch devices (i.e. on Android), an icon is added to the right to send the message, allowing to use virtual enter key for multi-lines messages
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 20 Mar 2019 09:29:44 +0100 |
parents | 805c4103dac5 |
children | f5302d57fb09 |
comparison
equal
deleted
inserted
replaced
275:1f88e7781fd0 | 276:a0835f0212d8 |
---|---|
16 | 16 |
17 # You should have received a copy of the GNU Affero General Public License | 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/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 | 20 |
21 from functools import partial | |
22 import mimetypes | |
23 import sys | |
21 from sat.core import log as logging | 24 from sat.core import log as logging |
22 log = logging.getLogger(__name__) | |
23 from sat.core.i18n import _ | 25 from sat.core.i18n import _ |
24 from cagou.core.constants import Const as C | 26 from cagou.core.constants import Const as C |
25 from kivy.uix.boxlayout import BoxLayout | 27 from kivy.uix.boxlayout import BoxLayout |
26 from kivy.uix.gridlayout import GridLayout | 28 from kivy.uix.gridlayout import GridLayout |
27 from kivy.uix.textinput import TextInput | 29 from kivy.uix.textinput import TextInput |
28 from kivy.metrics import sp, dp | 30 from kivy.metrics import sp, dp |
31 from kivy.clock import Clock | |
29 from kivy import properties | 32 from kivy import properties |
30 from sat_frontends.quick_frontend import quick_widgets | 33 from sat_frontends.quick_frontend import quick_widgets |
31 from sat_frontends.quick_frontend import quick_chat | 34 from sat_frontends.quick_frontend import quick_chat |
32 from sat_frontends.tools import jid | 35 from sat_frontends.tools import jid |
33 from cagou.core import cagou_widget | 36 from cagou.core import cagou_widget |
35 from cagou.core.image import Image | 38 from cagou.core.image import Image |
36 from cagou.core.common import SymbolButton, JidButton | 39 from cagou.core.common import SymbolButton, JidButton |
37 from kivy.uix.dropdown import DropDown | 40 from kivy.uix.dropdown import DropDown |
38 from kivy.core.window import Window | 41 from kivy.core.window import Window |
39 from cagou import G | 42 from cagou import G |
40 from functools import partial | 43 |
41 import mimetypes | 44 log = logging.getLogger(__name__) |
42 | |
43 | 45 |
44 PLUGIN_INFO = { | 46 PLUGIN_INFO = { |
45 "name": _(u"chat"), | 47 "name": _(u"chat"), |
46 "main": "Chat", | 48 "main": "Chat", |
47 "description": _(u"instant messaging with one person or a group"), | 49 "description": _(u"instant messaging with one person or a group"), |
121 if 'status' in update_dict: | 123 if 'status' in update_dict: |
122 status = update_dict['status'] | 124 status = update_dict['status'] |
123 self.delivery.text = u'\u2714' if status == 'delivered' else u'' | 125 self.delivery.text = u'\u2714' if status == 'delivered' else u'' |
124 | 126 |
125 | 127 |
128 class SendButton(SymbolButton): | |
129 message_input_box = properties.ObjectProperty() | |
130 | |
131 | |
126 class MessageInputBox(BoxLayout): | 132 class MessageInputBox(BoxLayout): |
127 pass | 133 message_input = properties.ObjectProperty() |
134 | |
135 def __init__(self, *args, **kwargs): | |
136 super(MessageInputBox, self).__init__(*args, **kwargs) | |
137 Clock.schedule_once(self.post_init, 0) | |
138 | |
139 def post_init(self, *args): | |
140 if sys.platform == 'android': | |
141 self.add_widget(SendButton(message_input_box=self), 0) | |
142 | |
143 def send_text(self): | |
144 self.message_input.send_text() | |
128 | 145 |
129 | 146 |
130 class MessageInputWidget(TextInput): | 147 class MessageInputWidget(TextInput): |
131 | 148 |
132 def _key_down(self, key, repeat=False): | 149 def keyboard_on_key_down(self, window, keycode, text, modifiers): |
133 displayed_str, internal_str, internal_action, scale = key | 150 # We don't send text when shift is pressed to be able to add line feeds |
134 if internal_action == 'enter': | 151 # (i.e. multi-lines messages). We don't send on Android either as the |
135 self.dispatch('on_text_validate') | 152 # send button appears on this platform. |
136 else: | 153 if (keycode[-1] == "enter" |
137 super(MessageInputWidget, self)._key_down(key, repeat) | 154 and "shift" not in modifiers |
155 and sys.platform != 'android'): | |
156 self.send_text() | |
157 else: | |
158 return super(MessageInputWidget, self).keyboard_on_key_down( | |
159 window, keycode, text, modifiers) | |
160 | |
161 def send_text(self): | |
162 self.dispatch('on_text_validate') | |
138 | 163 |
139 | 164 |
140 class MessagesWidget(GridLayout): | 165 class MessagesWidget(GridLayout): |
141 pass | 166 pass |
142 | 167 |