# HG changeset patch # User Goffi # Date 1468001916 -7200 # Node ID 30f6586f904b02e67715c4df502fee84b4f5ce18 # Parent 49d30fc158843da5325349f5ba09caff83208cc9 widget selector: this widget will be the default one and display the different activities a user can do (chat, blog, file sharing, games, etc). diff -r 49d30fc15884 -r 30f6586f904b src/cagou.kv --- 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 diff -r 49d30fc15884 -r 30f6586f904b src/cagou.py --- 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)) diff -r 49d30fc15884 -r 30f6586f904b src/widget_selector.kv --- /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 . + +: + spacing: 20 + Widget: + Label: + text: root.widget_type + bold: True + size_hint: (None, None) + Widget: diff -r 49d30fc15884 -r 30f6586f904b src/widget_selector.py --- /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 . + + +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] + }