diff cagou/core/common.py @ 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 3c9ba4a694ef
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):