Mercurial > libervia-backend
comparison frontends/src/wix/chat.py @ 1011:5a6354ff468c
wix: use of new logging system
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 05 May 2014 20:12:21 +0200 |
parents | cd02f5ef30df |
children | 11e2bb20e896 |
comparison
equal
deleted
inserted
replaced
1010:73a0b7f94674 | 1011:5a6354ff468c |
---|---|
16 | 16 |
17 # You should have received a copy of the GNU Affero General Public License | 17 # You should have received a copy of the GNU Affero General Public License |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 | 20 |
21 | |
22 from sat.core.i18n import _ | 21 from sat.core.i18n import _ |
23 import wx | 22 import wx |
24 import os.path | 23 import os.path |
25 import time | 24 import time |
26 import pdb | 25 from sat.core.log import getLogger |
27 from logging import debug, info, error, warning | 26 log = getLogger(__name__) |
28 from sat.tools.jid import JID | 27 from sat.tools.jid import JID |
29 from sat_frontends.quick_frontend.quick_chat import QuickChat | 28 from sat_frontends.quick_frontend.quick_chat import QuickChat |
30 from sat_frontends.wix.contact_list import ContactList | 29 from sat_frontends.wix.contact_list import ContactList |
31 from sat_frontends.wix.card_game import CardPanel | 30 from sat_frontends.wix.card_game import CardPanel |
32 from sat_frontends.wix.quiz_game import QuizPanel | 31 from sat_frontends.wix.quiz_game import QuizPanel |
33 | 32 |
34 | |
35 idSEND = 1 | 33 idSEND = 1 |
36 idTAROT = 2 | 34 idTAROT = 2 |
35 | |
37 | 36 |
38 class Chat(wx.Frame, QuickChat): | 37 class Chat(wx.Frame, QuickChat): |
39 """The chat Window for one to one conversations""" | 38 """The chat Window for one to one conversations""" |
40 | 39 |
41 def __init__(self, target, host, type_='one2one'): | 40 def __init__(self, target, host, type_='one2one'): |
109 self.historyPrint(profile=self.host.profile) | 108 self.historyPrint(profile=self.host.profile) |
110 | 109 |
111 def startGame(self, game_type, referee, players): | 110 def startGame(self, game_type, referee, players): |
112 """Configure the chat window to start a game""" | 111 """Configure the chat window to start a game""" |
113 if game_type=="Tarot": | 112 if game_type=="Tarot": |
114 debug (_("configure chat window for Tarot game")) | 113 log.debug (_("configure chat window for Tarot game")) |
115 self.tarot_panel = CardPanel(self, referee, players, self.nick) | 114 self.tarot_panel = CardPanel(self, referee, players, self.nick) |
116 self.sizer.Prepend(self.tarot_panel, 0, flag=wx.EXPAND) | 115 self.sizer.Prepend(self.tarot_panel, 0, flag=wx.EXPAND) |
117 self.sizer.Layout() | 116 self.sizer.Layout() |
118 self.Fit() | 117 self.Fit() |
119 self.splitter.UpdateSize() | 118 self.splitter.UpdateSize() |
120 elif game_type=="Quiz": | 119 elif game_type=="Quiz": |
121 debug (_("configure chat window for Quiz game")) | 120 log.debug (_("configure chat window for Quiz game")) |
122 self.quiz_panel = QuizPanel(self, referee, players, self.nick) | 121 self.quiz_panel = QuizPanel(self, referee, players, self.nick) |
123 self.sizer.Prepend(self.quiz_panel, 0, flag=wx.EXPAND) | 122 self.sizer.Prepend(self.quiz_panel, 0, flag=wx.EXPAND) |
124 self.sizer.Layout() | 123 self.sizer.Layout() |
125 self.Fit() | 124 self.Fit() |
126 self.splitter.UpdateSize() | 125 self.splitter.UpdateSize() |
141 for nick in nicks: | 140 for nick in nicks: |
142 self.present_panel.presents.replace(nick) | 141 self.present_panel.presents.replace(nick) |
143 | 142 |
144 def replaceUser(self, nick, show_info=True): | 143 def replaceUser(self, nick, show_info=True): |
145 """Add user if it is not in the group list""" | 144 """Add user if it is not in the group list""" |
146 debug (_("Replacing user %s") % nick) | 145 log.debug (_("Replacing user %s") % nick) |
147 if self.type != "group": | 146 if self.type != "group": |
148 error (_("[INTERNAL] trying to replace user for a non group chat window")) | 147 log.error (_("[INTERNAL] trying to replace user for a non group chat window")) |
149 return | 148 return |
150 QuickChat.replaceUser(self, nick, show_info) | 149 QuickChat.replaceUser(self, nick, show_info) |
151 self.present_panel.presents.replace(nick) | 150 self.present_panel.presents.replace(nick) |
152 | 151 |
153 def removeUser(self, nick, show_info=True): | 152 def removeUser(self, nick, show_info=True): |
166 for i in range(menuBar.GetMenuCount()): | 165 for i in range(menuBar.GetMenuCount()): |
167 menuBar.Remove(i) | 166 menuBar.Remove(i) |
168 | 167 |
169 def __createMenus_O2O(self): | 168 def __createMenus_O2O(self): |
170 """create menu bar for one 2 one chat""" | 169 """create menu bar for one 2 one chat""" |
171 info("Creating menus") | 170 log.info("Creating menus") |
172 self.__eraseMenus() | 171 self.__eraseMenus() |
173 menuBar = self.GetMenuBar() | 172 menuBar = self.GetMenuBar() |
174 actionMenu = wx.Menu() | 173 actionMenu = wx.Menu() |
175 actionMenu.Append(idSEND, _("&SendFile CTRL-s"),_(" Send a file to contact")) | 174 actionMenu.Append(idSEND, _("&SendFile CTRL-s"),_(" Send a file to contact")) |
176 menuBar.Append(actionMenu,_("&Action")) | 175 menuBar.Append(actionMenu,_("&Action")) |
178 #events | 177 #events |
179 wx.EVT_MENU(self, idSEND, self.onSendFile) | 178 wx.EVT_MENU(self, idSEND, self.onSendFile) |
180 | 179 |
181 def __createMenus_group(self): | 180 def __createMenus_group(self): |
182 """create menu bar for group chat""" | 181 """create menu bar for group chat""" |
183 info("Creating menus") | 182 log.info("Creating menus") |
184 self.__eraseMenus() | 183 self.__eraseMenus() |
185 menuBar = self.GetMenuBar() | 184 menuBar = self.GetMenuBar() |
186 actionMenu = wx.Menu() | 185 actionMenu = wx.Menu() |
187 actionMenu.Append(idTAROT, _("Start &Tarot game CTRL-t"),_(" Start a Tarot card game")) #tmp | 186 actionMenu.Append(idTAROT, _("Start &Tarot game CTRL-t"),_(" Start a Tarot card game")) #tmp |
188 menuBar.Append(actionMenu,_("&Games")) | 187 menuBar.Append(actionMenu,_("&Games")) |
219 """Print the message with differents colors depending on where it comes from.""" | 218 """Print the message with differents colors depending on where it comes from.""" |
220 try: | 219 try: |
221 jid,nick,mymess = QuickChat.printMessage(self, from_jid, msg, profile, timestamp) | 220 jid,nick,mymess = QuickChat.printMessage(self, from_jid, msg, profile, timestamp) |
222 except TypeError: | 221 except TypeError: |
223 return | 222 return |
224 print "printMessage, jid=",jid,"type=",self.type | 223 log.debug("printMessage, jid = %s type = %s" % (jid, self.type)) |
225 _font_bold = wx.Font(self.font["points"], self.font["family"], wx.NORMAL, wx.BOLD) | 224 _font_bold = wx.Font(self.font["points"], self.font["family"], wx.NORMAL, wx.BOLD) |
226 _font_normal = wx.Font(self.font["points"], self.font["family"], wx.NORMAL, wx.NORMAL) | 225 _font_normal = wx.Font(self.font["points"], self.font["family"], wx.NORMAL, wx.NORMAL) |
227 _font_italic = wx.Font(self.font["points"], self.font["family"], wx.ITALIC if mymess else wx.NORMAL, wx.NORMAL) | 226 _font_italic = wx.Font(self.font["points"], self.font["family"], wx.ITALIC if mymess else wx.NORMAL, wx.NORMAL) |
228 self.chatWindow.SetDefaultStyle(wx.TextAttr("GREY", font=_font_normal)) | 227 self.chatWindow.SetDefaultStyle(wx.TextAttr("GREY", font=_font_normal)) |
229 msg_time = time.localtime(timestamp or None) | 228 msg_time = time.localtime(timestamp or None) |
251 self.__blink() | 250 self.__blink() |
252 | 251 |
253 ### events ### | 252 ### events ### |
254 | 253 |
255 def onSendFile(self, e): | 254 def onSendFile(self, e): |
256 debug(_("Send File")) | 255 log.debug(_("Send File")) |
257 filename = wx.FileSelector(_("Choose a file to send"), flags = wx.FD_FILE_MUST_EXIST) | 256 filename = wx.FileSelector(_("Choose a file to send"), flags = wx.FD_FILE_MUST_EXIST) |
258 if filename: | 257 if filename: |
259 debug(_("filename: %s"),filename) | 258 log.debug(_("filename: %s"),filename) |
260 #FIXME: check last_resource: what if self.target.resource exists ? | 259 #FIXME: check last_resource: what if self.target.resource exists ? |
261 last_resource = self.host.bridge.getLastResource(unicode(self.target.bare), self.host.profile) | 260 last_resource = self.host.bridge.getLastResource(unicode(self.target.bare), self.host.profile) |
262 if last_resource: | 261 if last_resource: |
263 full_jid = JID("%s/%s" % (self.target.bare, last_resource)) | 262 full_jid = JID("%s/%s" % (self.target.bare, last_resource)) |
264 else: | 263 else: |
265 full_jid = self.target | 264 full_jid = self.target |
266 id = self.host.bridge.sendFile(full_jid, filename, {}, self.host.profile) | 265 id = self.host.bridge.sendFile(full_jid, filename, {}, self.host.profile) |
267 self.host.waitProgress(id, _("File Transfer"), _("Copying %s") % os.path.basename(filename), self.host.profile) | 266 self.host.waitProgress(id, _("File Transfer"), _("Copying %s") % os.path.basename(filename), self.host.profile) |
268 | 267 |
269 def onStartTarot(self, e): | 268 def onStartTarot(self, e): |
270 debug(_("Starting Tarot game")) | 269 log.debug(_("Starting Tarot game")) |
271 warning(_("FIXME: temporary menu, must be changed")) | 270 log.warning(_("FIXME: temporary menu, must be changed")) |
272 if len(self.occupants) != 4: | 271 if len(self.occupants) != 4: |
273 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 | 272 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 |
274 err_dlg.ShowModal() | 273 err_dlg.ShowModal() |
275 else: | 274 else: |
276 self.host.bridge.tarotGameCreate(self.id, list(self.occupants), self.host.profile) | 275 self.host.bridge.tarotGameCreate(self.id, list(self.occupants), self.host.profile) |