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