Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
189:757518d05833 | 190:31632472e857 |
---|---|
30 | 30 |
31 | 31 |
32 class ChatText(urwid.FlowWidget): | 32 class ChatText(urwid.FlowWidget): |
33 """Manage the printing of chat message""" | 33 """Manage the printing of chat message""" |
34 | 34 |
35 def __init__(self, parent, timestamp, my_jid, from_jid, message, align='left'): | 35 def __init__(self, parent, timestamp, nick, my_mess, message, align='left'): |
36 self.parent = parent | 36 self.parent = parent |
37 self.timestamp = time.localtime(timestamp) | 37 self.timestamp = time.localtime(timestamp) |
38 self.my_jid = my_jid | 38 self.nick = nick |
39 self.from_jid = from_jid | 39 self.my_mess = my_mess |
40 self.message = unicode(message) | 40 self.message = unicode(message) |
41 self.align = align | 41 self.align = align |
42 | 42 |
43 def selectable(self): | 43 def selectable(self): |
44 return True | 44 return True |
58 def get_cursor_coords(self, size): | 58 def get_cursor_coords(self, size): |
59 #(maxcol,) = size | 59 #(maxcol,) = size |
60 return 0, 0 | 60 return 0, 0 |
61 | 61 |
62 def display_widget(self, size, focus): | 62 def display_widget(self, size, focus): |
63 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 | |
64 render_txt = [] | 63 render_txt = [] |
65 if self.parent.show_timestamp: | 64 if self.parent.show_timestamp: |
66 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 | 65 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 |
67 render_txt.append(('date',"[%s]" % time.strftime(time_format, self.timestamp))) | 66 render_txt.append(('date',"[%s]" % time.strftime(time_format, self.timestamp))) |
68 if self.parent.show_short_nick: | 67 if self.parent.show_short_nick: |
69 render_txt.append(('my_nick' if my_mess else 'other_nick',"**" if my_mess else "*")) | 68 render_txt.append(('my_nick' if self.my_mess else 'other_nick',"**" if self.my_mess else "*")) |
70 else: | 69 else: |
71 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) | 70 render_txt.append(('my_nick' if self.my_mess else 'other_nick',"[%s] " % self.nick)) |
72 render_txt.append(('my_nick' if my_mess else 'other_nick',"[%s] " % nick)) | |
73 render_txt.append(self.message) | 71 render_txt.append(self.message) |
74 return urwid.Text(render_txt, align=self.align) | 72 return urwid.Text(render_txt, align=self.align) |
75 | 73 |
76 class Chat(urwid.WidgetWrap, QuickChat): | 74 class Chat(urwid.WidgetWrap, QuickChat): |
77 | 75 |
225 self.present_wid.deleteValue(nick) | 223 self.present_wid.deleteValue(nick) |
226 self.host.redraw() | 224 self.host.redraw() |
227 | 225 |
228 def printMessage(self, from_jid, msg, profile, timestamp=""): | 226 def printMessage(self, from_jid, msg, profile, timestamp=""): |
229 assert isinstance(from_jid, JID) | 227 assert isinstance(from_jid, JID) |
228 try: | |
229 jid,nick,mymess = QuickChat.printMessage(self, from_jid, msg, profile, timestamp) | |
230 except TypeError: | |
231 return | |
230 my_jid = self.host.profiles[profile]['whoami'] | 232 my_jid = self.host.profiles[profile]['whoami'] |
231 self.content.append(ChatText(self, timestamp or None, my_jid, from_jid, msg)) | 233 self.content.append(ChatText(self, timestamp or None, nick, mymess, msg)) |
234 self.text_list.set_focus(len(self.content)-1) | |
235 self.host.redraw() | |
236 | |
237 def printInfo(self, msg, type='normal'): | |
238 """Print general info | |
239 @param msg: message to print | |
240 @type: one of: | |
241 normal: general info like "toto has joined the room" | |
242 me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist" | |
243 """ | |
244 self.content.append(custom_widgets.ClickableText(msg)) | |
232 self.text_list.set_focus(len(self.content)-1) | 245 self.text_list.set_focus(len(self.content)-1) |
233 self.host.redraw() | 246 self.host.redraw() |
234 | 247 |
235 def startGame(self, game_type, referee, players): | 248 def startGame(self, game_type, referee, players): |
236 """Configure the chat window to start a game""" | 249 """Configure the chat window to start a game""" |