comparison frontends/src/primitivus/chat.py @ 531:3bd8f84f920d

primitivus: fixed info messages timestamp
author Goffi <goffi@goffi.org>
date Sun, 28 Oct 2012 17:59:24 +0100
parents 3f8c2a0f20e5
children 3eeb6c865e4d
comparison
equal deleted inserted replaced
530:6c07127ad2ed 531:3bd8f84f920d
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, nick, my_mess, message, align='left'): 35 def __init__(self, parent, timestamp, nick, my_mess, message, align='left', is_info=False):
36 self.parent = parent 36 self.parent = parent
37 self.timestamp = time.localtime(timestamp) 37 self.timestamp = time.localtime(timestamp)
38 self.nick = nick 38 self.nick = nick
39 self.my_mess = my_mess 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 self.is_info = is_info
42 43
43 def selectable(self): 44 def selectable(self):
44 return True 45 return True
45 46
46 def keypress(self, size, key): 47 def keypress(self, size, key):
59 #(maxcol,) = size 60 #(maxcol,) = size
60 return 0, 0 61 return 0, 0
61 62
62 def display_widget(self, size, focus): 63 def display_widget(self, size, focus):
63 render_txt = [] 64 render_txt = []
64 if self.parent.show_timestamp: 65 if not self.is_info:
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 66 if self.parent.show_timestamp:
66 render_txt.append(('date',"[%s]" % time.strftime(time_format, self.timestamp).decode('utf-8'))) 67 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 if self.parent.show_short_nick: 68 render_txt.append(('date',"[%s]" % time.strftime(time_format, self.timestamp).decode('utf-8')))
68 render_txt.append(('my_nick' if self.my_mess else 'other_nick',"**" if self.my_mess else "*")) 69 if self.parent.show_short_nick:
69 else: 70 render_txt.append(('my_nick' if self.my_mess else 'other_nick',"**" if self.my_mess else "*"))
70 render_txt.append(('my_nick' if self.my_mess else 'other_nick',"[%s] " % self.nick)) 71 else:
72 render_txt.append(('my_nick' if self.my_mess else 'other_nick',"[%s] " % self.nick))
71 render_txt.append(self.message) 73 render_txt.append(self.message)
72 return urwid.Text(render_txt, align=self.align) 74 return urwid.Text(render_txt, align=self.align)
73 75
74 class Chat(urwid.WidgetWrap, QuickChat): 76 class Chat(urwid.WidgetWrap, QuickChat):
75 77
270 if self.type=="one2one": 272 if self.type=="one2one":
271 self.host.x_notify.sendNotification(_("Primitivus: %s is talking to you") % from_jid) 273 self.host.x_notify.sendNotification(_("Primitivus: %s is talking to you") % from_jid)
272 elif self.getUserNick().lower() in msg.lower(): 274 elif self.getUserNick().lower() in msg.lower():
273 self.host.x_notify.sendNotification(_("Primitivus: Somebody pinged your name in %s room") % self.target) 275 self.host.x_notify.sendNotification(_("Primitivus: Somebody pinged your name in %s room") % self.target)
274 276
275 def printInfo(self, msg, type='normal'): 277 def printInfo(self, msg, type='normal', timestamp=""):
276 """Print general info 278 """Print general info
277 @param msg: message to print 279 @param msg: message to print
278 @type: one of: 280 @type: one of:
279 normal: general info like "toto has joined the room" 281 normal: general info like "toto has joined the room"
280 me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist" 282 me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist"
281 """ 283 """
282 self.content.append(sat_widgets.ClickableText(msg)) 284 #FIXME: duplicated code, this must be refactored
285 _widget = ChatText(self, timestamp or None, None, False, msg, is_info=True)
286 self.content.append(_widget)
283 if self.text_list.get_focus()[1] == len(self.content)-2: 287 if self.text_list.get_focus()[1] == len(self.content)-2:
284 #we don't change focus if user is not at the bottom 288 #we don't change focus if user is not at the bottom
285 #as that mean that he is probably watching discussion history 289 #as that mean that he is probably watching discussion history
286 self.text_list.set_focus(len(self.content)-1) 290 self.text_list.set_focus(len(self.content)-1)
287 self.host.redraw() 291 self.host.redraw()