Display log messages in progress dialog.

git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@3977 e7d03fd6-7b0d-0410-9947-9c21f3af8025
This commit is contained in:
calvin 2009-02-19 13:36:16 +00:00
parent 9adaadde4b
commit ab5c841c9b
3 changed files with 38 additions and 19 deletions

View file

@ -2,4 +2,3 @@
columns result (as icon), URL, name; doubleclick opens property popup columns result (as icon), URL, name; doubleclick opens property popup
http://doc.trolltech.com/4.4/qtreewidget.html http://doc.trolltech.com/4.4/qtreewidget.html
http://doc.trolltech.com/4.4/qtreewidgetitem.html http://doc.trolltech.com/4.4/qtreewidgetitem.html
- [GUI] Display log messages in text box.

View file

@ -152,7 +152,7 @@ class Configuration (dict):
self["scanvirus"] = False self["scanvirus"] = False
self["clamavconf"] = clamav.canonical_clamav_conf() self["clamavconf"] = clamav.canonical_clamav_conf()
def init_logging (self, status_logger, debug=None): def init_logging (self, status_logger, debug=None, handler=None):
""" """
Load logging.conf file settings to set up the Load logging.conf file settings to set up the
application logging (not to be confused with check loggers). application logging (not to be confused with check loggers).
@ -164,7 +164,8 @@ class Configuration (dict):
filename = normpath(os.path.join(get_config_dir(), "logging.conf")) filename = normpath(os.path.join(get_config_dir(), "logging.conf"))
if os.path.isfile(filename): if os.path.isfile(filename):
logging.config.fileConfig(filename) logging.config.fileConfig(filename)
handler = ansicolor.ColoredStreamHandler(strm=sys.stderr) if handler is None:
handler = ansicolor.ColoredStreamHandler(strm=sys.stderr)
handler.setFormatter(logging.Formatter("%(levelname)s %(message)s")) handler.setFormatter(logging.Formatter("%(levelname)s %(message)s"))
logging.getLogger(LOG).addHandler(handler) logging.getLogger(LOG).addHandler(handler)
self.set_debug(debug) self.set_debug(debug)

View file

@ -57,6 +57,7 @@ class LinkCheckerMain (QtGui.QMainWindow, Ui_MainWindow):
self.init_treewidget() self.init_treewidget()
self.read_settings() self.read_settings()
self.connect_widgets() self.connect_widgets()
self.init_config()
self.status = Status.idle self.status = Status.idle
def read_settings (self): def read_settings (self):
@ -151,8 +152,8 @@ Version 2 or later.</p>
self.controlButton.setEnabled(False) self.controlButton.setEnabled(False)
self.optionsButton.setEnabled(False) self.optionsButton.setEnabled(False)
self.treeWidget.clear() self.treeWidget.clear()
config = self.get_config() self.set_config()
aggregate = director.get_aggregate(config) aggregate = director.get_aggregate(self.config)
url = unicode(self.urlinput.text()).strip() url = unicode(self.urlinput.text()).strip()
if not url: if not url:
self.set_statusbar(_("Error, empty URL")) self.set_statusbar(_("Error, empty URL"))
@ -165,7 +166,7 @@ Version 2 or later.</p>
self.set_statusbar(_("Checking '%s'.") % strformat.limit(url, 40)) self.set_statusbar(_("Checking '%s'.") % strformat.limit(url, 40))
url_data = checker.get_url_from(url, 0, aggregate) url_data = checker.get_url_from(url, 0, aggregate)
try: try:
add_intern_pattern(url_data, config) add_intern_pattern(url_data, self.config)
except UnicodeError: except UnicodeError:
self.set_statusbar(_("Error, invalid URL '%s'.") % self.set_statusbar(_("Error, invalid URL '%s'.") %
strformat.limit(url, 40)) strformat.limit(url, 40))
@ -178,18 +179,20 @@ Version 2 or later.</p>
self.checker.check(self.aggregate, self.progress) self.checker.check(self.aggregate, self.progress)
self.status = Status.checking self.status = Status.checking
def get_config (self): def init_config (self):
"""Return check configuration.""" self.config = configuration.Configuration()
config = configuration.Configuration() self.config.logger_add("gui", GuiLogger)
config["recursionlevel"] = self.options.recursionlevel.value() self.config["logger"] = self.config.logger_new('gui', widget=self.checker)
config.logger_add("gui", GuiLogger) self.config["status"] = True
config["logger"] = config.logger_new('gui', widget=self.checker) handler = GuiLogHandler(self.checker)
config["verbose"] = self.options.verbose.isChecked() self.config.init_logging(StatusLogger(self.checker), handler=handler)
config["timeout"] = self.options.timeout.value()
config["threads"] = self.options.threads.value() def set_config (self):
config.init_logging(StatusLogger(self.checker)) """Set configuration."""
config["status"] = True self.config["recursionlevel"] = self.options.recursionlevel.value()
return config self.config["verbose"] = self.options.verbose.isChecked()
self.config["timeout"] = self.options.timeout.value()
self.config["threads"] = self.options.threads.value()
def log_url (self, url_data): def log_url (self, url_data):
"""Add URL data to tree widget.""" """Add URL data to tree widget."""
@ -209,6 +212,23 @@ Version 2 or later.</p>
self.statusBar.showMessage(msg) self.statusBar.showMessage(msg)
from logging import Handler
class GuiLogHandler (Handler, object):
def __init__ (self, widget):
"""Log to given stream (a file-like object) or to stderr if
strm is None.
"""
super(GuiLogHandler, self).__init__()
self.widget = widget
def emit (self, record):
"""Emit a record."""
msg = self.format(record)
self.widget.emit(QtCore.SIGNAL("status(QString)"), msg)
class HelpWindow (QtGui.QDialog): class HelpWindow (QtGui.QDialog):
"""A custom help display dialog.""" """A custom help display dialog."""
@ -344,7 +364,6 @@ class GuiLogger (Logger):
def __init__ (self, **args): def __init__ (self, **args):
super(GuiLogger, self).__init__(**args) super(GuiLogger, self).__init__(**args)
self.widget = args["widget"] self.widget = args["widget"]
self.end_output_called = False
def start_fileoutput (self): def start_fileoutput (self):
pass pass