Mercurial > libervia-backend
annotate frontends/wix/chat.py @ 77:1ae680f9682e
wix: MUC groupchat management + short nick shown in chat window instead of full jid when possible
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 30 Mar 2010 16:08:44 +1100 |
parents | 8becde8a967c |
children | ace2af8abc5a |
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 | |
72 | 30 from contact_list import ContactList |
0 | 31 |
32 | |
33 idSEND = 1 | |
34 | |
35 class Chat(wx.Frame, QuickChat): | |
36 """The chat Window for one to one conversations""" | |
37 | |
72 | 38 def __init__(self, target, host, type='one2one'): |
39 wx.Frame.__init__(self, None, title=target, pos=(0,0), size=(400,200)) | |
40 QuickChat.__init__(self, target, host, type) | |
0 | 41 |
72 | 42 self.splitter = wx.SplitterWindow(self, -1) |
43 | |
44 self.conv_panel = wx.Panel(self.splitter) | |
45 self.conv_panel.sizer = wx.BoxSizer(wx.VERTICAL) | |
76 | 46 self.subjectBox = wx.TextCtrl(self.conv_panel, -1, style = wx.TE_READONLY) |
72 | 47 self.chatWindow = wx.TextCtrl(self.conv_panel, -1, style = wx.TE_MULTILINE | wx.TE_RICH | wx.TE_READONLY) |
48 self.textBox = wx.TextCtrl(self.conv_panel, -1, style = wx.TE_PROCESS_ENTER) | |
76 | 49 self.conv_panel.sizer.Add(self.subjectBox, flag=wx.EXPAND) |
72 | 50 self.conv_panel.sizer.Add(self.chatWindow, 1, flag=wx.EXPAND) |
51 self.conv_panel.sizer.Add(self.textBox, flag=wx.EXPAND) | |
52 self.conv_panel.SetSizer(self.conv_panel.sizer) | |
53 self.splitter.Initialize(self.conv_panel) | |
54 self.setType(self.type) | |
55 | |
76 | 56 self.__createMenus() |
0 | 57 |
58 #events | |
59 self.Bind(wx.EVT_CLOSE, self.onClose, self) | |
60 self.Bind(wx.EVT_TEXT_ENTER, self.onEnterPressed, self.textBox) | |
61 | |
62 #fonts | |
63 self.font={} | |
64 self.font["points"] = self.chatWindow.GetFont().GetPointSize() | |
65 self.font["family"] = self.chatWindow.GetFont().GetFamily() | |
66 | |
67
0e50dd3a234a
message sending bug fixes + sortilege update
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
67 self.historyPrint(profile=self.host.profile) |
0 | 68 |
69 #misc | |
70 self.textBox.SetFocus() | |
71 self.Hide() #We hide because of the show toggle | |
72 | 72 |
73 def __createPresents(self): | |
74 """Create a list of present people in a group chat""" | |
75 self.present_panel = wx.Panel(self.splitter) | |
76 self.present_panel.sizer = wx.BoxSizer(wx.VERTICAL) | |
77 self.present_panel.SetBackgroundColour(wx.BLUE) | |
78 self.present_panel.presents = ContactList(self.present_panel, self.host, type='nicks') | |
79 self.present_panel.presents.SetMinSize(wx.Size(80,20)) | |
80 self.present_panel.sizer.Add(self.present_panel.presents, 1, wx.EXPAND) | |
81 self.present_panel.SetSizer(self.present_panel.sizer) | |
82 self.splitter.SplitVertically(self.present_panel, self.conv_panel, 80) | |
83 | |
84 def setType(self, type): | |
85 QuickChat.setType(self, type) | |
86 if type is 'group' and not self.splitter.IsSplit(): | |
87 self.__createPresents() | |
76 | 88 self.subjectBox.Show() |
72 | 89 elif type is 'one2one' and self.splitter.IsSplit(): |
90 self.splitter.Unsplit(self.present_panel) | |
91 del self.present_panel | |
76 | 92 else: |
93 self.subjectBox.Hide() | |
72 | 94 |
95 def setPresents(self, nicks): | |
96 """Set the users presents in the contact list for a group chat | |
97 @param nicks: list of nicknames | |
98 """ | |
99 debug (_("Adding users %s to room") % nicks) | |
100 if self.type != "group": | |
101 error (_("[INTERNAL] trying to set presents nicks for a non group chat window")) | |
102 return | |
103 for nick in nicks: | |
104 self.present_panel.presents.replace(nick) | |
75 | 105 |
106 | |
107 def replaceUser(self, nick): | |
108 """Add user if it is not in the group list""" | |
109 debug (_("Replacing user %s") % nick) | |
110 if self.type != "group": | |
111 error (_("[INTERNAL] trying to replace user for a non group chat window")) | |
112 return | |
113 self.present_panel.presents.replace(nick) | |
114 | |
115 def removeUser(self, nick): | |
116 """Remove a user from the group list""" | |
117 debug(_("Removing user %s") % nick) | |
118 if self.type != "group": | |
119 error (_("[INTERNAL] trying to remove user for a non group chat window")) | |
120 return | |
121 self.present_panel.presents.remove(nick) | |
122 | |
76 | 123 def setSubject(self, subject): |
124 """Set title for a group chat""" | |
125 debug(_("Setting subject to %s") % subject) | |
126 if self.type != "group": | |
127 error (_("[INTERNAL] trying to set subject for a non group chat window")) | |
128 return | |
129 self.subjectBox.SetValue(subject) | |
75 | 130 |
72 | 131 |
76 | 132 def __createMenus(self): |
0 | 133 info("Creating menus") |
134 actionMenu = wx.Menu() | |
70 | 135 actionMenu.Append(idSEND, _("&SendFile CTRL-s"),_(" Send a file to contact")) |
0 | 136 menuBar = wx.MenuBar() |
70 | 137 menuBar.Append(actionMenu,_("&Action")) |
0 | 138 self.SetMenuBar(menuBar) |
139 | |
140 #events | |
141 wx.EVT_MENU(self, idSEND, self.onSendFile) | |
142 | |
143 def __del__(self): | |
144 wx.Frame.__del__(self) | |
145 | |
146 def onClose(self, event): | |
147 """Close event: we only hide the frame.""" | |
148 event.Veto() | |
149 self.Show() ## this is a workaround to a wxpython bug: | |
150 ## with Raise on hidden frame, Hide doesn't work anymore | |
151 ## TODO: check this and repport bug to wxpython devs | |
152 self.Hide() | |
153 | |
154 def onEnterPressed(self, event): | |
155 """Behaviour when enter pressed in send line.""" | |
77
1ae680f9682e
wix: MUC groupchat management + short nick shown in chat window instead of full jid when possible
Goffi <goffi@goffi.org>
parents:
76
diff
changeset
|
156 self.host.bridge.sendMessage(self.target.short if self.type=='group' else self.target, |
1ae680f9682e
wix: MUC groupchat management + short nick shown in chat window instead of full jid when possible
Goffi <goffi@goffi.org>
parents:
76
diff
changeset
|
157 event.GetString(), |
1ae680f9682e
wix: MUC groupchat management + short nick shown in chat window instead of full jid when possible
Goffi <goffi@goffi.org>
parents:
76
diff
changeset
|
158 type = "groupchat" if self.type=='group' else "chat", |
1ae680f9682e
wix: MUC groupchat management + short nick shown in chat window instead of full jid when possible
Goffi <goffi@goffi.org>
parents:
76
diff
changeset
|
159 profile_key=self.host.profile) |
0 | 160 self.textBox.Clear() |
161 | |
162 | |
163 | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
164 def printMessage(self, from_jid, msg, profile, timestamp=""): |
0 | 165 """Print the message with differents colors depending on where it comes from.""" |
166 jid=JID(from_jid) | |
77
1ae680f9682e
wix: MUC groupchat management + short nick shown in chat window instead of full jid when possible
Goffi <goffi@goffi.org>
parents:
76
diff
changeset
|
167 nick = jid.resource if self.type == "group" else (self.host.CM.getAttr(jid,'nick') or self.host.CM.getAttr(jid,'name') or jid) |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
168 mymess = (jid.short == self.host.profiles[profile]['whoami'].short) #mymess = True if message comes from local user |
0 | 169 _font = wx.Font(self.font["points"], self.font["family"], wx.NORMAL, wx.BOLD) |
170 self.chatWindow.SetDefaultStyle(wx.TextAttr( "BLACK" if mymess else "BLUE", font=_font)) | |
77
1ae680f9682e
wix: MUC groupchat management + short nick shown in chat window instead of full jid when possible
Goffi <goffi@goffi.org>
parents:
76
diff
changeset
|
171 self.chatWindow.AppendText("[%s] " % nick) |
0 | 172 _font = wx.Font(self.font["points"], self.font["family"], wx.ITALIC if mymess else wx.NORMAL, wx.NORMAL) |
173 self.chatWindow.SetDefaultStyle(wx.TextAttr("BLACK", font=_font)) | |
174 self.chatWindow.AppendText("%s\n" % msg) | |
175 if not mymess: | |
176 self.Raise() #FIXME: too intrusive | |
177 | |
178 ### events ### | |
179 | |
180 def onSendFile(self, e): | |
70 | 181 debug(_("Send File")) |
182 filename = wx.FileSelector(_("Choose a file to send"), flags = wx.FD_FILE_MUST_EXIST) | |
0 | 183 if filename: |
70 | 184 debug(_("filename: %s"),filename) |
72 | 185 full_jid = self.host.CM.get_full(self.target) |
0 | 186 id = self.host.bridge.sendFile(full_jid, filename) |
70 | 187 self.host.waitProgress(id, _("File Transfer"), _("Copying %s") % os.path.basename(filename)) |
0 | 188 |