Mercurial > libervia-backend
changeset 1011:5a6354ff468c
wix: use of new logging system
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 05 May 2014 20:12:21 +0200 |
parents | 73a0b7f94674 |
children | c8771279497e |
files | frontends/src/wix/card_game.py frontends/src/wix/chat.py frontends/src/wix/constants.py frontends/src/wix/contact_list.py frontends/src/wix/main_window.py frontends/src/wix/profile.py frontends/src/wix/profile_manager.py frontends/src/wix/quiz_game.py frontends/src/wix/wix frontends/src/wix/xmlui.py |
diffstat | 10 files changed, 76 insertions(+), 80 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/src/wix/card_game.py Mon May 05 20:12:19 2014 +0200 +++ b/frontends/src/wix/card_game.py Mon May 05 20:12:21 2014 +0200 @@ -18,13 +18,11 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. - from sat.core.i18n import _ import wx import os.path, glob -import pdb -from logging import debug, info, error -from sat.tools.jid import JID +from sat.core.log import getLogger +log = getLogger(__name__) from sat_frontends.tools.games import TarotCard from sat_frontends.quick_frontend.quick_card_game import QuickCardGame from sat_frontends.wix.xmlui import XMLUI @@ -34,6 +32,7 @@ MIN_WIDTH = 950 #Minimum size of the panel MIN_HEIGHT = 500 + class WxCard(TarotCard): """This class is used to represent a card, graphically and logically""" @@ -43,7 +42,7 @@ root_name = os.path.splitext(os.path.basename(file))[0] suit,value = root_name.split('_') TarotCard.__init__(self, (suit, value)) - print "Carte:",suit, value #, self.bout + log.debug("Card: %s %s" % (suit, value)) #, self.bout def draw(self, dc, x, y): """Draw the card on the device context @@ -97,7 +96,7 @@ def contratSelected(self, data): """Called when the contrat has been choosed @param data: form result""" - debug (_("Contrat choosed")) + log.debug (_("Contrat choosed")) contrat = data[0][1] QuickCardGame.contratSelected(self, contrat) @@ -211,7 +210,7 @@ self.Refresh() def onMouseClick(self, event): - print "mouse click:",event.GetPosition() + log.debug("mouse click: %s" % event.GetPosition()) pos_x,pos_y = event.GetPosition() if self.state == "chien":
--- a/frontends/src/wix/chat.py Mon May 05 20:12:19 2014 +0200 +++ b/frontends/src/wix/chat.py Mon May 05 20:12:21 2014 +0200 @@ -18,23 +18,22 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. - from sat.core.i18n import _ import wx import os.path import time -import pdb -from logging import debug, info, error, warning +from sat.core.log import getLogger +log = getLogger(__name__) from sat.tools.jid import JID from sat_frontends.quick_frontend.quick_chat import QuickChat from sat_frontends.wix.contact_list import ContactList from sat_frontends.wix.card_game import CardPanel from sat_frontends.wix.quiz_game import QuizPanel - idSEND = 1 idTAROT = 2 + class Chat(wx.Frame, QuickChat): """The chat Window for one to one conversations""" @@ -111,14 +110,14 @@ def startGame(self, game_type, referee, players): """Configure the chat window to start a game""" if game_type=="Tarot": - debug (_("configure chat window for Tarot game")) + log.debug (_("configure chat window for Tarot game")) self.tarot_panel = CardPanel(self, referee, players, self.nick) self.sizer.Prepend(self.tarot_panel, 0, flag=wx.EXPAND) self.sizer.Layout() self.Fit() self.splitter.UpdateSize() elif game_type=="Quiz": - debug (_("configure chat window for Quiz game")) + log.debug (_("configure chat window for Quiz game")) self.quiz_panel = QuizPanel(self, referee, players, self.nick) self.sizer.Prepend(self.quiz_panel, 0, flag=wx.EXPAND) self.sizer.Layout() @@ -143,9 +142,9 @@ def replaceUser(self, nick, show_info=True): """Add user if it is not in the group list""" - debug (_("Replacing user %s") % nick) + log.debug (_("Replacing user %s") % nick) if self.type != "group": - error (_("[INTERNAL] trying to replace user for a non group chat window")) + log.error (_("[INTERNAL] trying to replace user for a non group chat window")) return QuickChat.replaceUser(self, nick, show_info) self.present_panel.presents.replace(nick) @@ -168,7 +167,7 @@ def __createMenus_O2O(self): """create menu bar for one 2 one chat""" - info("Creating menus") + log.info("Creating menus") self.__eraseMenus() menuBar = self.GetMenuBar() actionMenu = wx.Menu() @@ -180,7 +179,7 @@ def __createMenus_group(self): """create menu bar for group chat""" - info("Creating menus") + log.info("Creating menus") self.__eraseMenus() menuBar = self.GetMenuBar() actionMenu = wx.Menu() @@ -221,7 +220,7 @@ jid,nick,mymess = QuickChat.printMessage(self, from_jid, msg, profile, timestamp) except TypeError: return - print "printMessage, jid=",jid,"type=",self.type + log.debug("printMessage, jid = %s type = %s" % (jid, self.type)) _font_bold = wx.Font(self.font["points"], self.font["family"], wx.NORMAL, wx.BOLD) _font_normal = wx.Font(self.font["points"], self.font["family"], wx.NORMAL, wx.NORMAL) _font_italic = wx.Font(self.font["points"], self.font["family"], wx.ITALIC if mymess else wx.NORMAL, wx.NORMAL) @@ -253,10 +252,10 @@ ### events ### def onSendFile(self, e): - debug(_("Send File")) + log.debug(_("Send File")) filename = wx.FileSelector(_("Choose a file to send"), flags = wx.FD_FILE_MUST_EXIST) if filename: - debug(_("filename: %s"),filename) + log.debug(_("filename: %s"),filename) #FIXME: check last_resource: what if self.target.resource exists ? last_resource = self.host.bridge.getLastResource(unicode(self.target.bare), self.host.profile) if last_resource: @@ -267,8 +266,8 @@ self.host.waitProgress(id, _("File Transfer"), _("Copying %s") % os.path.basename(filename), self.host.profile) def onStartTarot(self, e): - debug(_("Starting Tarot game")) - warning(_("FIXME: temporary menu, must be changed")) + log.debug(_("Starting Tarot game")) + log.warning(_("FIXME: temporary menu, must be changed")) if len(self.occupants) != 4: 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 err_dlg.ShowModal()
--- a/frontends/src/wix/constants.py Mon May 05 20:12:19 2014 +0200 +++ b/frontends/src/wix/constants.py Mon May 05 20:12:21 2014 +0200 @@ -18,14 +18,11 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. from sat.core.i18n import _ -import sys import os.path -import gettext import sat_frontends.wix from sat_frontends.quick_frontend import constants -_ = gettext.gettext wix_root = os.path.dirname(sat_frontends.wix.__file__) @@ -42,4 +39,4 @@ ("dnd", _("DND"), "red"), ("xa", _("Away"), "red") ] - + LOG_OPT_SECTION = APP_NAME.lower()
--- a/frontends/src/wix/contact_list.py Mon May 05 20:12:19 2014 +0200 +++ b/frontends/src/wix/contact_list.py Mon May 05 20:12:21 2014 +0200 @@ -21,7 +21,8 @@ import wx from sat_frontends.quick_frontend.quick_contact_list import QuickContactList from sat_frontends.wix.constants import Const -from logging import debug, info, error +from sat.core.log import getLogger +log = getLogger(__name__) from cgi import escape from sat.tools.jid import JID from os.path import join @@ -41,7 +42,7 @@ @param parent: WxWidgets parent of the widget @param host: wix main app class @param type_: type of contact list: "JID" for the usual big jid contact list - "CUSTOM" for a customized contact list (self.__presentItem must then be overrided) + "CUSTOM" for a customized contact list (self._presentItem must then be overrided) """ wx.SimpleHtmlListBox.__init__(self, parent, -1) QuickContactList.__init__(self) @@ -58,9 +59,9 @@ def __typeSwitch(self): if self.type == "JID": - self.__presentItem = self.__presentItemJID - elif type_ != "CUSTOM": - self.__presentItem = self.__presentItemDefault + self._presentItem = self._presentItemJID + elif self.type != "CUSTOM": + self._presentItem = self._presentItemDefault def __find_idx(self, entity): """Find indexes of given contact (or groups) in contact list, manage jid @@ -84,12 +85,12 @@ XXX: None value for 'groups' has a different meaning than [None] which is for the default group. """ - debug(_("update %s") % contact) + log.debug(_("update %s") % contact) if not self.__find_idx(contact): self.add(contact, groups) else: for i in self.__find_idx(contact): - _present = self.__presentItem(contact) + _present = self._presentItem(contact) if _present != None: self.SetString(i, _present) @@ -106,17 +107,17 @@ return erased - def __presentGroup(self, group): + def _presentGroup(self, group): """Make a nice presentation for the contact groups""" html = u"""-- [%s] --""" % group return html - def __presentItemDefault(self, contact): + def _presentItemDefault(self, contact): """Make a basic presentation of string contacts in the list.""" return contact - def __presentItemJID(self, jid): + def _presentItemJID(self, jid): """Make a nice presentation of the contact in the list for JID contacts.""" name = self.getCache(jid,'name') nick = self.getCache(jid,'nick') @@ -158,9 +159,9 @@ def add(self, contact, groups = None): """add a contact to the list""" - debug (_("adding %s"),contact) + log.debug (_("adding %s"),contact) if not groups: - _present = self.__presentItem(contact) + _present = self._presentItem(contact) if _present: idx = self.Insert(_present, 0, contact) else: @@ -168,11 +169,11 @@ indexes = self.__find_idx(group) gp_idx = 0 if not indexes: #this is a new group, we have to create it - gp_idx = self.Append(self.__presentGroup(group), Group(group)) + gp_idx = self.Append(self._presentGroup(group), Group(group)) else: gp_idx = indexes[0] - _present = self.__presentItem(contact) + _present = self._presentItem(contact) if _present: self.Insert(_present, gp_idx+1, contact) @@ -197,7 +198,7 @@ def remove(self, contact): """remove a contact from the list""" - debug (_("removing %s"), contact) + log.debug (_("removing %s"), contact) list_idx = self.__find_idx(contact) list_idx.reverse() #as we make some deletions, we have to reverse the order for i in list_idx: @@ -215,7 +216,7 @@ contacts.sort() id_insert = self.GetSelection()+1 for contact in contacts: - _present = self.__presentItem(contact) + _present = self._presentItem(contact) if _present: self.Insert(_present, id_insert, contact) self.SetSelection(wx.NOT_FOUND)
--- a/frontends/src/wix/main_window.py Mon May 05 20:12:19 2014 +0200 +++ b/frontends/src/wix/main_window.py Mon May 05 20:12:21 2014 +0200 @@ -29,7 +29,8 @@ from sat_frontends.wix.profile_manager import ProfileManager import os.path from sat.tools.jid import JID -from logging import debug, info, warning, error +from sat.core.log import getLogger +log = getLogger(__name__) from sat_frontends.wix.constants import Const idCONNECT,\ @@ -104,7 +105,7 @@ def plug_profile(self, profile_key='@DEFAULT@'): """Hide profile panel then plug profile""" - debug (_('plugin profile %s' % profile_key)) + log.debug (_('plugin profile %s' % profile_key)) self.profile_pan.Hide() self.contact_list.Show() self.sizer.Layout() @@ -113,7 +114,7 @@ super(MainWindow, self).plug_profile(profile_key) def createMenus(self): - info(_("Creating menus")) + log.info(_("Creating menus")) connectMenu = wx.Menu() connectMenu.Append(idCONNECT, _("&Connect CTRL-c"),_(" Connect to the server")) connectMenu.Append(idDISCONNECT, _("&Disconnect CTRL-d"),_(" Disconnect from the server")) @@ -195,7 +196,7 @@ flags = wx.YES_NO | wx.ICON_QUESTION else: flags = wx.OK | wx.ICON_INFORMATION - error(_('unmanaged dialog type: %s'), type) + log.error(_('unmanaged dialog type: %s'), type) dlg = wx.MessageDialog(self, message, title, flags) answer = dlg.ShowModal() dlg.Destroy() @@ -236,7 +237,7 @@ # action was a one shot, nothing to do pass elif "xmlui" in data: - debug (_("XML user interface received")) + log.debug (_("XML user interface received")) XMLUI(self, xml_data = data['xmlui']) else: dlg = wx.MessageDialog(self, _(u"Unmanaged action result"), @@ -259,10 +260,10 @@ #TODO: refactor this in QuickApp if not self.check_profile(profile): return - debug (_("Confirmation asked")) + log.debug (_("Confirmation asked")) answer_data={} if confirmation_type == "FILE_TRANSFER": - debug (_("File transfer confirmation asked")) + log.debug (_("File transfer confirmation asked")) 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"]}, _('File Request'), wx.YES_NO | wx.ICON_QUESTION @@ -282,7 +283,7 @@ dlg.Destroy() elif confirmation_type == "YES/NO": - debug (_("Yes/No confirmation asked")) + log.debug (_("Yes/No confirmation asked")) dlg = wx.MessageDialog(self, data["message"], _('Confirmation'), wx.YES_NO | wx.ICON_QUESTION @@ -298,9 +299,9 @@ def actionResult(self, type, id, data, profile): if not self.check_profile(profile): return - debug (_("actionResult: type = [%(type)s] id = [%(id)s] data = [%(data)s]") % {'type':type, 'id':id, 'data':data}) + log.debug (_("actionResult: type = [%(type)s] id = [%(id)s] data = [%(data)s]") % {'type':type, 'id':id, 'data':data}) if not id in self.current_action_ids: - debug (_('unknown id, ignoring')) + log.debug (_('unknown id, ignoring')) return if type == "SUPPRESS": self.current_action_ids.remove(id) @@ -322,7 +323,7 @@ dlg.Destroy() elif type == "XMLUI": self.current_action_ids.remove(id) - debug (_("XML user interface received")) + log.debug (_("XML user interface received")) misc = {} #FIXME FIXME FIXME: must clean all this crap ! title = _('Form') @@ -344,7 +345,7 @@ del self.current_action_ids_cb[id] callback(data) else: - error (_("FIXME FIXME FIXME: type [%s] not implemented") % type) + log.error (_("FIXME FIXME FIXME: type [%s] not implemented") % type) raise NotImplementedError @@ -374,7 +375,7 @@ ### events ### def onContactActivated(self, jid): - debug (_("onContactActivated: %s"), jid) + log.debug (_("onContactActivated: %s"), jid) if self.chat_wins[jid.bare].IsShown(): self.chat_wins[jid.bare].Hide() else: @@ -392,11 +393,11 @@ self.bridge.setPresence(show=show, statuses={'default': status}, profile_key=self.profile) #FIXME: manage multilingual statuses def onStatusChange(self, e): - debug(_("Status change request")) + log.debug(_("Status change request")) self.__updateStatus() def onParam(self, e): - debug(_("Param request")) + log.debug(_("Param request")) def success(params): XMLUI(self, xml_data=params, title=_("Configuration")) @@ -430,7 +431,7 @@ self.Close() def onShowProfile(self, e): - debug(_("Show contact's profile request")) + log.debug(_("Show contact's profile request")) target = self.contact_list.getSelection() if not target: dlg = wx.MessageDialog(self, _("You haven't selected any contact !"), @@ -446,11 +447,11 @@ def onProfileReceived(self, data): """Called when a profile is received""" - debug (_('Profile received: [%s]') % data) + log.debug (_('Profile received: [%s]') % data) Profile(self, data) def onJoinRoom(self, e): - warning('FIXME: temporary menu, must be improved') + log.warning('FIXME: temporary menu, must be improved') #TODO: a proper MUC room joining dialog with nickname etc dlg = wx.TextEntryDialog( self, _("Please enter MUC's JID"), @@ -461,18 +462,18 @@ if room_jid.is_valid(): self.bridge.joinMUC(room_jid, self.profiles[self.profile]['whoami'].node, {}, self.profile) else: - error (_("'%s' is an invalid JID !"), room_jid) + log.error (_("'%s' is an invalid JID !"), room_jid) def onClose(self, e): QuickApp.onExit(self) - info(_("Exiting...")) + log.info(_("Exiting...")) for win in self.chat_wins: self.chat_wins[win].Destroy() self.tray_icon.Destroy() e.Skip() def onTrayClick(self, e): - debug(_("Tray Click")) + log.debug(_("Tray Click")) if self.IsShown(): self.Hide() else:
--- a/frontends/src/wix/profile.py Mon May 05 20:12:19 2014 +0200 +++ b/frontends/src/wix/profile.py Mon May 05 20:12:21 2014 +0200 @@ -20,7 +20,8 @@ from sat.core.i18n import _ import wx import pdb -from logging import debug, info, error +from sat.core.log import getLogger +log = getLogger(__name__) from sat.tools.jid import JID @@ -85,7 +86,7 @@ def onClose(self, event): """Close event""" - debug(_("close")) + log.debug(_("close")) self.MakeModal(False) event.Skip()
--- a/frontends/src/wix/profile_manager.py Mon May 05 20:12:19 2014 +0200 +++ b/frontends/src/wix/profile_manager.py Mon May 05 20:12:21 2014 +0200 @@ -21,7 +21,8 @@ from sat.core.i18n import _ import wx -from logging import debug, info, error +from sat.core.log import getLogger +log = getLogger(__name__) from sat.tools.jid import JID @@ -145,11 +146,11 @@ new_jid = self.login_jid.GetValue() new_pass = self.login_pass.GetValue() if old_jid != new_jid: - debug(_('Saving new JID and server')) + log.debug(_('Saving new JID and server')) self.host.bridge.setParam("JabberID", new_jid, "Connection", profile_key=profile) self.host.bridge.setParam("Server", JID(new_jid).domain, "Connection", profile_key=profile) if old_pass != new_pass: - debug(_('Saving new password')) + log.debug(_('Saving new password')) self.host.bridge.setParam("Password", new_pass, "Connection", profile_key=profile) self.host.plug_profile(profile)
--- a/frontends/src/wix/quiz_game.py Mon May 05 20:12:19 2014 +0200 +++ b/frontends/src/wix/quiz_game.py Mon May 05 20:12:21 2014 +0200 @@ -23,7 +23,8 @@ import wx import os.path, glob import pdb -from logging import debug, info, error +from sat.core.log import getLogger +log = getLogger(__name__) from sat.tools.jid import JID from time import time from math import sin, cos, pi
--- a/frontends/src/wix/wix Mon May 05 20:12:19 2014 +0200 +++ b/frontends/src/wix/wix Mon May 05 20:12:21 2014 +0200 @@ -18,17 +18,12 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. +from sat_frontends.wix.constants import Const as C +from sat.core import log +log.satConfigure(C.LOG_BACKEND_STANDARD, C) import wx -from sat_frontends.bridge.DBus import DBusBridgeFrontend -import logging -from logging import debug, info, error from sat_frontends.wix.main_window import MainWindow -### logging configuration FIXME: put this elsewhere ### -logging.basicConfig(level=logging.DEBUG, - format='%(message)s') -### - class SATApp(wx.App): def __init__(self, redirect=False, filename=None, useBestVisual=False, clearSigInt=True):
--- a/frontends/src/wix/xmlui.py Mon May 05 20:12:19 2014 +0200 +++ b/frontends/src/wix/xmlui.py Mon May 05 20:12:21 2014 +0200 @@ -21,7 +21,8 @@ from sat.core.i18n import _ import wx -from logging import debug, info, warning, error +from sat.core.log import getLogger +log = getLogger(__name__) from sat.tools.jid import JID from sat_frontends.tools import xmlui from sat_frontends.constants import Const @@ -144,7 +145,7 @@ try: label = [label for label, _value in self._xmlui_attr_map.items() if _value == value][0] except IndexError: - warning(_("Can't find value [%s] to select" % value)) + log.warning(_("Can't find value [%s] to select" % value)) return for idx in xrange(self.GetCount()): self.SetSelection(idx, self.GetString(idx) == label) @@ -320,7 +321,7 @@ def onClose(self, event): """Close event: we have to send the form.""" - debug(_("close")) + log.debug(_("close")) if self.type == 'param': self.onSaveParams() else: