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