Mercurial > libervia-desktop-kivy
changeset 12:30f6586f904b
widget selector:
this widget will be the default one and display the different activities a user can do (chat, blog, file sharing, games, etc).
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 08 Jul 2016 20:18:36 +0200 |
parents | 49d30fc15884 |
children | 12a189fbb9ba |
files | src/cagou.kv src/cagou.py src/widget_selector.kv src/widget_selector.py |
diffstat | 4 files changed, 97 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/cagou.kv Fri Jul 08 20:17:52 2016 +0200 +++ b/src/cagou.kv Fri Jul 08 20:18:36 2016 +0200 @@ -17,3 +17,4 @@ #:include profile_manager.kv #:include contact_list.kv #:include cagou_widget.kv +#:include widget_selector.kv
--- a/src/cagou.py Fri Jul 08 20:17:52 2016 +0200 +++ b/src/cagou.py Fri Jul 08 20:18:36 2016 +0200 @@ -33,8 +33,8 @@ from kivy.app import App import xmlui from profile_manager import ProfileManager -from contact_list import ContactList from kivy.uix.boxlayout import BoxLayout +from widget_selector import WidgetSelector from cagou_widget import CagouWidget import os.path @@ -73,8 +73,8 @@ self.app.run() def plugging_profiles(self): - contact_list = self.widgets.getOrCreateWidget(ContactList, None, on_new_widget=None) - self.app.root.change_widgets([contact_list]) + widget_selector = WidgetSelector(self) + self.app.root.change_widgets([widget_selector]) def setPresenceStatus(self, show='', status=None, profile=C.PROF_KEY_NONE): log.info(u"Profile presence status set to {show}/{status}".format(show=show, status=status))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/widget_selector.kv Fri Jul 08 20:18:36 2016 +0200 @@ -0,0 +1,24 @@ +# Cagou: desktop/mobile frontend for Salut à Toi XMPP client +# Copyright (C) 2016 Jérôme Poisson (goffi@goffi.org) + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +<WidgetSelItem>: + spacing: 20 + Widget: + Label: + text: root.widget_type + bold: True + size_hint: (None, None) + Widget:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/widget_selector.py Fri Jul 08 20:18:36 2016 +0200 @@ -0,0 +1,69 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# Cagou: desktop/mobile frontend for Salut à Toi XMPP client +# Copyright (C) 2016 Jérôme Poisson (goffi@goffi.org) + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + + +from sat.core import log as logging +log = logging.getLogger(__name__) +from kivy.uix.boxlayout import BoxLayout +from kivy.uix.listview import ListView +from kivy.adapters.listadapter import ListAdapter +from kivy import properties +from contact_list import ContactList +from kivy.uix.behaviors import ButtonBehavior +from cagou_widget import CagouWidget + + +class WidgetSelItem(ButtonBehavior, BoxLayout): + widget_type = properties.StringProperty('') + + def __init__(self, **kwargs): + super(WidgetSelItem, self).__init__(**kwargs) + self.host = kwargs['host'] + self.callback = kwargs['callback'] + + def select(self, *args): + log.debug(u"widget selection: {}".format(self.widget_type)) + self.host.switchWidget(self, self.callback()) + + def deselect(self, *args): + pass + + +class WidgetSelector(CagouWidget): + + def __init__(self, host): + super(WidgetSelector, self).__init__() + self.host = host + self.widget_factory = { + 'contacts': lambda: host.widgets.getOrCreateWidget(ContactList, None, on_new_widget=None), + } + self.adapter = ListAdapter(data=self.widget_factory, + cls=WidgetSelItem, + args_converter=self.dataConverter, + selection_mode='single', + allow_empty_selection=True, + ) + self.add_widget(ListView(adapter=self.adapter)) + + def dataConverter(self, idx, widget_type): + return { + "host": self.host, + "widget_type": widget_type, + "callback": self.widget_factory[widget_type] + }