view frontends/primitivus/chat.py @ 123:34766e0cf970

wix: chat: date is now printed in grey
author Goffi <goffi@goffi.org>
date Thu, 08 Jul 2010 18:29:44 +0800
parents 1ca5f254ce41
children 961e0898271f
line wrap: on
line source

#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
Primitivus: a SAT frontend
Copyright (C) 2009, 2010  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 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 General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""

import urwid
from quick_frontend.quick_contact_list import QuickContactList
from quick_frontend.quick_chat import QuickChat
from custom_widgets import Password,List,InputDialog,ConfirmDialog,Alert,SelectableText,LabelLine,SurroundedText


class Chat(urwid.WidgetWrap, QuickChat):

    def __init__(self, target, host, type='one2one'):
        QuickChat.__init__(self, target, host, type)
        self.content = urwid.SimpleListWalker([])
        self.text_list = urwid.ListBox(self.content)
        main_widget = LabelLine(
                      urwid.Frame(self.text_list), SurroundedText(str(target))
                      )
        urwid.WidgetWrap.__init__(self, main_widget)
        self.setType(type)
    
    def setType(self, type):
        QuickChat.setType(self, type)
        if type == 'one2one':
            self.historyPrint(profile=self.host.profile)
    
    def setSubject(self, subject):
        """Set title for a group chat"""
        QuickChat.setSubject(self, subject)
        self._w.base_widget.header = urwid.AttrMap(urwid.Text(unicode(subject),align='center'),'title')


    def printMessage(self, from_jid, msg, profile, timestamp=""):
        self.content.append(SelectableText("[%s] " % from_jid + msg))
        self.text_list.set_focus(len(self.content)-1)
        self.host.redraw()