diff frontends/primitivus/chat.py @ 190:31632472e857

quick_frontend, wix, primitivus: informations in chat window - user joined/left information - messages starting with /me are managed
author Goffi <goffi@goffi.org>
date Wed, 18 Aug 2010 21:42:30 +0800
parents a566f654929e
children 754e12eaea14
line wrap: on
line diff
--- a/frontends/primitivus/chat.py	Wed Aug 18 20:50:45 2010 +0800
+++ b/frontends/primitivus/chat.py	Wed Aug 18 21:42:30 2010 +0800
@@ -32,11 +32,11 @@
 class ChatText(urwid.FlowWidget):
     """Manage the printing of chat message"""
     
-    def __init__(self, parent, timestamp, my_jid, from_jid, message, align='left'):
+    def __init__(self, parent, timestamp, nick, my_mess, message, align='left'):
         self.parent = parent
         self.timestamp = time.localtime(timestamp)
-        self.my_jid = my_jid
-        self.from_jid = from_jid
+        self.nick = nick
+        self.my_mess = my_mess
         self.message = unicode(message)
         self.align = align
 
@@ -60,16 +60,14 @@
         return 0, 0
 
     def display_widget(self, size, focus):
-        my_mess = (self.from_jid.resource == self.parent.nick) if self.parent.type == "group" else (self.from_jid.short == self.my_jid.short) #mymess = True if message comes from local user
         render_txt = []
         if self.parent.show_timestamp:
             time_format = "%c" if self.timestamp < self.parent.day_change else "%H:%M" #if the message was sent before today, we print the full date
             render_txt.append(('date',"[%s]" % time.strftime(time_format, self.timestamp)))
         if self.parent.show_short_nick:
-            render_txt.append(('my_nick' if my_mess else 'other_nick',"**" if my_mess else "*"))
+            render_txt.append(('my_nick' if self.my_mess else 'other_nick',"**" if self.my_mess else "*"))
         else:
-            nick = self.from_jid.resource if self.parent.type == "group" else (self.parent.host.CM.getAttr(self.from_jid,'nick') or self.parent.host.CM.getAttr(self.from_jid,'name') or self.from_jid.node)
-            render_txt.append(('my_nick' if my_mess else 'other_nick',"[%s] " % nick))
+            render_txt.append(('my_nick' if self.my_mess else 'other_nick',"[%s] " % self.nick))
         render_txt.append(self.message)
         return urwid.Text(render_txt, align=self.align)
 
@@ -227,8 +225,23 @@
 
     def printMessage(self, from_jid, msg, profile, timestamp=""):
         assert isinstance(from_jid, JID)
+        try:
+            jid,nick,mymess = QuickChat.printMessage(self, from_jid, msg, profile, timestamp)
+        except TypeError:
+            return
         my_jid = self.host.profiles[profile]['whoami']
-        self.content.append(ChatText(self, timestamp or None, my_jid, from_jid, msg))
+        self.content.append(ChatText(self, timestamp or None, nick, mymess, msg))
+        self.text_list.set_focus(len(self.content)-1)
+        self.host.redraw()
+    
+    def printInfo(self, msg, type='normal'):
+        """Print general info
+        @param msg: message to print
+        @type: one of:
+            normal: general info like "toto has joined the room"
+            me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist"
+        """
+        self.content.append(custom_widgets.ClickableText(msg))
         self.text_list.set_focus(len(self.content)-1)
         self.host.redraw()