changeset 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 03d74435c01c
children 4233be74572a
files cagou/core/common.py cagou/kv/common.kv
diffstat 2 files changed, 28 insertions(+), 11 deletions(-) [+]
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):
--- a/cagou/kv/common.kv	Sat Jan 26 20:24:48 2019 +0100
+++ b/cagou/kv/common.kv	Sat Jan 26 20:24:48 2019 +0100
@@ -18,6 +18,7 @@
 <JidItem>:
     size_hint: 1, None
     height: dp(70)
+    avatar: avatar
     canvas.before:
         Color:
             rgba: self.bg_color
@@ -25,7 +26,7 @@
             pos: self.pos
             size: self.size
     Image:
-        source: root.getImage(self)
+        id: avatar
         size_hint: None, None
         size: dp(64), dp(64)
     Label: