Mercurial > libervia-backend
annotate frontends/wix/chat.py @ 72:f271fff3a713
MUC implementation: first draft
/!\ the experimental muc branche of wokkel must be used
- bridge: new roomJoined signal
- wix: contact list widget is now in a separate file, and manage different kinds of presentation
- wix: chat window now manage group chat (first draft, not working yet)
- wix: constants are now in a separate class, so then can be accessible from everywhere
- wix: new menu to join room (do nothing yet, except entering in a test room)
- new plugin for xep 0045 (MUC), use wokkel experimental MUC branch
- plugins: the profile is now given for get_handler, cause it can be used internally by a plugin (e.g.: xep-0045 plugin)
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 21 Mar 2010 10:28:55 +1100 |
parents | 8f2ed279784b |
children | 7322a41f8a8e |
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) | |
100 | |
0 | 101 def createMenus(self): |
102 info("Creating menus") | |
103 actionMenu = wx.Menu() | |
70 | 104 actionMenu.Append(idSEND, _("&SendFile CTRL-s"),_(" Send a file to contact")) |
0 | 105 menuBar = wx.MenuBar() |
70 | 106 menuBar.Append(actionMenu,_("&Action")) |
0 | 107 self.SetMenuBar(menuBar) |
108 | |
109 #events | |
110 wx.EVT_MENU(self, idSEND, self.onSendFile) | |
111 | |
112 def __del__(self): | |
113 wx.Frame.__del__(self) | |
114 | |
115 def onClose(self, event): | |
116 """Close event: we only hide the frame.""" | |
117 event.Veto() | |
118 self.Show() ## this is a workaround to a wxpython bug: | |
119 ## with Raise on hidden frame, Hide doesn't work anymore | |
120 ## TODO: check this and repport bug to wxpython devs | |
121 self.Hide() | |
122 | |
123 def onEnterPressed(self, event): | |
124 """Behaviour when enter pressed in send line.""" | |
72 | 125 self.host.bridge.sendMessage(self.target, event.GetString(), profile_key=self.host.profile) |
0 | 126 self.textBox.Clear() |
127 | |
128 | |
129 | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
130 def printMessage(self, from_jid, msg, profile, timestamp=""): |
0 | 131 """Print the message with differents colors depending on where it comes from.""" |
132 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
|
133 mymess = (jid.short == self.host.profiles[profile]['whoami'].short) #mymess = True if message comes from local user |
0 | 134 _font = wx.Font(self.font["points"], self.font["family"], wx.NORMAL, wx.BOLD) |
135 self.chatWindow.SetDefaultStyle(wx.TextAttr( "BLACK" if mymess else "BLUE", font=_font)) | |
136 self.chatWindow.AppendText("[%s] " % jid) | |
137 _font = wx.Font(self.font["points"], self.font["family"], wx.ITALIC if mymess else wx.NORMAL, wx.NORMAL) | |
138 self.chatWindow.SetDefaultStyle(wx.TextAttr("BLACK", font=_font)) | |
139 self.chatWindow.AppendText("%s\n" % msg) | |
140 if not mymess: | |
141 self.Raise() #FIXME: too intrusive | |
142 | |
143 ### events ### | |
144 | |
145 def onSendFile(self, e): | |
70 | 146 debug(_("Send File")) |
147 filename = wx.FileSelector(_("Choose a file to send"), flags = wx.FD_FILE_MUST_EXIST) | |
0 | 148 if filename: |
70 | 149 debug(_("filename: %s"),filename) |
72 | 150 full_jid = self.host.CM.get_full(self.target) |
0 | 151 id = self.host.bridge.sendFile(full_jid, filename) |
70 | 152 self.host.waitProgress(id, _("File Transfer"), _("Copying %s") % os.path.basename(filename)) |
0 | 153 |