wix: use of new logging system

This commit is contained in:
Goffi 2014-05-05 20:12:21 +02:00
commit 2fddb02872
10 changed files with 76 additions and 80 deletions

View file

@ -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 @@ CARD_HEIGHT = 136
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 @@ class WxCard(TarotCard):
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 @@ class CardPanel(QuickCardGame, wx.Panel):
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 @@ class CardPanel(QuickCardGame, wx.Panel):
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":

View file

@ -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 @@ class Chat(wx.Frame, QuickChat):
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 @@ class Chat(wx.Frame, QuickChat):
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 @@ class Chat(wx.Frame, QuickChat):
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 @@ class Chat(wx.Frame, QuickChat):
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 @@ class Chat(wx.Frame, QuickChat):
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 @@ class Chat(wx.Frame, QuickChat):
### 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 @@ class Chat(wx.Frame, QuickChat):
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()

View file

@ -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 @@ class Const(constants.Const):
("dnd", _("DND"), "red"),
("xa", _("Away"), "red")
]
LOG_OPT_SECTION = APP_NAME.lower()

View file

@ -21,7 +21,8 @@ from sat.core.i18n import _
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 @@ class ContactList(wx.SimpleHtmlListBox, QuickContactList):
@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 @@ class ContactList(wx.SimpleHtmlListBox, QuickContactList):
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 @@ class ContactList(wx.SimpleHtmlListBox, QuickContactList):
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 @@ class ContactList(wx.SimpleHtmlListBox, QuickContactList):
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 @@ class ContactList(wx.SimpleHtmlListBox, QuickContactList):
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 @@ class ContactList(wx.SimpleHtmlListBox, QuickContactList):
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 @@ class ContactList(wx.SimpleHtmlListBox, QuickContactList):
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 @@ class ContactList(wx.SimpleHtmlListBox, QuickContactList):
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)

View file

@ -29,7 +29,8 @@ from sat_frontends.wix.profile import Profile
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 @@ class MainWindow(wx.Frame, QuickApp):
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 @@ class MainWindow(wx.Frame, QuickApp):
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 @@ class MainWindow(wx.Frame, QuickApp):
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 @@ class MainWindow(wx.Frame, QuickApp):
# 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 @@ class MainWindow(wx.Frame, QuickApp):
#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 @@ class MainWindow(wx.Frame, QuickApp):
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 @@ class MainWindow(wx.Frame, QuickApp):
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 @@ class MainWindow(wx.Frame, QuickApp):
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 @@ class MainWindow(wx.Frame, QuickApp):
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 @@ class MainWindow(wx.Frame, QuickApp):
### 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 @@ class MainWindow(wx.Frame, QuickApp):
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 @@ class MainWindow(wx.Frame, QuickApp):
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 @@ class MainWindow(wx.Frame, QuickApp):
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 @@ class MainWindow(wx.Frame, QuickApp):
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:

View file

@ -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 @@ class Profile(wx.Frame):
def onClose(self, event):
"""Close event"""
debug(_("close"))
log.debug(_("close"))
self.MakeModal(False)
event.Skip()

View file

@ -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 @@ class ProfileManager(wx.Panel):
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)

View file

@ -23,7 +23,8 @@ from sat.core.i18n import _
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

View file

@ -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):

View file

@ -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 @@ class ListWidget(EventWidget, WixWidget, xmlui.ListWidget, wx.ListBox):
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 @@ class XMLUI(xmlui.XMLUI, wx.Frame):
def onClose(self, event):
"""Close event: we have to send the form."""
debug(_("close"))
log.debug(_("close"))
if self.type == 'param':
self.onSaveParams()
else: