Mercurial > libervia-desktop-kivy
changeset 25:d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 10 Aug 2016 01:24:37 +0200 |
parents | bc15b55a4114 |
children | 3efca1b10b2f |
files | src/cagou/core/cagou_main.py src/cagou/core/cagou_widget.py src/cagou/core/constants.py src/cagou/kv/cagou_widget.kv src/cagou/plugins/plugin_wid_chat.py src/cagou/plugins/plugin_wid_contact_list.py src/cagou/plugins/plugin_wid_widget_selector.kv src/cagou/plugins/plugin_wid_widget_selector.py |
diffstat | 8 files changed, 68 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/cagou/core/cagou_main.py Tue Aug 09 22:06:00 2016 +0200 +++ b/src/cagou/core/cagou_main.py Wed Aug 10 01:24:37 2016 +0200 @@ -71,8 +71,8 @@ super(Cagou, self).__init__(create_bridge=DBusBridgeFrontend, xmlui=xmlui) self._import_kv() self.app = CagouApp() - media_dir = self.app.media_dir = self.bridge.getConfig("", "media_dir") - self.app.default_avatar = os.path.join(media_dir, "misc/default_avatar.png") + self.media_dir = self.app.media_dir = self.bridge.getConfig("", "media_dir") + self.app.default_avatar = os.path.join(self.media_dir, "misc/default_avatar.png") self._plg_wids = [] # widget plugins self._import_plugins() @@ -135,6 +135,19 @@ if 'factory' not in plugin_info: plugin_info['factory'] = self._defaultFactory + # icons + for size in ('small', 'medium'): + key = u'icon_{}'.format(size) + try: + path = plugin_info[key] + except KeyError: + path = C.DEFAULT_WIDGET_ICON.format(media=self.media_dir) + else: + path = path.format(media=self.media_dir) + if not os.path.isfile(path): + path = C.DEFAULT_WIDGET_ICON.format(media=self.media_dir) + plugin_info[key] = path + self._plg_wids.append(plugin_info) if not self._plg_wids: log.error(_(u"no widget plugin found"))
--- a/src/cagou/core/cagou_widget.py Tue Aug 09 22:06:00 2016 +0200 +++ b/src/cagou/core/cagou_widget.py Wed Aug 10 01:24:37 2016 +0200 @@ -20,14 +20,23 @@ from sat.core import log as logging log = logging.getLogger(__name__) -from kivy.uix.button import Button +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 -class HeaderWidgetButton(Button): +class HeaderWidgetChoice(ButtonBehavior, BoxLayout): + def __init__(self, cagou_widget, plugin_info): + self.plugin_info = plugin_info + super(HeaderWidgetChoice, self).__init__() + self.bind(on_release=lambda btn, plugin_info=plugin_info: cagou_widget.switchWidget(plugin_info)) + + + +class HeaderWidgetCurrent(ButtonBehavior, Image): pass @@ -36,15 +45,18 @@ def __init__(self, cagou_widget): super(HeaderWidgetSelector, self).__init__() for plugin_info in G.host.getPluggedWidgets(except_cls=cagou_widget.__class__): - btn = HeaderWidgetButton(text=plugin_info["name"]) - btn.bind(on_release=lambda btn, plugin_info=plugin_info: cagou_widget.switchWidget(plugin_info)) - self.add_widget(btn) + choice = HeaderWidgetChoice(cagou_widget, plugin_info) + self.add_widget(choice) class CagouWidget(BoxLayout): header_input = properties.ObjectProperty(None) def __init__(self): + for p in G.host.getPluggedWidgets(): + if p['main'] == self.__class__: + self.plugin_info = p + break BoxLayout.__init__(self, orientation="vertical") self.selector = HeaderWidgetSelector(self)
--- a/src/cagou/core/constants.py Tue Aug 09 22:06:00 2016 +0200 +++ b/src/cagou/core/constants.py Wed Aug 10 01:24:37 2016 +0200 @@ -25,3 +25,5 @@ LOG_OPT_SECTION = APP_NAME.lower() CONFIG_SECTION = APP_NAME.lower() WID_SELECTOR = 'selector' + ICON_SIZES = ('small', 'medium') # small = 32, medium = 44 + DEFAULT_WIDGET_ICON = u'{media}/misc/black.png'
--- a/src/cagou/kv/cagou_widget.kv Tue Aug 09 22:06:00 2016 +0200 +++ b/src/cagou/kv/cagou_widget.kv Wed Aug 10 01:24:37 2016 +0200 @@ -15,9 +15,28 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. -<HeaderWidgetButton>: +<HeaderWidgetChoice>: + canvas.before: + Color: + rgba: 1, 1, 1, 1 + BorderImage: + pos: self.pos + size: self.size + source: 'atlas://data/images/defaulttheme/button' size_hint_y: None height: 44 + Image: + size_hint: None, 1 + source: root.plugin_info['icon_medium'] + allow_stretch: True + width: self.texture_size[0]*self.height/self.texture_size[1] + Label: + size_hint: 1, 1 + text: root.plugin_info['name'] + bold: True + text_size: self.size + halign: "center" + valign: "middle" <HeaderWidgetSelector>: size_hint: 0.3, 1 @@ -27,12 +46,13 @@ header_input: header_input BoxLayout: size_hint: 1, None - height: 30 - Button: - text: "wid_XXX" + height: 32 + HeaderWidgetCurrent: on_release: root.selector.open(self) + source: root.plugin_info['icon_small'] size_hint: None, 1 - width: 60 + allow_stretch: True + width: self.texture_size[0]*self.height/self.texture_size[1] TextInput: id: header_input multiline: False
--- a/src/cagou/plugins/plugin_wid_chat.py Tue Aug 09 22:06:00 2016 +0200 +++ b/src/cagou/plugins/plugin_wid_chat.py Wed Aug 10 01:24:37 2016 +0200 @@ -37,6 +37,8 @@ "name": _(u"chat"), "main": "Chat", "description": _(u"instant messaging with one person or a group"), + "icon_small": u"{media}/icons/muchoslava/png/chat_rouge_32.png", + "icon_medium": u"{media}/icons/muchoslava/png/chat_rouge_44.png" }
--- a/src/cagou/plugins/plugin_wid_contact_list.py Tue Aug 09 22:06:00 2016 +0200 +++ b/src/cagou/plugins/plugin_wid_contact_list.py Wed Aug 10 01:24:37 2016 +0200 @@ -36,6 +36,8 @@ "name": _(u"contacts"), "main": "ContactList", "description": _(u"list of contacts"), + "icon_small": u"{media}/icons/muchoslava/png/contact_list_rouge_32.png", + "icon_medium": u"{media}/icons/muchoslava/png/contact_list_rouge_44.png" }
--- a/src/cagou/plugins/plugin_wid_widget_selector.kv Tue Aug 09 22:06:00 2016 +0200 +++ b/src/cagou/plugins/plugin_wid_widget_selector.kv Wed Aug 10 01:24:37 2016 +0200 @@ -18,6 +18,9 @@ size_hint: (1, None) height: 50 Widget: + Image: + source: root.plugin_info["icon_medium"] + width: self.texture_size[0] Label: text: root.plugin_info["name"] bold: True
--- a/src/cagou/plugins/plugin_wid_widget_selector.py Tue Aug 09 22:06:00 2016 +0200 +++ b/src/cagou/plugins/plugin_wid_widget_selector.py Wed Aug 10 01:24:37 2016 +0200 @@ -36,6 +36,8 @@ "import_name": C.WID_SELECTOR, "main": "WidgetSelector", "description": _(u"show available widgets and allow to select one"), + "icon_small": u"{media}/icons/muchoslava/png/selector_rouge_32.png", + "icon_medium": u"{media}/icons/muchoslava/png/selector_rouge_44.png" }