diff 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
line wrap: on
line diff
--- a/src/cagou/plugins/plugin_wid_chat.py	Sun Aug 28 16:50:56 2016 +0200
+++ b/src/cagou/plugins/plugin_wid_chat.py	Mon Aug 29 01:23:49 2016 +0200
@@ -30,6 +30,7 @@
 from sat_frontends.quick_frontend import quick_chat
 from sat_frontends.tools import jid
 from cagou.core import cagou_widget
+from cagou.core.image import Image
 from cagou import G
 
 
@@ -42,12 +43,27 @@
 }
 
 
+class MessAvatar(Image):
+    pass
+
+
 class MessageWidget(BoxLayout):
     mess_data = properties.ObjectProperty()
-    mess_label = properties.ObjectProperty(None)
+    mess_label = properties.ObjectProperty()
+    mess_box = properties.ObjectProperty()
 
     def __init__(self, **kwargs):
         BoxLayout.__init__(self, orientation='vertical', **kwargs)
+        avatar = MessAvatar(source=self.mess_data.avatar)
+        if self.mess_data.own_mess:
+            self.mess_box.add_widget(avatar, len(self.mess_box.children))
+        else:
+            self.mess_box.add_widget(avatar)
+
+    @property
+    def chat(self):
+        """return parent Chat instance"""
+        return self.mess_data.parent
 
     @property
     def message(self):
@@ -57,14 +73,15 @@
     def sizeAdjust(self):
         """this widget grows up with its children"""
         text_width, text_height = self.mess_label.texture_size
-        if text_width > self.parent.width:
-            self.mess_label.text_size = (self.parent.width - 10, None)
+        other_width = sum([c.width for c in self.mess_box.children if c != self.mess_label])
+        if text_width + other_width > self.parent.width:
+            self.mess_label.text_size = (self.parent.width - other_width - 10, None)
             self.text_max = text_width
-        elif self.mess_label.text_size[0] is not None and text_width < self.parent.width - 10:
+        elif self.mess_label.text_size[0] is not None and text_width + other_width < self.parent.width - 10:
             if text_width > self.text_max:
                 self.mess_label.text_size = (None, None)
             else:
-                self.mess_label.text_size = (self.parent.width - 10, None)
+                self.mess_label.text_size = (self.parent.width - other_width - 10, None)
 
 
 class MessageInputWidget(TextInput):