Mercurial > libervia-desktop-kivy
changeset 179:7177fe2d9725
common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 01 May 2018 20:48:48 +0200 |
parents | 11ff8cd93659 |
children | 0ddd2b20cc6b |
files | cagou/core/cagou_widget.py cagou/core/common.py cagou/kv/cagou_widget.kv cagou/plugins/plugin_wid_widget_selector.kv |
diffstat | 4 files changed, 25 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/cagou/core/cagou_widget.py Tue May 01 18:28:22 2018 +0200 +++ b/cagou/core/cagou_widget.py Tue May 01 20:48:48 2018 +0200 @@ -20,12 +20,12 @@ from sat.core import log as logging log = logging.getLogger(__name__) -from kivy.uix.image import Image from kivy.uix.behaviors import ButtonBehavior from kivy.uix.boxlayout import BoxLayout from kivy.uix.dropdown import DropDown from kivy import properties from cagou import G +from cagou.core.common import ActionIcon class HeaderWidgetChoice(ButtonBehavior, BoxLayout): @@ -36,7 +36,7 @@ self.bind(on_release=lambda btn: cagou_widget.switchWidget(plugin_info)) -class HeaderWidgetCurrent(ButtonBehavior, Image): +class HeaderWidgetCurrent(ButtonBehavior, ActionIcon): pass
--- a/cagou/core/common.py Tue May 01 18:28:22 2018 +0200 +++ b/cagou/core/common.py Tue May 01 20:48:48 2018 +0200 @@ -83,3 +83,19 @@ class ActionSymbol(Symbol): pass + + +class ActionIcon(BoxLayout): + plugin_info = properties.DictProperty() + + def on_plugin_info(self, instance, plugin_info): + self.clear_widgets() + try: + symbol = plugin_info['icon_symbol'] + except KeyError: + icon_src = plugin_info['icon_medium'] + icon_wid = Image(source=icon_src, allow_stretch=True) + self.add_widget(icon_wid) + else: + icon_wid = ActionSymbol(symbol=symbol) + self.add_widget(icon_wid)
--- a/cagou/kv/cagou_widget.kv Tue May 01 18:28:22 2018 +0200 +++ b/cagou/kv/cagou_widget.kv Tue May 01 20:48:48 2018 +0200 @@ -27,10 +27,9 @@ height: dp(44) spacing: dp(20) padding: dp(5), dp(3), dp(10), dp(3) - Image: + ActionIcon: + plugin_info: root.plugin_info size_hint: None, 1 - source: root.plugin_info['icon_medium'] - allow_stretch: True width: self.height Label: size_hint: None, 1 @@ -60,11 +59,10 @@ height: dp(32) spacing: dp(3) HeaderWidgetCurrent: - on_release: root.selector.open(self) - source: root.plugin_info['icon_small'] + plugin_info: root.plugin_info size_hint: None, 1 - allow_stretch: True width: self.height + on_release: root.selector.open(self) TextInput: id: header_input background_normal: app.expand('{media}/misc/borders/border_hollow_light.png')
--- a/cagou/plugins/plugin_wid_widget_selector.kv Tue May 01 18:28:22 2018 +0200 +++ b/cagou/plugins/plugin_wid_widget_selector.kv Tue May 01 20:48:48 2018 +0200 @@ -23,11 +23,10 @@ id: item size_hint: None, 1 spacing: dp(10) - Image: - source: root.plugin_info["icon_medium"] - allow_stretch: True - keep_ratio: True + ActionIcon: + plugin_info: root.plugin_info size_hint: None, 1 + width: self.height Label: text: root.plugin_info["name"] bold: True