annotate frontends/src/wix/chat.py @ 406:b03b38b20c18

plugin XEP-0045: send error on invalid room jid on _join
author Goffi <goffi@goffi.org>
date Sat, 08 Oct 2011 19:04:28 +0200
parents e66d300c5d42
children 9393ffbad6dc
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
228
b1794cbb88e5 2011 copyright upgrade
Goffi <goffi@goffi.org>
parents: 227
diff changeset
6 Copyright (C) 2009, 2010, 2011 Jérôme Poisson (goffi@goffi.org)
0
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
122
29998cd0ed8d wix: time is now printed in chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
26 import time
0
goffi@necton2
parents:
diff changeset
27 import pdb
85
fc7583282d40 Tarot Game plugin: first draft
Goffi <goffi@goffi.org>
parents: 80
diff changeset
28 from logging import debug, info, error, warning
225
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
29 from sat.tools.jid import JID
227
533507bb4e32 distutils wix installation
Goffi <goffi@goffi.org>
parents: 225
diff changeset
30 from sat_frontends.quick_frontend.quick_chat import QuickChat
533507bb4e32 distutils wix installation
Goffi <goffi@goffi.org>
parents: 225
diff changeset
31 from sat_frontends.wix.contact_list import ContactList
533507bb4e32 distutils wix installation
Goffi <goffi@goffi.org>
parents: 225
diff changeset
32 from sat_frontends.wix.card_game import CardPanel
361
141eeb7cd9e6 Quizz game: first draft
Goffi <goffi@goffi.org>
parents: 321
diff changeset
33 from sat_frontends.wix.quiz_game import QuizPanel
0
goffi@necton2
parents:
diff changeset
34
goffi@necton2
parents:
diff changeset
35
goffi@necton2
parents:
diff changeset
36 idSEND = 1
85
fc7583282d40 Tarot Game plugin: first draft
Goffi <goffi@goffi.org>
parents: 80
diff changeset
37 idTAROT = 2
0
goffi@necton2
parents:
diff changeset
38
goffi@necton2
parents:
diff changeset
39 class Chat(wx.Frame, QuickChat):
goffi@necton2
parents:
diff changeset
40 """The chat Window for one to one conversations"""
goffi@necton2
parents:
diff changeset
41
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
42 def __init__(self, target, host, type='one2one'):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
43 wx.Frame.__init__(self, None, title=target, pos=(0,0), size=(400,200))
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
44 QuickChat.__init__(self, target, host, type)
0
goffi@necton2
parents:
diff changeset
45
86
4b5f2d55b6ac wix: Tarot panel now appear on top of groupchat window when a Tarot game is started
Goffi <goffi@goffi.org>
parents: 85
diff changeset
46 self.sizer = wx.BoxSizer(wx.VERTICAL)
4b5f2d55b6ac wix: Tarot panel now appear on top of groupchat window when a Tarot game is started
Goffi <goffi@goffi.org>
parents: 85
diff changeset
47 self.SetSizer(self.sizer)
4b5f2d55b6ac wix: Tarot panel now appear on top of groupchat window when a Tarot game is started
Goffi <goffi@goffi.org>
parents: 85
diff changeset
48
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
49 self.splitter = wx.SplitterWindow(self, -1)
86
4b5f2d55b6ac wix: Tarot panel now appear on top of groupchat window when a Tarot game is started
Goffi <goffi@goffi.org>
parents: 85
diff changeset
50 self.sizer.Add(self.splitter, 1, flag = wx.EXPAND)
4b5f2d55b6ac wix: Tarot panel now appear on top of groupchat window when a Tarot game is started
Goffi <goffi@goffi.org>
parents: 85
diff changeset
51
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
52 self.conv_panel = wx.Panel(self.splitter)
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
53 self.conv_panel.sizer = wx.BoxSizer(wx.VERTICAL)
76
8becde8a967c MUC: added subject management
Goffi <goffi@goffi.org>
parents: 75
diff changeset
54 self.subjectBox = wx.TextCtrl(self.conv_panel, -1, style = wx.TE_READONLY)
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
55 self.chatWindow = wx.TextCtrl(self.conv_panel, -1, style = wx.TE_MULTILINE | wx.TE_RICH | wx.TE_READONLY)
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
56 self.textBox = wx.TextCtrl(self.conv_panel, -1, style = wx.TE_PROCESS_ENTER)
76
8becde8a967c MUC: added subject management
Goffi <goffi@goffi.org>
parents: 75
diff changeset
57 self.conv_panel.sizer.Add(self.subjectBox, flag=wx.EXPAND)
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
58 self.conv_panel.sizer.Add(self.chatWindow, 1, flag=wx.EXPAND)
86
4b5f2d55b6ac wix: Tarot panel now appear on top of groupchat window when a Tarot game is started
Goffi <goffi@goffi.org>
parents: 85
diff changeset
59 self.conv_panel.sizer.Add(self.textBox, 0, flag=wx.EXPAND)
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
60 self.conv_panel.SetSizer(self.conv_panel.sizer)
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
61 self.splitter.Initialize(self.conv_panel)
78
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
62 self.SetMenuBar(wx.MenuBar())
0
goffi@necton2
parents:
diff changeset
63
goffi@necton2
parents:
diff changeset
64 #events
goffi@necton2
parents:
diff changeset
65 self.Bind(wx.EVT_CLOSE, self.onClose, self)
goffi@necton2
parents:
diff changeset
66 self.Bind(wx.EVT_TEXT_ENTER, self.onEnterPressed, self.textBox)
goffi@necton2
parents:
diff changeset
67
goffi@necton2
parents:
diff changeset
68 #fonts
goffi@necton2
parents:
diff changeset
69 self.font={}
goffi@necton2
parents:
diff changeset
70 self.font["points"] = self.chatWindow.GetFont().GetPointSize()
goffi@necton2
parents:
diff changeset
71 self.font["family"] = self.chatWindow.GetFont().GetFamily()
goffi@necton2
parents:
diff changeset
72
79
db0a0f000e37 Chat presentation enhancement
Goffi <goffi@goffi.org>
parents: 78
diff changeset
73
0
goffi@necton2
parents:
diff changeset
74 #misc
122
29998cd0ed8d wix: time is now printed in chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
75 self.day_change = time.strptime(time.strftime("%a %b %d 00:00:00 %Y")) #struct_time of day changing time
29998cd0ed8d wix: time is now printed in chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
76 self.setType(self.type)
0
goffi@necton2
parents:
diff changeset
77 self.textBox.SetFocus()
goffi@necton2
parents:
diff changeset
78 self.Hide() #We hide because of the show toggle
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
79
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
80 def __createPresents(self):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
81 """Create a list of present people in a group chat"""
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
82 self.present_panel = wx.Panel(self.splitter)
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
83 self.present_panel.sizer = wx.BoxSizer(wx.VERTICAL)
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
84 self.present_panel.SetBackgroundColour(wx.BLUE)
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
85 self.present_panel.presents = ContactList(self.present_panel, self.host, type='nicks')
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
86 self.present_panel.presents.SetMinSize(wx.Size(80,20))
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
87 self.present_panel.sizer.Add(self.present_panel.presents, 1, wx.EXPAND)
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
88 self.present_panel.SetSizer(self.present_panel.sizer)
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
89 self.splitter.SplitVertically(self.present_panel, self.conv_panel, 80)
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
90
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
91 def setType(self, type):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
92 QuickChat.setType(self, type)
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
93 if type is 'group' and not self.splitter.IsSplit():
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
94 self.__createPresents()
76
8becde8a967c MUC: added subject management
Goffi <goffi@goffi.org>
parents: 75
diff changeset
95 self.subjectBox.Show()
78
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
96 self.__eraseMenus()
85
fc7583282d40 Tarot Game plugin: first draft
Goffi <goffi@goffi.org>
parents: 80
diff changeset
97 self.__createMenus_group()
86
4b5f2d55b6ac wix: Tarot panel now appear on top of groupchat window when a Tarot game is started
Goffi <goffi@goffi.org>
parents: 85
diff changeset
98 self.sizer.Layout()
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
99 elif type is 'one2one' and self.splitter.IsSplit():
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
100 self.splitter.Unsplit(self.present_panel)
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
101 del self.present_panel
78
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
102 self.GetMenuBar().Show()
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
103 self.subjectBox.Hide()
85
fc7583282d40 Tarot Game plugin: first draft
Goffi <goffi@goffi.org>
parents: 80
diff changeset
104 self.__eraseMenus()
78
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
105 self.__createMenus_O2O()
79
db0a0f000e37 Chat presentation enhancement
Goffi <goffi@goffi.org>
parents: 78
diff changeset
106 self.nick = None
76
8becde8a967c MUC: added subject management
Goffi <goffi@goffi.org>
parents: 75
diff changeset
107 else:
8becde8a967c MUC: added subject management
Goffi <goffi@goffi.org>
parents: 75
diff changeset
108 self.subjectBox.Hide()
85
fc7583282d40 Tarot Game plugin: first draft
Goffi <goffi@goffi.org>
parents: 80
diff changeset
109 self.__eraseMenus()
78
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
110 self.__createMenus_O2O()
79
db0a0f000e37 Chat presentation enhancement
Goffi <goffi@goffi.org>
parents: 78
diff changeset
111 self.historyPrint(profile=self.host.profile)
86
4b5f2d55b6ac wix: Tarot panel now appear on top of groupchat window when a Tarot game is started
Goffi <goffi@goffi.org>
parents: 85
diff changeset
112
90
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 87
diff changeset
113 def startGame(self, game_type, referee, players):
86
4b5f2d55b6ac wix: Tarot panel now appear on top of groupchat window when a Tarot game is started
Goffi <goffi@goffi.org>
parents: 85
diff changeset
114 """Configure the chat window to start a game"""
4b5f2d55b6ac wix: Tarot panel now appear on top of groupchat window when a Tarot game is started
Goffi <goffi@goffi.org>
parents: 85
diff changeset
115 if game_type=="Tarot":
4b5f2d55b6ac wix: Tarot panel now appear on top of groupchat window when a Tarot game is started
Goffi <goffi@goffi.org>
parents: 85
diff changeset
116 debug (_("configure chat window for Tarot game"))
90
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 87
diff changeset
117 self.tarot_panel = CardPanel(self, referee, players, self.nick)
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
118 self.sizer.Prepend(self.tarot_panel, 0, flag=wx.EXPAND)
86
4b5f2d55b6ac wix: Tarot panel now appear on top of groupchat window when a Tarot game is started
Goffi <goffi@goffi.org>
parents: 85
diff changeset
119 self.sizer.Layout()
4b5f2d55b6ac wix: Tarot panel now appear on top of groupchat window when a Tarot game is started
Goffi <goffi@goffi.org>
parents: 85
diff changeset
120 self.Fit()
321
1a990a88bff2 wix: force updating of splitterWindow in ChatWindow (needed when Tarot game is launched)
Goffi <goffi@goffi.org>
parents: 276
diff changeset
121 self.splitter.UpdateSize()
361
141eeb7cd9e6 Quizz game: first draft
Goffi <goffi@goffi.org>
parents: 321
diff changeset
122 elif game_type=="Quiz":
141eeb7cd9e6 Quizz game: first draft
Goffi <goffi@goffi.org>
parents: 321
diff changeset
123 debug (_("configure chat window for Quiz game"))
141eeb7cd9e6 Quizz game: first draft
Goffi <goffi@goffi.org>
parents: 321
diff changeset
124 self.quiz_panel = QuizPanel(self, referee, players, self.nick)
141eeb7cd9e6 Quizz game: first draft
Goffi <goffi@goffi.org>
parents: 321
diff changeset
125 self.sizer.Prepend(self.quiz_panel, 0, flag=wx.EXPAND)
141eeb7cd9e6 Quizz game: first draft
Goffi <goffi@goffi.org>
parents: 321
diff changeset
126 self.sizer.Layout()
141eeb7cd9e6 Quizz game: first draft
Goffi <goffi@goffi.org>
parents: 321
diff changeset
127 self.Fit()
141eeb7cd9e6 Quizz game: first draft
Goffi <goffi@goffi.org>
parents: 321
diff changeset
128 self.splitter.UpdateSize()
86
4b5f2d55b6ac wix: Tarot panel now appear on top of groupchat window when a Tarot game is started
Goffi <goffi@goffi.org>
parents: 85
diff changeset
129
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
130 def getGame(self, game_type):
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
131 """Return class managing the game type"""
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
132 #TODO: check that the game is launched, and manage errors
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
133 if game_type=="Tarot":
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
134 return self.tarot_panel
361
141eeb7cd9e6 Quizz game: first draft
Goffi <goffi@goffi.org>
parents: 321
diff changeset
135 elif game_type=="Quiz":
141eeb7cd9e6 Quizz game: first draft
Goffi <goffi@goffi.org>
parents: 321
diff changeset
136 return self.quiz_panel
85
fc7583282d40 Tarot Game plugin: first draft
Goffi <goffi@goffi.org>
parents: 80
diff changeset
137
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
138 def setPresents(self, nicks):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
139 """Set the users presents in the contact list for a group chat
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
140 @param nicks: list of nicknames
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
141 """
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 90
diff changeset
142 QuickChat.setPresents(self, nicks)
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
143 for nick in nicks:
85
fc7583282d40 Tarot Game plugin: first draft
Goffi <goffi@goffi.org>
parents: 80
diff changeset
144 self.present_panel.presents.replace(nick)
75
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
145
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
146 def replaceUser(self, nick):
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
147 """Add user if it is not in the group list"""
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
148 debug (_("Replacing user %s") % nick)
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
149 if self.type != "group":
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
150 error (_("[INTERNAL] trying to replace user for a non group chat window"))
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
151 return
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 90
diff changeset
152 QuickChat.replaceUser(self, nick)
122
29998cd0ed8d wix: time is now printed in chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
153 self.present_panel.presents.replace(nick)
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 90
diff changeset
154
75
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
155 def removeUser(self, nick):
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
156 """Remove a user from the group list"""
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 90
diff changeset
157 QuickChat.removeUser(self, nick)
75
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
158 self.present_panel.presents.remove(nick)
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
159
76
8becde8a967c MUC: added subject management
Goffi <goffi@goffi.org>
parents: 75
diff changeset
160 def setSubject(self, subject):
8becde8a967c MUC: added subject management
Goffi <goffi@goffi.org>
parents: 75
diff changeset
161 """Set title for a group chat"""
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 90
diff changeset
162 QuickChat.setSubject(self, subject)
76
8becde8a967c MUC: added subject management
Goffi <goffi@goffi.org>
parents: 75
diff changeset
163 self.subjectBox.SetValue(subject)
75
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
164
78
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
165 def __eraseMenus(self):
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
166 """erase all menus"""
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
167 menuBar = self.GetMenuBar()
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
168 for i in range(menuBar.GetMenuCount()):
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
169 menuBar.Remove(i)
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
170
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
171 def __createMenus_O2O(self):
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
172 """create menu bar for one 2 one chat"""
0
goffi@necton2
parents:
diff changeset
173 info("Creating menus")
78
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
174 self.__eraseMenus()
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
175 menuBar = self.GetMenuBar()
0
goffi@necton2
parents:
diff changeset
176 actionMenu = wx.Menu()
70
Goffi <goffi@goffi.org>
parents: 67
diff changeset
177 actionMenu.Append(idSEND, _("&SendFile CTRL-s"),_(" Send a file to contact"))
Goffi <goffi@goffi.org>
parents: 67
diff changeset
178 menuBar.Append(actionMenu,_("&Action"))
0
goffi@necton2
parents:
diff changeset
179
goffi@necton2
parents:
diff changeset
180 #events
goffi@necton2
parents:
diff changeset
181 wx.EVT_MENU(self, idSEND, self.onSendFile)
goffi@necton2
parents:
diff changeset
182
85
fc7583282d40 Tarot Game plugin: first draft
Goffi <goffi@goffi.org>
parents: 80
diff changeset
183 def __createMenus_group(self):
fc7583282d40 Tarot Game plugin: first draft
Goffi <goffi@goffi.org>
parents: 80
diff changeset
184 """create menu bar for group chat"""
fc7583282d40 Tarot Game plugin: first draft
Goffi <goffi@goffi.org>
parents: 80
diff changeset
185 info("Creating menus")
fc7583282d40 Tarot Game plugin: first draft
Goffi <goffi@goffi.org>
parents: 80
diff changeset
186 self.__eraseMenus()
fc7583282d40 Tarot Game plugin: first draft
Goffi <goffi@goffi.org>
parents: 80
diff changeset
187 menuBar = self.GetMenuBar()
fc7583282d40 Tarot Game plugin: first draft
Goffi <goffi@goffi.org>
parents: 80
diff changeset
188 actionMenu = wx.Menu()
fc7583282d40 Tarot Game plugin: first draft
Goffi <goffi@goffi.org>
parents: 80
diff changeset
189 actionMenu.Append(idTAROT, _("Start &Tarot game CTRL-t"),_(" Start a Tarot card game")) #tmp
fc7583282d40 Tarot Game plugin: first draft
Goffi <goffi@goffi.org>
parents: 80
diff changeset
190 menuBar.Append(actionMenu,_("&Games"))
fc7583282d40 Tarot Game plugin: first draft
Goffi <goffi@goffi.org>
parents: 80
diff changeset
191
fc7583282d40 Tarot Game plugin: first draft
Goffi <goffi@goffi.org>
parents: 80
diff changeset
192 #events
fc7583282d40 Tarot Game plugin: first draft
Goffi <goffi@goffi.org>
parents: 80
diff changeset
193 wx.EVT_MENU(self, idTAROT, self.onStartTarot)
fc7583282d40 Tarot Game plugin: first draft
Goffi <goffi@goffi.org>
parents: 80
diff changeset
194
0
goffi@necton2
parents:
diff changeset
195 def __del__(self):
goffi@necton2
parents:
diff changeset
196 wx.Frame.__del__(self)
goffi@necton2
parents:
diff changeset
197
goffi@necton2
parents:
diff changeset
198 def onClose(self, event):
goffi@necton2
parents:
diff changeset
199 """Close event: we only hide the frame."""
goffi@necton2
parents:
diff changeset
200 event.Veto()
goffi@necton2
parents:
diff changeset
201 self.Hide()
goffi@necton2
parents:
diff changeset
202
goffi@necton2
parents:
diff changeset
203 def onEnterPressed(self, event):
goffi@necton2
parents:
diff changeset
204 """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
205 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
206 event.GetString(),
276
a00e87d48213 bridge, bridge constructor: fixed mix stuff
Goffi <goffi@goffi.org>
parents: 228
diff changeset
207 mess_type = "groupchat" if self.type=='group' else "chat",
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
208 profile_key=self.host.profile)
0
goffi@necton2
parents:
diff changeset
209 self.textBox.Clear()
goffi@necton2
parents:
diff changeset
210
190
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 183
diff changeset
211 def __blink(self):
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 183
diff changeset
212 """Do wizzz and buzzz to show window to user or
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 183
diff changeset
213 at least inform him of something new"""
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 183
diff changeset
214 #TODO: use notification system
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 183
diff changeset
215 if not self.IsActive():
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 183
diff changeset
216 self.RequestUserAttention()
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 183
diff changeset
217 if not self.IsShown():
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 183
diff changeset
218 self.Show()
0
goffi@necton2
parents:
diff changeset
219
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 57
diff changeset
220 def printMessage(self, from_jid, msg, profile, timestamp=""):
0
goffi@necton2
parents:
diff changeset
221 """Print the message with differents colors depending on where it comes from."""
190
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 183
diff changeset
222 try:
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 183
diff changeset
223 jid,nick,mymess = QuickChat.printMessage(self, from_jid, msg, profile, timestamp)
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 183
diff changeset
224 except TypeError:
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 183
diff changeset
225 return
79
db0a0f000e37 Chat presentation enhancement
Goffi <goffi@goffi.org>
parents: 78
diff changeset
226 print "printMessage, jid=",jid,"type=",self.type
122
29998cd0ed8d wix: time is now printed in chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
227 _font_bold = wx.Font(self.font["points"], self.font["family"], wx.NORMAL, wx.BOLD)
29998cd0ed8d wix: time is now printed in chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
228 _font_normal = wx.Font(self.font["points"], self.font["family"], wx.NORMAL, wx.NORMAL)
29998cd0ed8d wix: time is now printed in chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
229 _font_italic = wx.Font(self.font["points"], self.font["family"], wx.ITALIC if mymess else wx.NORMAL, wx.NORMAL)
123
34766e0cf970 wix: chat: date is now printed in grey
Goffi <goffi@goffi.org>
parents: 122
diff changeset
230 self.chatWindow.SetDefaultStyle(wx.TextAttr("GREY", font=_font_normal))
122
29998cd0ed8d wix: time is now printed in chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
231 msg_time = time.localtime(timestamp or None)
29998cd0ed8d wix: time is now printed in chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
232 time_format = "%c" if msg_time < self.day_change else "%H:%M" #if the message was sent before today, we print the full date
29998cd0ed8d wix: time is now printed in chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
233 self.chatWindow.AppendText("[%s]" % time.strftime(time_format, msg_time ))
29998cd0ed8d wix: time is now printed in chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
234 self.chatWindow.SetDefaultStyle(wx.TextAttr( "BLACK" if mymess else "BLUE", font=_font_bold))
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
235 self.chatWindow.AppendText("[%s] " % nick)
122
29998cd0ed8d wix: time is now printed in chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
236 self.chatWindow.SetDefaultStyle(wx.TextAttr("BLACK", font=_font_italic))
0
goffi@necton2
parents:
diff changeset
237 self.chatWindow.AppendText("%s\n" % msg)
goffi@necton2
parents:
diff changeset
238 if not mymess:
190
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 183
diff changeset
239 self.__blink()
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 183
diff changeset
240
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 183
diff changeset
241 def printInfo(self, msg, type='normal'):
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 183
diff changeset
242 """Print general info
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 183
diff changeset
243 @param msg: message to print
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 183
diff changeset
244 @type: one of:
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 183
diff changeset
245 normal: general info like "toto has joined the room"
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 183
diff changeset
246 me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist"
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 183
diff changeset
247 """
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 183
diff changeset
248 _font_bold = wx.Font(self.font["points"], self.font["family"], wx.NORMAL, wx.BOLD)
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 183
diff changeset
249 _font_normal = wx.Font(self.font["points"], self.font["family"], wx.NORMAL, wx.NORMAL)
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 183
diff changeset
250 self.chatWindow.SetDefaultStyle(wx.TextAttr("BLACK", font=_font_bold if type == 'normal' else _font_normal))
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 183
diff changeset
251 self.chatWindow.AppendText("%s\n" % msg)
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 183
diff changeset
252 if type=="me":
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 183
diff changeset
253 self.__blink()
0
goffi@necton2
parents:
diff changeset
254
goffi@necton2
parents:
diff changeset
255 ### events ###
goffi@necton2
parents:
diff changeset
256
goffi@necton2
parents:
diff changeset
257 def onSendFile(self, e):
70
Goffi <goffi@goffi.org>
parents: 67
diff changeset
258 debug(_("Send File"))
Goffi <goffi@goffi.org>
parents: 67
diff changeset
259 filename = wx.FileSelector(_("Choose a file to send"), flags = wx.FD_FILE_MUST_EXIST)
0
goffi@necton2
parents:
diff changeset
260 if filename:
70
Goffi <goffi@goffi.org>
parents: 67
diff changeset
261 debug(_("filename: %s"),filename)
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
262 full_jid = self.host.CM.get_full(self.target)
387
e66d300c5d42 frontends, bridge: sendFile method signature change + jid parameters in bridge now use _jid suffix
Goffi <goffi@goffi.org>
parents: 361
diff changeset
263 id = self.host.bridge.sendFile(full_jid, filename, {}, self.host.profile)
70
Goffi <goffi@goffi.org>
parents: 67
diff changeset
264 self.host.waitProgress(id, _("File Transfer"), _("Copying %s") % os.path.basename(filename))
0
goffi@necton2
parents:
diff changeset
265
85
fc7583282d40 Tarot Game plugin: first draft
Goffi <goffi@goffi.org>
parents: 80
diff changeset
266 def onStartTarot(self, e):
fc7583282d40 Tarot Game plugin: first draft
Goffi <goffi@goffi.org>
parents: 80
diff changeset
267 debug (_("Starting Tarot game"))
fc7583282d40 Tarot Game plugin: first draft
Goffi <goffi@goffi.org>
parents: 80
diff changeset
268 warning (_("FIXME: temporary menu, must be changed"))
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
269 if len(self.occupants) != 4:
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
270 err_dlg = wx.MessageDialog(self, _("You need to be exactly 4 peoples in the room to start a Tarot game"), _("Can't start game"), style = wx.OK | wx.ICON_ERROR) #FIXME: gof: temporary only, need to choose the people with who the game has to be started
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
271 err_dlg.ShowModal()
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
272 else:
90
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 87
diff changeset
273 self.host.bridge.tarotGameCreate(self.id, list(self.occupants), self.host.profile)