Mercurial > libervia-desktop-kivy
comparison src/cagou/plugins/plugin_wid_chat.py @ 44:7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 29 Aug 2016 01:23:49 +0200 |
parents | 286865bc013a |
children | b0595a33465d |
comparison
equal
deleted
inserted
replaced
43:12fdc7d1feb1 | 44:7819e9efa250 |
---|---|
28 from kivy import properties | 28 from kivy import properties |
29 from sat_frontends.quick_frontend import quick_widgets | 29 from sat_frontends.quick_frontend import quick_widgets |
30 from sat_frontends.quick_frontend import quick_chat | 30 from sat_frontends.quick_frontend import quick_chat |
31 from sat_frontends.tools import jid | 31 from sat_frontends.tools import jid |
32 from cagou.core import cagou_widget | 32 from cagou.core import cagou_widget |
33 from cagou.core.image import Image | |
33 from cagou import G | 34 from cagou import G |
34 | 35 |
35 | 36 |
36 PLUGIN_INFO = { | 37 PLUGIN_INFO = { |
37 "name": _(u"chat"), | 38 "name": _(u"chat"), |
40 "icon_small": u"{media}/icons/muchoslava/png/chat_rouge_32.png", | 41 "icon_small": u"{media}/icons/muchoslava/png/chat_rouge_32.png", |
41 "icon_medium": u"{media}/icons/muchoslava/png/chat_rouge_44.png" | 42 "icon_medium": u"{media}/icons/muchoslava/png/chat_rouge_44.png" |
42 } | 43 } |
43 | 44 |
44 | 45 |
46 class MessAvatar(Image): | |
47 pass | |
48 | |
49 | |
45 class MessageWidget(BoxLayout): | 50 class MessageWidget(BoxLayout): |
46 mess_data = properties.ObjectProperty() | 51 mess_data = properties.ObjectProperty() |
47 mess_label = properties.ObjectProperty(None) | 52 mess_label = properties.ObjectProperty() |
53 mess_box = properties.ObjectProperty() | |
48 | 54 |
49 def __init__(self, **kwargs): | 55 def __init__(self, **kwargs): |
50 BoxLayout.__init__(self, orientation='vertical', **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 | |
63 @property | |
64 def chat(self): | |
65 """return parent Chat instance""" | |
66 return self.mess_data.parent | |
51 | 67 |
52 @property | 68 @property |
53 def message(self): | 69 def message(self): |
54 """Return currently displayed message""" | 70 """Return currently displayed message""" |
55 return self.mess_data.main_message | 71 return self.mess_data.main_message |
56 | 72 |
57 def sizeAdjust(self): | 73 def sizeAdjust(self): |
58 """this widget grows up with its children""" | 74 """this widget grows up with its children""" |
59 text_width, text_height = self.mess_label.texture_size | 75 text_width, text_height = self.mess_label.texture_size |
60 if text_width > self.parent.width: | 76 other_width = sum([c.width for c in self.mess_box.children if c != self.mess_label]) |
61 self.mess_label.text_size = (self.parent.width - 10, None) | 77 if text_width + other_width > self.parent.width: |
78 self.mess_label.text_size = (self.parent.width - other_width - 10, None) | |
62 self.text_max = text_width | 79 self.text_max = text_width |
63 elif self.mess_label.text_size[0] is not None and text_width < self.parent.width - 10: | 80 elif self.mess_label.text_size[0] is not None and text_width + other_width < self.parent.width - 10: |
64 if text_width > self.text_max: | 81 if text_width > self.text_max: |
65 self.mess_label.text_size = (None, None) | 82 self.mess_label.text_size = (None, None) |
66 else: | 83 else: |
67 self.mess_label.text_size = (self.parent.width - 10, None) | 84 self.mess_label.text_size = (self.parent.width - other_width - 10, None) |
68 | 85 |
69 | 86 |
70 class MessageInputWidget(TextInput): | 87 class MessageInputWidget(TextInput): |
71 | 88 |
72 def _key_down(self, key, repeat=False): | 89 def _key_down(self, key, repeat=False): |