# HG changeset patch # User Goffi # Date 1523023988 -7200 # Node ID 1cca97e27a691862b7438a160d5157e0ac058f9c # Parent c3aa71daceb8625d59686c31a91a0752077d085f core (common): new Symbol widget: it uses font icon to display a symbol by name (should move to direct svg rendering once it's stable in Kivy). bg_color property allows to change background color. margin property allows to display a margin around the symbol diff -r c3aa71daceb8 -r 1cca97e27a69 cagou/core/common.py --- a/cagou/core/common.py Fri Apr 06 16:13:08 2018 +0200 +++ b/cagou/core/common.py Fri Apr 06 16:13:08 2018 +0200 @@ -19,10 +19,19 @@ """common widgets, which can be reused everywhere""" +from sat.core.i18n import _ from kivy.uix.image import Image +from kivy.uix.label import Label from kivy.uix.behaviors import ButtonBehavior from kivy.uix.boxlayout import BoxLayout +from kivy import properties from cagou import G +import json +from sat.core import log as logging + +log = logging.getLogger(__name__) + +UNKNOWN_SYMBOL = u'Unknown symbol name' class IconButton(ButtonBehavior, Image): @@ -44,3 +53,25 @@ return "" else: return host.getAvatar(self.jid, profile=self.profile) or host.getDefaultAvatar(self.jid) + + +class Symbol(Label): + symbol_map = None + symbol = properties.StringProperty() + margin = properties.NumericProperty(0) + + def __init__(self, **kwargs): + if self.symbol_map is None: + with open(G.host.app.expand('{media}/fonts/fontello/config.json')) as f: + fontello_conf = json.load(f) + Symbol.symbol_map = {g['css']:g['code'] for g in fontello_conf['glyphs']} + + super(Symbol, self).__init__(**kwargs) + + def on_symbol(self, instance, symbol): + try: + code = self.symbol_map[symbol] + except KeyError: + log.warning(_(u"Invalid symbol {symbol}").format(symbol=symbol)) + else: + self.text = unichr(code) diff -r c3aa71daceb8 -r 1cca97e27a69 cagou/core/image.py --- a/cagou/core/image.py Fri Apr 06 16:13:08 2018 +0200 +++ b/cagou/core/image.py Fri Apr 06 16:13:08 2018 +0200 @@ -81,4 +81,3 @@ self.source = self.source[7:] else: super(AsyncImage, self)._load_source(*args) - diff -r c3aa71daceb8 -r 1cca97e27a69 cagou/kv/common.kv --- a/cagou/kv/common.kv Fri Apr 06 16:13:08 2018 +0200 +++ b/cagou/kv/common.kv Fri Apr 06 16:13:08 2018 +0200 @@ -37,3 +37,17 @@ padding_x: dp(20) +: + font_name: app.expand('{media}/fonts/fontello/font/fontello.ttf') + text_size: self.size + font_size: self.width - self.margin + margin: dp(5) + halign: 'center' + valign: 'middle' + bg_color: 1, 1, 1, 1 + canvas.before: + Color: + rgba: self.bg_color + Rectangle: + pos: self.pos + size: self.size