annotate frontends/wix/chat.py @ 70:8f2ed279784b

i18n - gettext support added in frontends - first draft of frontends french translation
author Goffi <goffi@goffi.org>
date Fri, 05 Mar 2010 20:33:10 +1100
parents 0e50dd3a234a
children f271fff3a713
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
goffi@necton2
parents:
diff changeset
1 #!/usr/bin/python
goffi@necton2
parents:
diff changeset
2 # -*- coding: utf-8 -*-
goffi@necton2
parents:
diff changeset
3
goffi@necton2
parents:
diff changeset
4 """
goffi@necton2
parents:
diff changeset
5 wix: a SAT frontend
57
a5b5fb5fc9fd updated README and copyright note
Goffi <goffi@goffi.org>
parents: 0
diff changeset
6 Copyright (C) 2009, 2010 Jérôme Poisson (goffi@goffi.org)
0
goffi@necton2
parents:
diff changeset
7
goffi@necton2
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
goffi@necton2
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
goffi@necton2
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
goffi@necton2
parents:
diff changeset
11 (at your option) any later version.
goffi@necton2
parents:
diff changeset
12
goffi@necton2
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
goffi@necton2
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
goffi@necton2
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
goffi@necton2
parents:
diff changeset
16 GNU General Public License for more details.
goffi@necton2
parents:
diff changeset
17
goffi@necton2
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
goffi@necton2
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
goffi@necton2
parents:
diff changeset
20 """
goffi@necton2
parents:
diff changeset
21
goffi@necton2
parents:
diff changeset
22
goffi@necton2
parents:
diff changeset
23
goffi@necton2
parents:
diff changeset
24 import wx
goffi@necton2
parents:
diff changeset
25 import os.path
goffi@necton2
parents:
diff changeset
26 import pdb
goffi@necton2
parents:
diff changeset
27 from logging import debug, info, error
goffi@necton2
parents:
diff changeset
28 from tools.jid import JID
goffi@necton2
parents:
diff changeset
29 from quick_frontend.quick_chat import QuickChat
goffi@necton2
parents:
diff changeset
30
goffi@necton2
parents:
diff changeset
31
goffi@necton2
parents:
diff changeset
32 idSEND = 1
goffi@necton2
parents:
diff changeset
33
goffi@necton2
parents:
diff changeset
34 class Chat(wx.Frame, QuickChat):
goffi@necton2
parents:
diff changeset
35 """The chat Window for one to one conversations"""
goffi@necton2
parents:
diff changeset
36
goffi@necton2
parents:
diff changeset
37 def __init__(self, to_jid, host):
goffi@necton2
parents:
diff changeset
38 wx.Frame.__init__(self, None, title=to_jid, pos=(0,0), size=(400,200))
goffi@necton2
parents:
diff changeset
39 QuickChat.__init__(self, to_jid, host)
goffi@necton2
parents:
diff changeset
40
goffi@necton2
parents:
diff changeset
41 self.chatWindow = wx.TextCtrl(self, -1, style = wx.TE_MULTILINE | wx.TE_RICH | wx.TE_READONLY)
goffi@necton2
parents:
diff changeset
42 self.textBox = wx.TextCtrl(self, -1, style = wx.TE_PROCESS_ENTER)
goffi@necton2
parents:
diff changeset
43 self.sizer = wx.BoxSizer(wx.VERTICAL)
goffi@necton2
parents:
diff changeset
44 self.sizer.Add(self.chatWindow, 1, flag=wx.EXPAND)
goffi@necton2
parents:
diff changeset
45 self.sizer.Add(self.textBox, flag=wx.EXPAND)
goffi@necton2
parents:
diff changeset
46 self.SetSizer(self.sizer)
goffi@necton2
parents:
diff changeset
47 self.SetAutoLayout(True)
goffi@necton2
parents:
diff changeset
48 self.createMenus()
goffi@necton2
parents:
diff changeset
49
goffi@necton2
parents:
diff changeset
50 #events
goffi@necton2
parents:
diff changeset
51 self.Bind(wx.EVT_CLOSE, self.onClose, self)
goffi@necton2
parents:
diff changeset
52 self.Bind(wx.EVT_TEXT_ENTER, self.onEnterPressed, self.textBox)
goffi@necton2
parents:
diff changeset
53
goffi@necton2
parents:
diff changeset
54 #fonts
goffi@necton2
parents:
diff changeset
55 self.font={}
goffi@necton2
parents:
diff changeset
56 self.font["points"] = self.chatWindow.GetFont().GetPointSize()
goffi@necton2
parents:
diff changeset
57 self.font["family"] = self.chatWindow.GetFont().GetFamily()
goffi@necton2
parents:
diff changeset
58
67
0e50dd3a234a message sending bug fixes + sortilege update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
59 self.historyPrint(profile=self.host.profile)
0
goffi@necton2
parents:
diff changeset
60
goffi@necton2
parents:
diff changeset
61 #misc
goffi@necton2
parents:
diff changeset
62 self.textBox.SetFocus()
goffi@necton2
parents:
diff changeset
63 self.Hide() #We hide because of the show toggle
goffi@necton2
parents:
diff changeset
64
goffi@necton2
parents:
diff changeset
65 def createMenus(self):
goffi@necton2
parents:
diff changeset
66 info("Creating menus")
goffi@necton2
parents:
diff changeset
67 actionMenu = wx.Menu()
70
Goffi <goffi@goffi.org>
parents: 67
diff changeset
68 actionMenu.Append(idSEND, _("&SendFile CTRL-s"),_(" Send a file to contact"))
0
goffi@necton2
parents:
diff changeset
69 menuBar = wx.MenuBar()
70
Goffi <goffi@goffi.org>
parents: 67
diff changeset
70 menuBar.Append(actionMenu,_("&Action"))
0
goffi@necton2
parents:
diff changeset
71 self.SetMenuBar(menuBar)
goffi@necton2
parents:
diff changeset
72
goffi@necton2
parents:
diff changeset
73 #events
goffi@necton2
parents:
diff changeset
74 wx.EVT_MENU(self, idSEND, self.onSendFile)
goffi@necton2
parents:
diff changeset
75
goffi@necton2
parents:
diff changeset
76 def __del__(self):
goffi@necton2
parents:
diff changeset
77 wx.Frame.__del__(self)
goffi@necton2
parents:
diff changeset
78
goffi@necton2
parents:
diff changeset
79 def onClose(self, event):
goffi@necton2
parents:
diff changeset
80 """Close event: we only hide the frame."""
goffi@necton2
parents:
diff changeset
81 event.Veto()
goffi@necton2
parents:
diff changeset
82 self.Show() ## this is a workaround to a wxpython bug:
goffi@necton2
parents:
diff changeset
83 ## with Raise on hidden frame, Hide doesn't work anymore
goffi@necton2
parents:
diff changeset
84 ## TODO: check this and repport bug to wxpython devs
goffi@necton2
parents:
diff changeset
85 self.Hide()
goffi@necton2
parents:
diff changeset
86
goffi@necton2
parents:
diff changeset
87 def onEnterPressed(self, event):
goffi@necton2
parents:
diff changeset
88 """Behaviour when enter pressed in send line."""
67
0e50dd3a234a message sending bug fixes + sortilege update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
89 self.host.bridge.sendMessage(self.to_jid, event.GetString(), profile_key=self.host.profile)
0
goffi@necton2
parents:
diff changeset
90 self.textBox.Clear()
goffi@necton2
parents:
diff changeset
91
goffi@necton2
parents:
diff changeset
92
goffi@necton2
parents:
diff changeset
93
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 57
diff changeset
94 def printMessage(self, from_jid, msg, profile, timestamp=""):
0
goffi@necton2
parents:
diff changeset
95 """Print the message with differents colors depending on where it comes from."""
goffi@necton2
parents:
diff changeset
96 jid=JID(from_jid)
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 57
diff changeset
97 mymess = (jid.short == self.host.profiles[profile]['whoami'].short) #mymess = True if message comes from local user
0
goffi@necton2
parents:
diff changeset
98 _font = wx.Font(self.font["points"], self.font["family"], wx.NORMAL, wx.BOLD)
goffi@necton2
parents:
diff changeset
99 self.chatWindow.SetDefaultStyle(wx.TextAttr( "BLACK" if mymess else "BLUE", font=_font))
goffi@necton2
parents:
diff changeset
100 self.chatWindow.AppendText("[%s] " % jid)
goffi@necton2
parents:
diff changeset
101 _font = wx.Font(self.font["points"], self.font["family"], wx.ITALIC if mymess else wx.NORMAL, wx.NORMAL)
goffi@necton2
parents:
diff changeset
102 self.chatWindow.SetDefaultStyle(wx.TextAttr("BLACK", font=_font))
goffi@necton2
parents:
diff changeset
103 self.chatWindow.AppendText("%s\n" % msg)
goffi@necton2
parents:
diff changeset
104 if not mymess:
goffi@necton2
parents:
diff changeset
105 self.Raise() #FIXME: too intrusive
goffi@necton2
parents:
diff changeset
106
goffi@necton2
parents:
diff changeset
107 ### events ###
goffi@necton2
parents:
diff changeset
108
goffi@necton2
parents:
diff changeset
109 def onSendFile(self, e):
70
Goffi <goffi@goffi.org>
parents: 67
diff changeset
110 debug(_("Send File"))
Goffi <goffi@goffi.org>
parents: 67
diff changeset
111 filename = wx.FileSelector(_("Choose a file to send"), flags = wx.FD_FILE_MUST_EXIST)
0
goffi@necton2
parents:
diff changeset
112 if filename:
70
Goffi <goffi@goffi.org>
parents: 67
diff changeset
113 debug(_("filename: %s"),filename)
0
goffi@necton2
parents:
diff changeset
114 full_jid = self.host.CM.get_full(self.to_jid)
goffi@necton2
parents:
diff changeset
115 id = self.host.bridge.sendFile(full_jid, filename)
70
Goffi <goffi@goffi.org>
parents: 67
diff changeset
116 self.host.waitProgress(id, _("File Transfer"), _("Copying %s") % os.path.basename(filename))
0
goffi@necton2
parents:
diff changeset
117