Mercurial > libervia-backend
comparison frontends/src/wix/main_window.py @ 1011:5a6354ff468c
wix: use of new logging system
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 05 May 2014 20:12:21 +0200 |
parents | 3a96920c07b7 |
children | c4c14480715a |
comparison
equal
deleted
inserted
replaced
1010:73a0b7f94674 | 1011:5a6354ff468c |
---|---|
27 from sat_frontends.wix.xmlui import XMLUI | 27 from sat_frontends.wix.xmlui import XMLUI |
28 from sat_frontends.wix.profile import Profile | 28 from sat_frontends.wix.profile import Profile |
29 from sat_frontends.wix.profile_manager import ProfileManager | 29 from sat_frontends.wix.profile_manager import ProfileManager |
30 import os.path | 30 import os.path |
31 from sat.tools.jid import JID | 31 from sat.tools.jid import JID |
32 from logging import debug, info, warning, error | 32 from sat.core.log import getLogger |
33 log = getLogger(__name__) | |
33 from sat_frontends.wix.constants import Const | 34 from sat_frontends.wix.constants import Const |
34 | 35 |
35 idCONNECT,\ | 36 idCONNECT,\ |
36 idDISCONNECT,\ | 37 idDISCONNECT,\ |
37 idEXIT,\ | 38 idEXIT,\ |
102 | 103 |
103 self.Show() | 104 self.Show() |
104 | 105 |
105 def plug_profile(self, profile_key='@DEFAULT@'): | 106 def plug_profile(self, profile_key='@DEFAULT@'): |
106 """Hide profile panel then plug profile""" | 107 """Hide profile panel then plug profile""" |
107 debug (_('plugin profile %s' % profile_key)) | 108 log.debug (_('plugin profile %s' % profile_key)) |
108 self.profile_pan.Hide() | 109 self.profile_pan.Hide() |
109 self.contact_list.Show() | 110 self.contact_list.Show() |
110 self.sizer.Layout() | 111 self.sizer.Layout() |
111 for i in range(self.menuBar.GetMenuCount()): | 112 for i in range(self.menuBar.GetMenuCount()): |
112 self.menuBar.EnableTop(i, True) | 113 self.menuBar.EnableTop(i, True) |
113 super(MainWindow, self).plug_profile(profile_key) | 114 super(MainWindow, self).plug_profile(profile_key) |
114 | 115 |
115 def createMenus(self): | 116 def createMenus(self): |
116 info(_("Creating menus")) | 117 log.info(_("Creating menus")) |
117 connectMenu = wx.Menu() | 118 connectMenu = wx.Menu() |
118 connectMenu.Append(idCONNECT, _("&Connect CTRL-c"),_(" Connect to the server")) | 119 connectMenu.Append(idCONNECT, _("&Connect CTRL-c"),_(" Connect to the server")) |
119 connectMenu.Append(idDISCONNECT, _("&Disconnect CTRL-d"),_(" Disconnect from the server")) | 120 connectMenu.Append(idDISCONNECT, _("&Disconnect CTRL-d"),_(" Disconnect from the server")) |
120 connectMenu.Append(idPARAM,_("&Parameters"),_(" Configure the program")) | 121 connectMenu.Append(idPARAM,_("&Parameters"),_(" Configure the program")) |
121 connectMenu.AppendSeparator() | 122 connectMenu.AppendSeparator() |
193 flags = wx.OK | wx.ICON_ERROR | 194 flags = wx.OK | wx.ICON_ERROR |
194 elif type == 'yes/no': | 195 elif type == 'yes/no': |
195 flags = wx.YES_NO | wx.ICON_QUESTION | 196 flags = wx.YES_NO | wx.ICON_QUESTION |
196 else: | 197 else: |
197 flags = wx.OK | wx.ICON_INFORMATION | 198 flags = wx.OK | wx.ICON_INFORMATION |
198 error(_('unmanaged dialog type: %s'), type) | 199 log.error(_('unmanaged dialog type: %s'), type) |
199 dlg = wx.MessageDialog(self, message, title, flags) | 200 dlg = wx.MessageDialog(self, message, title, flags) |
200 answer = dlg.ShowModal() | 201 answer = dlg.ShowModal() |
201 dlg.Destroy() | 202 dlg.Destroy() |
202 if answer_cb: | 203 if answer_cb: |
203 data = [answer_data] if answer_data else [] | 204 data = [answer_data] if answer_data else [] |
234 def action_cb(data): | 235 def action_cb(data): |
235 if not data: | 236 if not data: |
236 # action was a one shot, nothing to do | 237 # action was a one shot, nothing to do |
237 pass | 238 pass |
238 elif "xmlui" in data: | 239 elif "xmlui" in data: |
239 debug (_("XML user interface received")) | 240 log.debug (_("XML user interface received")) |
240 XMLUI(self, xml_data = data['xmlui']) | 241 XMLUI(self, xml_data = data['xmlui']) |
241 else: | 242 else: |
242 dlg = wx.MessageDialog(self, _(u"Unmanaged action result"), | 243 dlg = wx.MessageDialog(self, _(u"Unmanaged action result"), |
243 _('Error'), | 244 _('Error'), |
244 wx.OK | wx.ICON_ERROR | 245 wx.OK | wx.ICON_ERROR |
257 | 258 |
258 def askConfirmation(self, confirmation_id, confirmation_type, data, profile): | 259 def askConfirmation(self, confirmation_id, confirmation_type, data, profile): |
259 #TODO: refactor this in QuickApp | 260 #TODO: refactor this in QuickApp |
260 if not self.check_profile(profile): | 261 if not self.check_profile(profile): |
261 return | 262 return |
262 debug (_("Confirmation asked")) | 263 log.debug (_("Confirmation asked")) |
263 answer_data={} | 264 answer_data={} |
264 if confirmation_type == "FILE_TRANSFER": | 265 if confirmation_type == "FILE_TRANSFER": |
265 debug (_("File transfer confirmation asked")) | 266 log.debug (_("File transfer confirmation asked")) |
266 dlg = wx.MessageDialog(self, _("The contact %(jid)s wants to send you the file %(filename)s\nDo you accept ?") % {'jid':data["from"], 'filename':data["filename"]}, | 267 dlg = wx.MessageDialog(self, _("The contact %(jid)s wants to send you the file %(filename)s\nDo you accept ?") % {'jid':data["from"], 'filename':data["filename"]}, |
267 _('File Request'), | 268 _('File Request'), |
268 wx.YES_NO | wx.ICON_QUESTION | 269 wx.YES_NO | wx.ICON_QUESTION |
269 ) | 270 ) |
270 answer=dlg.ShowModal() | 271 answer=dlg.ShowModal() |
280 self.bridge.confirmationAnswer(confirmation_id, False, answer_data, profile) | 281 self.bridge.confirmationAnswer(confirmation_id, False, answer_data, profile) |
281 | 282 |
282 dlg.Destroy() | 283 dlg.Destroy() |
283 | 284 |
284 elif confirmation_type == "YES/NO": | 285 elif confirmation_type == "YES/NO": |
285 debug (_("Yes/No confirmation asked")) | 286 log.debug (_("Yes/No confirmation asked")) |
286 dlg = wx.MessageDialog(self, data["message"], | 287 dlg = wx.MessageDialog(self, data["message"], |
287 _('Confirmation'), | 288 _('Confirmation'), |
288 wx.YES_NO | wx.ICON_QUESTION | 289 wx.YES_NO | wx.ICON_QUESTION |
289 ) | 290 ) |
290 answer=dlg.ShowModal() | 291 answer=dlg.ShowModal() |
296 dlg.Destroy() | 297 dlg.Destroy() |
297 | 298 |
298 def actionResult(self, type, id, data, profile): | 299 def actionResult(self, type, id, data, profile): |
299 if not self.check_profile(profile): | 300 if not self.check_profile(profile): |
300 return | 301 return |
301 debug (_("actionResult: type = [%(type)s] id = [%(id)s] data = [%(data)s]") % {'type':type, 'id':id, 'data':data}) | 302 log.debug (_("actionResult: type = [%(type)s] id = [%(id)s] data = [%(data)s]") % {'type':type, 'id':id, 'data':data}) |
302 if not id in self.current_action_ids: | 303 if not id in self.current_action_ids: |
303 debug (_('unknown id, ignoring')) | 304 log.debug (_('unknown id, ignoring')) |
304 return | 305 return |
305 if type == "SUPPRESS": | 306 if type == "SUPPRESS": |
306 self.current_action_ids.remove(id) | 307 self.current_action_ids.remove(id) |
307 elif type == "SUCCESS": | 308 elif type == "SUCCESS": |
308 self.current_action_ids.remove(id) | 309 self.current_action_ids.remove(id) |
320 ) | 321 ) |
321 dlg.ShowModal() | 322 dlg.ShowModal() |
322 dlg.Destroy() | 323 dlg.Destroy() |
323 elif type == "XMLUI": | 324 elif type == "XMLUI": |
324 self.current_action_ids.remove(id) | 325 self.current_action_ids.remove(id) |
325 debug (_("XML user interface received")) | 326 log.debug (_("XML user interface received")) |
326 misc = {} | 327 misc = {} |
327 #FIXME FIXME FIXME: must clean all this crap ! | 328 #FIXME FIXME FIXME: must clean all this crap ! |
328 title = _('Form') | 329 title = _('Form') |
329 if data['type'] == _('registration'): | 330 if data['type'] == _('registration'): |
330 title = _('Registration') | 331 title = _('Registration') |
342 if self.current_action_ids_cb.has_key(id): | 343 if self.current_action_ids_cb.has_key(id): |
343 callback = self.current_action_ids_cb[id] | 344 callback = self.current_action_ids_cb[id] |
344 del self.current_action_ids_cb[id] | 345 del self.current_action_ids_cb[id] |
345 callback(data) | 346 callback(data) |
346 else: | 347 else: |
347 error (_("FIXME FIXME FIXME: type [%s] not implemented") % type) | 348 log.error (_("FIXME FIXME FIXME: type [%s] not implemented") % type) |
348 raise NotImplementedError | 349 raise NotImplementedError |
349 | 350 |
350 | 351 |
351 | 352 |
352 def progressCB(self, progress_id, title, message, profile): | 353 def progressCB(self, progress_id, title, message, profile): |
372 | 373 |
373 | 374 |
374 ### events ### | 375 ### events ### |
375 | 376 |
376 def onContactActivated(self, jid): | 377 def onContactActivated(self, jid): |
377 debug (_("onContactActivated: %s"), jid) | 378 log.debug (_("onContactActivated: %s"), jid) |
378 if self.chat_wins[jid.bare].IsShown(): | 379 if self.chat_wins[jid.bare].IsShown(): |
379 self.chat_wins[jid.bare].Hide() | 380 self.chat_wins[jid.bare].Hide() |
380 else: | 381 else: |
381 self.chat_wins[jid.bare].Show() | 382 self.chat_wins[jid.bare].Show() |
382 | 383 |
390 show = [x for x in Const.PRESENCE if x[1] == self.statusBox.GetValue()][0][0] | 391 show = [x for x in Const.PRESENCE if x[1] == self.statusBox.GetValue()][0][0] |
391 status = self.statusTxt.GetValue() | 392 status = self.statusTxt.GetValue() |
392 self.bridge.setPresence(show=show, statuses={'default': status}, profile_key=self.profile) #FIXME: manage multilingual statuses | 393 self.bridge.setPresence(show=show, statuses={'default': status}, profile_key=self.profile) #FIXME: manage multilingual statuses |
393 | 394 |
394 def onStatusChange(self, e): | 395 def onStatusChange(self, e): |
395 debug(_("Status change request")) | 396 log.debug(_("Status change request")) |
396 self.__updateStatus() | 397 self.__updateStatus() |
397 | 398 |
398 def onParam(self, e): | 399 def onParam(self, e): |
399 debug(_("Param request")) | 400 log.debug(_("Param request")) |
400 def success(params): | 401 def success(params): |
401 XMLUI(self, xml_data=params, title=_("Configuration")) | 402 XMLUI(self, xml_data=params, title=_("Configuration")) |
402 | 403 |
403 def failure(error): | 404 def failure(error): |
404 dlg = wx.MessageDialog(self, unicode(error), | 405 dlg = wx.MessageDialog(self, unicode(error), |
428 | 429 |
429 def onExit(self, e): | 430 def onExit(self, e): |
430 self.Close() | 431 self.Close() |
431 | 432 |
432 def onShowProfile(self, e): | 433 def onShowProfile(self, e): |
433 debug(_("Show contact's profile request")) | 434 log.debug(_("Show contact's profile request")) |
434 target = self.contact_list.getSelection() | 435 target = self.contact_list.getSelection() |
435 if not target: | 436 if not target: |
436 dlg = wx.MessageDialog(self, _("You haven't selected any contact !"), | 437 dlg = wx.MessageDialog(self, _("You haven't selected any contact !"), |
437 _('Error'), | 438 _('Error'), |
438 wx.OK | wx.ICON_ERROR | 439 wx.OK | wx.ICON_ERROR |
444 self.current_action_ids.add(_id) | 445 self.current_action_ids.add(_id) |
445 self.current_action_ids_cb[_id] = self.onProfileReceived | 446 self.current_action_ids_cb[_id] = self.onProfileReceived |
446 | 447 |
447 def onProfileReceived(self, data): | 448 def onProfileReceived(self, data): |
448 """Called when a profile is received""" | 449 """Called when a profile is received""" |
449 debug (_('Profile received: [%s]') % data) | 450 log.debug (_('Profile received: [%s]') % data) |
450 Profile(self, data) | 451 Profile(self, data) |
451 | 452 |
452 def onJoinRoom(self, e): | 453 def onJoinRoom(self, e): |
453 warning('FIXME: temporary menu, must be improved') | 454 log.warning('FIXME: temporary menu, must be improved') |
454 #TODO: a proper MUC room joining dialog with nickname etc | 455 #TODO: a proper MUC room joining dialog with nickname etc |
455 dlg = wx.TextEntryDialog( | 456 dlg = wx.TextEntryDialog( |
456 self, _("Please enter MUC's JID"), | 457 self, _("Please enter MUC's JID"), |
457 #_('Entering a MUC room'), 'test@conference.necton2.int') | 458 #_('Entering a MUC room'), 'test@conference.necton2.int') |
458 _('Entering a MUC room'), 'room@muc_service.server.tld') | 459 _('Entering a MUC room'), 'room@muc_service.server.tld') |
459 if dlg.ShowModal() == wx.ID_OK: | 460 if dlg.ShowModal() == wx.ID_OK: |
460 room_jid=JID(dlg.GetValue()) | 461 room_jid=JID(dlg.GetValue()) |
461 if room_jid.is_valid(): | 462 if room_jid.is_valid(): |
462 self.bridge.joinMUC(room_jid, self.profiles[self.profile]['whoami'].node, {}, self.profile) | 463 self.bridge.joinMUC(room_jid, self.profiles[self.profile]['whoami'].node, {}, self.profile) |
463 else: | 464 else: |
464 error (_("'%s' is an invalid JID !"), room_jid) | 465 log.error (_("'%s' is an invalid JID !"), room_jid) |
465 | 466 |
466 def onClose(self, e): | 467 def onClose(self, e): |
467 QuickApp.onExit(self) | 468 QuickApp.onExit(self) |
468 info(_("Exiting...")) | 469 log.info(_("Exiting...")) |
469 for win in self.chat_wins: | 470 for win in self.chat_wins: |
470 self.chat_wins[win].Destroy() | 471 self.chat_wins[win].Destroy() |
471 self.tray_icon.Destroy() | 472 self.tray_icon.Destroy() |
472 e.Skip() | 473 e.Skip() |
473 | 474 |
474 def onTrayClick(self, e): | 475 def onTrayClick(self, e): |
475 debug(_("Tray Click")) | 476 log.debug(_("Tray Click")) |
476 if self.IsShown(): | 477 if self.IsShown(): |
477 self.Hide() | 478 self.Hide() |
478 else: | 479 else: |
479 self.Show() | 480 self.Show() |
480 self.Raise() | 481 self.Raise() |