annotate frontends/wix/chat.py @ 54:2ce9e350cdf9

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