wix: time is now printed in chat window

- replaceUser is fixed
This commit is contained in:
Goffi 2010-07-08 18:26:30 +08:00
commit 8f52701d89

View file

@ -23,6 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import wx
import os.path
import time
import pdb
from logging import debug, info, error, warning
from tools.jid import JID
@ -68,9 +69,10 @@ class Chat(wx.Frame, QuickChat):
self.font["points"] = self.chatWindow.GetFont().GetPointSize()
self.font["family"] = self.chatWindow.GetFont().GetFamily()
self.setType(self.type)
#misc
self.day_change = time.strptime(time.strftime("%a %b %d 00:00:00 %Y")) #struct_time of day changing time
self.setType(self.type)
self.textBox.SetFocus()
self.Hide() #We hide because of the show toggle
@ -92,7 +94,6 @@ class Chat(wx.Frame, QuickChat):
self.subjectBox.Show()
self.__eraseMenus()
self.__createMenus_group()
self.historyPrint(profile=self.host.profile)
self.sizer.Layout()
elif type is 'one2one' and self.splitter.IsSplit():
self.splitter.Unsplit(self.present_panel)
@ -133,7 +134,6 @@ class Chat(wx.Frame, QuickChat):
self.present_panel.presents.replace(nick)
self.occupants.add(nick)
def replaceUser(self, nick):
"""Add user if it is not in the group list"""
debug (_("Replacing user %s") % nick)
@ -141,6 +141,8 @@ class Chat(wx.Frame, QuickChat):
error (_("[INTERNAL] trying to replace user for a non group chat window"))
return
QuickChat.replaceUser(self, nick)
self.present_panel.presents.replace(nick)
self.occupants.add(nick)
def removeUser(self, nick):
"""Remove a user from the group list"""
@ -210,11 +212,16 @@ class Chat(wx.Frame, QuickChat):
print "printMessage, jid=",jid,"type=",self.type
nick = jid.resource if self.type == "group" else (self.host.CM.getAttr(jid,'nick') or self.host.CM.getAttr(jid,'name') or jid.node)
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
_font = wx.Font(self.font["points"], self.font["family"], wx.NORMAL, wx.BOLD)
self.chatWindow.SetDefaultStyle(wx.TextAttr( "BLACK" if mymess else "BLUE", font=_font))
_font_bold = wx.Font(self.font["points"], self.font["family"], wx.NORMAL, wx.BOLD)
_font_normal = wx.Font(self.font["points"], self.font["family"], wx.NORMAL, wx.NORMAL)
_font_italic = wx.Font(self.font["points"], self.font["family"], wx.ITALIC if mymess else wx.NORMAL, wx.NORMAL)
self.chatWindow.SetDefaultStyle(wx.TextAttr("BLACK", font=_font_normal))
msg_time = time.localtime(timestamp or None)
time_format = "%c" if msg_time < self.day_change else "%H:%M" #if the message was sent before today, we print the full date
self.chatWindow.AppendText("[%s]" % time.strftime(time_format, msg_time ))
self.chatWindow.SetDefaultStyle(wx.TextAttr( "BLACK" if mymess else "BLUE", font=_font_bold))
self.chatWindow.AppendText("[%s] " % nick)
_font = wx.Font(self.font["points"], self.font["family"], wx.ITALIC if mymess else wx.NORMAL, wx.NORMAL)
self.chatWindow.SetDefaultStyle(wx.TextAttr("BLACK", font=_font))
self.chatWindow.SetDefaultStyle(wx.TextAttr("BLACK", font=_font_italic))
self.chatWindow.AppendText("%s\n" % msg)
if not mymess:
#TODO: use notification system