comparison frontends/wix/chat.py @ 122:29998cd0ed8d

wix: time is now printed in chat window - replaceUser is fixed
author Goffi <goffi@goffi.org>
date Thu, 08 Jul 2010 18:26:30 +0800
parents 1ca5f254ce41
children 34766e0cf970
comparison
equal deleted inserted replaced
121:03d8bcc67182 122:29998cd0ed8d
21 21
22 22
23 23
24 import wx 24 import wx
25 import os.path 25 import os.path
26 import time
26 import pdb 27 import pdb
27 from logging import debug, info, error, warning 28 from logging import debug, info, error, warning
28 from tools.jid import JID 29 from tools.jid import JID
29 from quick_frontend.quick_chat import QuickChat 30 from quick_frontend.quick_chat import QuickChat
30 from contact_list import ContactList 31 from contact_list import ContactList
66 #fonts 67 #fonts
67 self.font={} 68 self.font={}
68 self.font["points"] = self.chatWindow.GetFont().GetPointSize() 69 self.font["points"] = self.chatWindow.GetFont().GetPointSize()
69 self.font["family"] = self.chatWindow.GetFont().GetFamily() 70 self.font["family"] = self.chatWindow.GetFont().GetFamily()
70 71
72
73 #misc
74 self.day_change = time.strptime(time.strftime("%a %b %d 00:00:00 %Y")) #struct_time of day changing time
71 self.setType(self.type) 75 self.setType(self.type)
72
73 #misc
74 self.textBox.SetFocus() 76 self.textBox.SetFocus()
75 self.Hide() #We hide because of the show toggle 77 self.Hide() #We hide because of the show toggle
76 78
77 def __createPresents(self): 79 def __createPresents(self):
78 """Create a list of present people in a group chat""" 80 """Create a list of present people in a group chat"""
90 if type is 'group' and not self.splitter.IsSplit(): 92 if type is 'group' and not self.splitter.IsSplit():
91 self.__createPresents() 93 self.__createPresents()
92 self.subjectBox.Show() 94 self.subjectBox.Show()
93 self.__eraseMenus() 95 self.__eraseMenus()
94 self.__createMenus_group() 96 self.__createMenus_group()
95 self.historyPrint(profile=self.host.profile)
96 self.sizer.Layout() 97 self.sizer.Layout()
97 elif type is 'one2one' and self.splitter.IsSplit(): 98 elif type is 'one2one' and self.splitter.IsSplit():
98 self.splitter.Unsplit(self.present_panel) 99 self.splitter.Unsplit(self.present_panel)
99 del self.present_panel 100 del self.present_panel
100 self.GetMenuBar().Show() 101 self.GetMenuBar().Show()
131 QuickChat.setPresents(self, nicks) 132 QuickChat.setPresents(self, nicks)
132 for nick in nicks: 133 for nick in nicks:
133 self.present_panel.presents.replace(nick) 134 self.present_panel.presents.replace(nick)
134 self.occupants.add(nick) 135 self.occupants.add(nick)
135 136
136
137 def replaceUser(self, nick): 137 def replaceUser(self, nick):
138 """Add user if it is not in the group list""" 138 """Add user if it is not in the group list"""
139 debug (_("Replacing user %s") % nick) 139 debug (_("Replacing user %s") % nick)
140 if self.type != "group": 140 if self.type != "group":
141 error (_("[INTERNAL] trying to replace user for a non group chat window")) 141 error (_("[INTERNAL] trying to replace user for a non group chat window"))
142 return 142 return
143 QuickChat.replaceUser(self, nick) 143 QuickChat.replaceUser(self, nick)
144 self.present_panel.presents.replace(nick)
145 self.occupants.add(nick)
144 146
145 def removeUser(self, nick): 147 def removeUser(self, nick):
146 """Remove a user from the group list""" 148 """Remove a user from the group list"""
147 QuickChat.removeUser(self, nick) 149 QuickChat.removeUser(self, nick)
148 self.present_panel.presents.remove(nick) 150 self.present_panel.presents.remove(nick)
208 """Print the message with differents colors depending on where it comes from.""" 210 """Print the message with differents colors depending on where it comes from."""
209 jid=JID(from_jid) 211 jid=JID(from_jid)
210 print "printMessage, jid=",jid,"type=",self.type 212 print "printMessage, jid=",jid,"type=",self.type
211 nick = jid.resource if self.type == "group" else (self.host.CM.getAttr(jid,'nick') or self.host.CM.getAttr(jid,'name') or jid.node) 213 nick = jid.resource if self.type == "group" else (self.host.CM.getAttr(jid,'nick') or self.host.CM.getAttr(jid,'name') or jid.node)
212 mymess = (jid.resource == self.nick) if self.type == "group" else (jid.short == self.host.profiles[profile]['whoami'].short) #mymess = True if message comes from local user 214 mymess = (jid.resource == self.nick) if self.type == "group" else (jid.short == self.host.profiles[profile]['whoami'].short) #mymess = True if message comes from local user
213 _font = wx.Font(self.font["points"], self.font["family"], wx.NORMAL, wx.BOLD) 215 _font_bold = wx.Font(self.font["points"], self.font["family"], wx.NORMAL, wx.BOLD)
214 self.chatWindow.SetDefaultStyle(wx.TextAttr( "BLACK" if mymess else "BLUE", font=_font)) 216 _font_normal = wx.Font(self.font["points"], self.font["family"], wx.NORMAL, wx.NORMAL)
217 _font_italic = wx.Font(self.font["points"], self.font["family"], wx.ITALIC if mymess else wx.NORMAL, wx.NORMAL)
218 self.chatWindow.SetDefaultStyle(wx.TextAttr("BLACK", font=_font_normal))
219 msg_time = time.localtime(timestamp or None)
220 time_format = "%c" if msg_time < self.day_change else "%H:%M" #if the message was sent before today, we print the full date
221 self.chatWindow.AppendText("[%s]" % time.strftime(time_format, msg_time ))
222 self.chatWindow.SetDefaultStyle(wx.TextAttr( "BLACK" if mymess else "BLUE", font=_font_bold))
215 self.chatWindow.AppendText("[%s] " % nick) 223 self.chatWindow.AppendText("[%s] " % nick)
216 _font = wx.Font(self.font["points"], self.font["family"], wx.ITALIC if mymess else wx.NORMAL, wx.NORMAL) 224 self.chatWindow.SetDefaultStyle(wx.TextAttr("BLACK", font=_font_italic))
217 self.chatWindow.SetDefaultStyle(wx.TextAttr("BLACK", font=_font))
218 self.chatWindow.AppendText("%s\n" % msg) 225 self.chatWindow.AppendText("%s\n" % msg)
219 if not mymess: 226 if not mymess:
220 #TODO: use notification system 227 #TODO: use notification system
221 self.RequestUserAttention() #FIXME: do this only if in background. 228 self.RequestUserAttention() #FIXME: do this only if in background.
222 self.Show() #gof: FIXME: to check 229 self.Show() #gof: FIXME: to check