changeset 459:72290ebfaa8b

core (common), contact_list: new `data` property: when this property is set, the `source` is automatically set from avatar data.
author Goffi <goffi@goffi.org>
date Sun, 19 Apr 2020 17:06:45 +0200
parents 1dd6db69406a
children b5e8e470f7f7
files cagou/core/common.py cagou/kv/common.kv cagou/plugins/plugin_wid_contact_list.kv
diffstat 3 files changed, 14 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/cagou/core/common.py	Tue Apr 14 21:14:44 2020 +0200
+++ b/cagou/core/common.py	Sun Apr 19 17:06:45 2020 +0200
@@ -21,7 +21,6 @@
 import json
 from functools import partial, total_ordering
 from kivy.uix.widget import Widget
-from kivy.uix.image import Image, AsyncImage
 from kivy.uix.label import Label
 from kivy.uix.behaviors import ButtonBehavior
 from kivy.uix.behaviors import ToggleButtonBehavior
@@ -37,6 +36,7 @@
 from sat_frontends.quick_frontend import quick_chat
 from .constants import Const as C
 from .common_widgets import CategorySeparator
+from .image import Image, AsyncImage
 from cagou import G
 
 log = logging.getLogger(__name__)
@@ -49,7 +49,17 @@
 
 
 class Avatar(Image):
-    pass
+    data = properties.DictProperty(allownone=True)
+
+    def on_kv_post(self, __):
+        if not self.source:
+            self.source = G.host.getDefaultAvatar()
+
+    def on_data(self, __, data):
+        if data is None:
+            self.source = G.host.getDefaultAvatar()
+        else:
+            self.source = data['path']
 
 
 class NotifLabel(Label):
--- a/cagou/kv/common.kv	Tue Apr 14 21:14:44 2020 +0200
+++ b/cagou/kv/common.kv	Sun Apr 19 17:06:45 2020 +0200
@@ -46,7 +46,7 @@
         Avatar:
             id: avatar
             pos_hint: {'x': 0, 'y': 0}
-            source: root.data['avatar']['path'] if root.data.get('avatar') else app.default_avatar
+            data: root.data.get('avatar')
             allow_stretch: True
     BoxLayout:
         id: label_box
--- a/cagou/plugins/plugin_wid_contact_list.kv	Tue Apr 14 21:14:44 2020 +0200
+++ b/cagou/plugins/plugin_wid_contact_list.kv	Sun Apr 19 17:06:45 2020 +0200
@@ -48,7 +48,7 @@
         id: avatar
         size_hint: 1, None
         height: dp(60)
-        source: root.contact_item.data.get('avatar', app.default_avatar)
+        data: root.contact_item.data.get('avatar')
         allow_stretch: True
     Label:
         size_hint: 1, None