diff cagou/core/common.py @ 256:ba7b8cb7ddcd

common: don't use anymore positional argument in JidItem
author Goffi <goffi@goffi.org>
date Sat, 26 Jan 2019 20:24:48 +0100
parents cf61a011f731
children 0ef216091f2b
line wrap: on
line diff
--- a/cagou/core/common.py	Sat Jan 26 20:24:48 2019 +0100
+++ b/cagou/core/common.py	Sat Jan 26 20:24:48 2019 +0100
@@ -43,21 +43,37 @@
 class JidItem(BoxLayout):
     bg_color = properties.ListProperty([0.2, 0.2, 0.2, 1])
     color = properties.ListProperty([1, 1, 1, 1])
+    jid = properties.StringProperty()
+    profile = properties.StringProperty()
+    nick = properties.StringProperty()
+    avatar = properties.ObjectProperty()
 
-    def __init__(self, jid, profile, **kwargs):
-        self.jid = jid
-        self.profile = profile
-        self.nick = kwargs.get('nick')
-        super(JidItem, self).__init__(**kwargs)
+    def on_avatar(self, wid, jid_):
+        if self.jid and self.profile:
+            self.getImage()
 
-    def getImage(self, wid):
+    def on_jid(self, wid, jid_):
+        if self.profile and self.avatar:
+            self.getImage()
+
+    def on_profile(self, wid, profile):
+        if self.jid and self.avatar:
+            self.getImage()
+
+    def getImage(self):
         host = G.host
         if host.contact_lists[self.profile].isRoom(self.jid.bare):
-            wid.opacity = 0
-            return ""
+            self.avatar.opacity = 0
+            self.avatar.source = ""
         else:
-            return (host.getAvatar(self.jid, profile=self.profile)
-                or host.getDefaultAvatar(self.jid))
+            try:
+                self.avatar.source = (
+                    host.getAvatar(self.jid, profile=self.profile)
+                    or host.getDefaultAvatar(self.jid)
+                )
+            except Exception as e:
+                __import__('pudb').set_trace()
+                print(e)
 
 
 class JidButton(ButtonBehavior, JidItem):