view src/cagou.py @ 10:8b2836b5b6c7

added CagouWidget: CagouWidget is the base for all selectable widgets, it currently displays basic drop/down menu which will be used to switch widget (in a similar way as in Blender), and a text input which will be the generic search field (behaviour may vary between widgets).
author Goffi <goffi@goffi.org>
date Fri, 08 Jul 2016 20:17:09 +0200
parents 7b0a53d2afd3
children 49d30fc15884
line wrap: on
line source

#!/usr//bin/env python2
# -*- 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/>.


import logging_setter
logging_setter.set_logging()
from constants import Const as C
from sat.core import log as logging
log = logging.getLogger(__name__)
from sat_frontends.quick_frontend.quick_app import QuickApp
from sat_frontends.bridge.DBus import DBusBridgeFrontend
# from sat_frontends.quick_frontend import quick_utils
import kivy
kivy.require('1.9.1')
import kivy.support
kivy.support.install_gobject_iteration()
from kivy.app import App
import xmlui
from profile_manager import ProfileManager
from contact_list import ContactList
from kivy.uix.boxlayout import BoxLayout
import os.path


class CagouRootWidget(BoxLayout):

    def __init__(self, widgets):
        super(CagouRootWidget, self).__init__(orientation=("vertical"))
        for wid in widgets:
            self.add_widget(wid)

    def change_widgets(self, widgets):
        self.clear_widgets()
        for wid in widgets:
            self.add_widget(wid)


class CagouApp(App):
    """Kivy App for Cagou"""

    def build(self):
        return CagouRootWidget([ProfileManager(self.host)])


class Cagou(QuickApp):
    MB_HANDLE = False

    def __init__(self):
        super(Cagou, self).__init__(create_bridge=DBusBridgeFrontend, xmlui=xmlui)
        self.app = CagouApp()
        self.app.host = self
        media_dir = self.app.media_dir = self.bridge.getConfig("", "media_dir")
        self.app.default_avatar = os.path.join(media_dir, "misc/default_avatar.png")

    def run(self):
        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])

    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))


if __name__ == '__main__':
    Cagou().run()