# HG changeset patch # User Goffi # Date 1587308805 -7200 # Node ID 72290ebfaa8bcd6208918024a6912e32a4507e28 # Parent 1dd6db69406a29a3a8c6bd3646e0ee4983387046 core (common), contact_list: new `data` property: when this property is set, the `source` is automatically set from avatar data. diff -r 1dd6db69406a -r 72290ebfaa8b cagou/core/common.py --- 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): diff -r 1dd6db69406a -r 72290ebfaa8b cagou/kv/common.kv --- 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 diff -r 1dd6db69406a -r 72290ebfaa8b cagou/plugins/plugin_wid_contact_list.kv --- 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