From ab5c841c9b9d7ab2d18a0fd6a9bdc8cfc8ea40ef Mon Sep 17 00:00:00 2001 From: calvin Date: Thu, 19 Feb 2009 13:36:16 +0000 Subject: [PATCH] Display log messages in progress dialog. git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@3977 e7d03fd6-7b0d-0410-9947-9c21f3af8025 --- TODO.txt | 1 - linkcheck/configuration/__init__.py | 5 +-- linkcheck/gui/__init__.py | 51 ++++++++++++++++++++--------- 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/TODO.txt b/TODO.txt index 43d0b6a7..7bf60723 100644 --- a/TODO.txt +++ b/TODO.txt @@ -2,4 +2,3 @@ columns result (as icon), URL, name; doubleclick opens property popup http://doc.trolltech.com/4.4/qtreewidget.html http://doc.trolltech.com/4.4/qtreewidgetitem.html -- [GUI] Display log messages in text box. diff --git a/linkcheck/configuration/__init__.py b/linkcheck/configuration/__init__.py index b890d1eb..ea1171db 100644 --- a/linkcheck/configuration/__init__.py +++ b/linkcheck/configuration/__init__.py @@ -152,7 +152,7 @@ class Configuration (dict): self["scanvirus"] = False 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 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")) if os.path.isfile(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")) logging.getLogger(LOG).addHandler(handler) self.set_debug(debug) diff --git a/linkcheck/gui/__init__.py b/linkcheck/gui/__init__.py index 7210b6fb..26cbfadb 100644 --- a/linkcheck/gui/__init__.py +++ b/linkcheck/gui/__init__.py @@ -57,6 +57,7 @@ class LinkCheckerMain (QtGui.QMainWindow, Ui_MainWindow): self.init_treewidget() self.read_settings() self.connect_widgets() + self.init_config() self.status = Status.idle def read_settings (self): @@ -151,8 +152,8 @@ Version 2 or later.

self.controlButton.setEnabled(False) self.optionsButton.setEnabled(False) self.treeWidget.clear() - config = self.get_config() - aggregate = director.get_aggregate(config) + self.set_config() + aggregate = director.get_aggregate(self.config) url = unicode(self.urlinput.text()).strip() if not url: self.set_statusbar(_("Error, empty URL")) @@ -165,7 +166,7 @@ Version 2 or later.

self.set_statusbar(_("Checking '%s'.") % strformat.limit(url, 40)) url_data = checker.get_url_from(url, 0, aggregate) try: - add_intern_pattern(url_data, config) + add_intern_pattern(url_data, self.config) except UnicodeError: self.set_statusbar(_("Error, invalid URL '%s'.") % strformat.limit(url, 40)) @@ -178,18 +179,20 @@ Version 2 or later.

self.checker.check(self.aggregate, self.progress) self.status = Status.checking - def get_config (self): - """Return check configuration.""" - config = configuration.Configuration() - config["recursionlevel"] = self.options.recursionlevel.value() - config.logger_add("gui", GuiLogger) - config["logger"] = config.logger_new('gui', widget=self.checker) - config["verbose"] = self.options.verbose.isChecked() - config["timeout"] = self.options.timeout.value() - config["threads"] = self.options.threads.value() - config.init_logging(StatusLogger(self.checker)) - config["status"] = True - return config + def init_config (self): + self.config = configuration.Configuration() + self.config.logger_add("gui", GuiLogger) + self.config["logger"] = self.config.logger_new('gui', widget=self.checker) + self.config["status"] = True + handler = GuiLogHandler(self.checker) + self.config.init_logging(StatusLogger(self.checker), handler=handler) + + def set_config (self): + """Set configuration.""" + self.config["recursionlevel"] = self.options.recursionlevel.value() + 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): """Add URL data to tree widget.""" @@ -209,6 +212,23 @@ Version 2 or later.

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): """A custom help display dialog.""" @@ -344,7 +364,6 @@ class GuiLogger (Logger): def __init__ (self, **args): super(GuiLogger, self).__init__(**args) self.widget = args["widget"] - self.end_output_called = False def start_fileoutput (self): pass