Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
71:efe81b61673c | 72:f271fff3a713 |
---|---|
25 import os.path | 25 import os.path |
26 import pdb | 26 import pdb |
27 from logging import debug, info, error | 27 from logging import debug, info, error |
28 from tools.jid import JID | 28 from tools.jid import JID |
29 from quick_frontend.quick_chat import QuickChat | 29 from quick_frontend.quick_chat import QuickChat |
30 from contact_list import ContactList | |
30 | 31 |
31 | 32 |
32 idSEND = 1 | 33 idSEND = 1 |
33 | 34 |
34 class Chat(wx.Frame, QuickChat): | 35 class Chat(wx.Frame, QuickChat): |
35 """The chat Window for one to one conversations""" | 36 """The chat Window for one to one conversations""" |
36 | 37 |
37 def __init__(self, to_jid, host): | 38 def __init__(self, target, host, type='one2one'): |
38 wx.Frame.__init__(self, None, title=to_jid, pos=(0,0), size=(400,200)) | 39 wx.Frame.__init__(self, None, title=target, pos=(0,0), size=(400,200)) |
39 QuickChat.__init__(self, to_jid, host) | 40 QuickChat.__init__(self, target, host, type) |
40 | 41 |
41 self.chatWindow = wx.TextCtrl(self, -1, style = wx.TE_MULTILINE | wx.TE_RICH | wx.TE_READONLY) | 42 self.splitter = wx.SplitterWindow(self, -1) |
42 self.textBox = wx.TextCtrl(self, -1, style = wx.TE_PROCESS_ENTER) | 43 |
43 self.sizer = wx.BoxSizer(wx.VERTICAL) | 44 self.conv_panel = wx.Panel(self.splitter) |
44 self.sizer.Add(self.chatWindow, 1, flag=wx.EXPAND) | 45 self.conv_panel.sizer = wx.BoxSizer(wx.VERTICAL) |
45 self.sizer.Add(self.textBox, flag=wx.EXPAND) | 46 self.chatWindow = wx.TextCtrl(self.conv_panel, -1, style = wx.TE_MULTILINE | wx.TE_RICH | wx.TE_READONLY) |
46 self.SetSizer(self.sizer) | 47 self.textBox = wx.TextCtrl(self.conv_panel, -1, style = wx.TE_PROCESS_ENTER) |
47 self.SetAutoLayout(True) | 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 | |
48 self.createMenus() | 54 self.createMenus() |
49 | 55 |
50 #events | 56 #events |
51 self.Bind(wx.EVT_CLOSE, self.onClose, self) | 57 self.Bind(wx.EVT_CLOSE, self.onClose, self) |
52 self.Bind(wx.EVT_TEXT_ENTER, self.onEnterPressed, self.textBox) | 58 self.Bind(wx.EVT_TEXT_ENTER, self.onEnterPressed, self.textBox) |
59 self.historyPrint(profile=self.host.profile) | 65 self.historyPrint(profile=self.host.profile) |
60 | 66 |
61 #misc | 67 #misc |
62 self.textBox.SetFocus() | 68 self.textBox.SetFocus() |
63 self.Hide() #We hide because of the show toggle | 69 self.Hide() #We hide because of the show toggle |
64 | 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 | |
65 def createMenus(self): | 101 def createMenus(self): |
66 info("Creating menus") | 102 info("Creating menus") |
67 actionMenu = wx.Menu() | 103 actionMenu = wx.Menu() |
68 actionMenu.Append(idSEND, _("&SendFile CTRL-s"),_(" Send a file to contact")) | 104 actionMenu.Append(idSEND, _("&SendFile CTRL-s"),_(" Send a file to contact")) |
69 menuBar = wx.MenuBar() | 105 menuBar = wx.MenuBar() |
84 ## TODO: check this and repport bug to wxpython devs | 120 ## TODO: check this and repport bug to wxpython devs |
85 self.Hide() | 121 self.Hide() |
86 | 122 |
87 def onEnterPressed(self, event): | 123 def onEnterPressed(self, event): |
88 """Behaviour when enter pressed in send line.""" | 124 """Behaviour when enter pressed in send line.""" |
89 self.host.bridge.sendMessage(self.to_jid, event.GetString(), profile_key=self.host.profile) | 125 self.host.bridge.sendMessage(self.target, event.GetString(), profile_key=self.host.profile) |
90 self.textBox.Clear() | 126 self.textBox.Clear() |
91 | 127 |
92 | 128 |
93 | 129 |
94 def printMessage(self, from_jid, msg, profile, timestamp=""): | 130 def printMessage(self, from_jid, msg, profile, timestamp=""): |
109 def onSendFile(self, e): | 145 def onSendFile(self, e): |
110 debug(_("Send File")) | 146 debug(_("Send File")) |
111 filename = wx.FileSelector(_("Choose a file to send"), flags = wx.FD_FILE_MUST_EXIST) | 147 filename = wx.FileSelector(_("Choose a file to send"), flags = wx.FD_FILE_MUST_EXIST) |
112 if filename: | 148 if filename: |
113 debug(_("filename: %s"),filename) | 149 debug(_("filename: %s"),filename) |
114 full_jid = self.host.CM.get_full(self.to_jid) | 150 full_jid = self.host.CM.get_full(self.target) |
115 id = self.host.bridge.sendFile(full_jid, filename) | 151 id = self.host.bridge.sendFile(full_jid, filename) |
116 self.host.waitProgress(id, _("File Transfer"), _("Copying %s") % os.path.basename(filename)) | 152 self.host.waitProgress(id, _("File Transfer"), _("Copying %s") % os.path.basename(filename)) |
117 | 153 |