Mercurial > libervia-desktop-kivy
comparison src/cagou/plugins/plugin_wid_chat.py @ 45:b0595a33465d
chat: design improvments:
- all message are now on the same side, no more left/right which can be difficult to read on big screen
- use of GridLayout for MessageWidget and MessagesWidget, as the minimum_height attribute simplify size handling. This attribute will be present in BoxLayout too in Kivy 1.9.2, so we may switch back in the future
- info messages are displayed in yellow with a black background
- nick and date are now displayed in the same label
- avatar, nick and date are on the same line just above the message bubble
- padding/spacing adjustments
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 04 Sep 2016 19:38:21 +0200 |
parents | 7819e9efa250 |
children | d6a63942d5ad |
comparison
equal
deleted
inserted
replaced
44:7819e9efa250 | 45:b0595a33465d |
---|---|
20 | 20 |
21 from sat.core import log as logging | 21 from sat.core import log as logging |
22 log = logging.getLogger(__name__) | 22 log = logging.getLogger(__name__) |
23 from sat.core.i18n import _ | 23 from sat.core.i18n import _ |
24 from cagou.core.constants import Const as C | 24 from cagou.core.constants import Const as C |
25 from kivy.uix.boxlayout import BoxLayout | 25 from kivy.uix.gridlayout import GridLayout |
26 from kivy.uix.scrollview import ScrollView | 26 from kivy.uix.scrollview import ScrollView |
27 from kivy.uix.textinput import TextInput | 27 from kivy.uix.textinput import TextInput |
28 from kivy.metrics import dp | |
28 from kivy import properties | 29 from kivy import properties |
29 from sat_frontends.quick_frontend import quick_widgets | 30 from sat_frontends.quick_frontend import quick_widgets |
30 from sat_frontends.quick_frontend import quick_chat | 31 from sat_frontends.quick_frontend import quick_chat |
31 from sat_frontends.tools import jid | 32 from sat_frontends.tools import jid |
32 from cagou.core import cagou_widget | 33 from cagou.core import cagou_widget |
45 | 46 |
46 class MessAvatar(Image): | 47 class MessAvatar(Image): |
47 pass | 48 pass |
48 | 49 |
49 | 50 |
50 class MessageWidget(BoxLayout): | 51 class MessageWidget(GridLayout): |
51 mess_data = properties.ObjectProperty() | 52 mess_data = properties.ObjectProperty() |
52 mess_label = properties.ObjectProperty() | 53 mess_label = properties.ObjectProperty() |
53 mess_box = properties.ObjectProperty() | 54 mess_padding = (dp(5), dp(5)) |
54 | |
55 def __init__(self, **kwargs): | |
56 BoxLayout.__init__(self, orientation='vertical', **kwargs) | |
57 avatar = MessAvatar(source=self.mess_data.avatar) | |
58 if self.mess_data.own_mess: | |
59 self.mess_box.add_widget(avatar, len(self.mess_box.children)) | |
60 else: | |
61 self.mess_box.add_widget(avatar) | |
62 | 55 |
63 @property | 56 @property |
64 def chat(self): | 57 def chat(self): |
65 """return parent Chat instance""" | 58 """return parent Chat instance""" |
66 return self.mess_data.parent | 59 return self.mess_data.parent |
68 @property | 61 @property |
69 def message(self): | 62 def message(self): |
70 """Return currently displayed message""" | 63 """Return currently displayed message""" |
71 return self.mess_data.main_message | 64 return self.mess_data.main_message |
72 | 65 |
73 def sizeAdjust(self): | 66 def widthAdjust(self): |
74 """this widget grows up with its children""" | 67 """this widget grows up with its children""" |
68 parent = self.mess_label.parent | |
69 padding_x = self.mess_padding[0] | |
75 text_width, text_height = self.mess_label.texture_size | 70 text_width, text_height = self.mess_label.texture_size |
76 other_width = sum([c.width for c in self.mess_box.children if c != self.mess_label]) | 71 if text_width > parent.width: |
77 if text_width + other_width > self.parent.width: | 72 self.mess_label.text_size = (parent.width - padding_x, None) |
78 self.mess_label.text_size = (self.parent.width - other_width - 10, None) | |
79 self.text_max = text_width | 73 self.text_max = text_width |
80 elif self.mess_label.text_size[0] is not None and text_width + other_width < self.parent.width - 10: | 74 elif self.mess_label.text_size[0] is not None and text_width < parent.width - padding_x: |
81 if text_width > self.text_max: | 75 if text_width < self.text_max: |
82 self.mess_label.text_size = (None, None) | 76 self.mess_label.text_size = (None, None) |
83 else: | 77 else: |
84 self.mess_label.text_size = (self.parent.width - other_width - 10, None) | 78 self.mess_label.text_size = (parent.width - padding_x, None) |
85 | 79 |
86 | 80 |
87 class MessageInputWidget(TextInput): | 81 class MessageInputWidget(TextInput): |
88 | 82 |
89 def _key_down(self, key, repeat=False): | 83 def _key_down(self, key, repeat=False): |
92 self.dispatch('on_text_validate') | 86 self.dispatch('on_text_validate') |
93 else: | 87 else: |
94 super(MessageInputWidget, self)._key_down(key, repeat) | 88 super(MessageInputWidget, self)._key_down(key, repeat) |
95 | 89 |
96 | 90 |
97 class MessagesWidget(BoxLayout): | 91 class MessagesWidget(GridLayout): |
98 _spacing = properties.NumericProperty(10) | 92 pass |
99 _padding = properties.NumericProperty(5) | |
100 | |
101 def __init__(self, **kwargs): | |
102 kwargs['orientation'] = 'vertical' | |
103 kwargs['size_hint'] = (1, None) | |
104 super(MessagesWidget, self).__init__(**kwargs) | |
105 | |
106 def sizeAdjust(self): | |
107 self.height = sum([(c.height+self._padding*2) for c in self.children]) + self._spacing | |
108 | 93 |
109 | 94 |
110 class Chat(quick_chat.QuickChat, cagou_widget.CagouWidget): | 95 class Chat(quick_chat.QuickChat, cagou_widget.CagouWidget): |
111 | 96 |
112 def __init__(self, host, target, type_=C.CHAT_ONE2ONE, occupants=None, subject=None, profiles=None): | 97 def __init__(self, host, target, type_=C.CHAT_ONE2ONE, occupants=None, subject=None, profiles=None): |