2009-02-23 22:44:49 +00:00
|
|
|
# -*- coding: iso-8859-1 -*-
|
2014-01-08 21:33:04 +00:00
|
|
|
# Copyright (C) 2009-2014 Bastian Kleineidam
|
2009-02-23 22:44:49 +00:00
|
|
|
#
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
#
|
2009-07-24 21:58:20 +00:00
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2009-02-23 22:44:49 +00:00
|
|
|
|
|
|
|
|
from logging import Handler
|
2013-12-11 17:41:55 +00:00
|
|
|
from ..logger import _Logger
|
2009-02-23 22:44:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class GuiLogHandler (Handler, object):
|
2009-02-24 20:51:44 +00:00
|
|
|
"""Delegate log messages to the UI."""
|
2009-02-23 22:44:49 +00:00
|
|
|
|
2010-11-18 22:26:34 +00:00
|
|
|
def __init__ (self, signal):
|
2009-02-24 20:51:44 +00:00
|
|
|
"""Save widget."""
|
2009-02-23 22:44:49 +00:00
|
|
|
super(GuiLogHandler, self).__init__()
|
2010-11-18 22:26:34 +00:00
|
|
|
self.signal = signal
|
2009-02-23 22:44:49 +00:00
|
|
|
|
|
|
|
|
def emit (self, record):
|
2010-10-14 19:13:28 +00:00
|
|
|
"""Emit a record. It gets logged in the debug widget."""
|
2010-11-18 22:26:34 +00:00
|
|
|
self.signal.emit(self.format(record))
|
2009-02-23 22:44:49 +00:00
|
|
|
|
|
|
|
|
|
2013-12-11 17:41:55 +00:00
|
|
|
class SignalLogger (_Logger):
|
2012-04-18 19:52:36 +00:00
|
|
|
"""Use Qt signals for logged URLs and statistics."""
|
2009-02-23 22:44:49 +00:00
|
|
|
|
2013-12-11 17:41:55 +00:00
|
|
|
LoggerName = "gui"
|
|
|
|
|
|
2009-02-23 22:44:49 +00:00
|
|
|
def __init__ (self, **args):
|
2011-02-17 18:59:02 +00:00
|
|
|
"""Store signals for URL and statistic data."""
|
2012-04-18 19:52:36 +00:00
|
|
|
super(SignalLogger, self).__init__(**args)
|
2010-11-18 22:26:34 +00:00
|
|
|
self.log_url_signal = args["signal"]
|
2010-12-16 20:52:26 +00:00
|
|
|
self.log_stats_signal = args["stats"]
|
2009-02-23 22:44:49 +00:00
|
|
|
|
|
|
|
|
def start_fileoutput (self):
|
2011-02-17 18:59:02 +00:00
|
|
|
"""Override fileoutput handling of base class."""
|
2009-02-23 22:44:49 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def close_fileoutput (self):
|
2011-02-17 18:59:02 +00:00
|
|
|
"""Override fileoutput handling of base class."""
|
2009-02-23 22:44:49 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def log_url (self, url_data):
|
2011-02-17 18:59:02 +00:00
|
|
|
"""Emit URL data which gets logged in the main window."""
|
2010-11-18 22:26:34 +00:00
|
|
|
self.log_url_signal.emit(url_data)
|
2009-02-23 22:44:49 +00:00
|
|
|
|
2014-03-14 20:06:10 +00:00
|
|
|
def end_output (self, downloaded_bytes=None):
|
2011-02-17 18:59:02 +00:00
|
|
|
"""Emit statistic data which gets logged in the main window."""
|
2014-03-14 20:06:10 +00:00
|
|
|
self.stats.downloaded_bytes = downloaded_bytes
|
2010-12-16 20:52:26 +00:00
|
|
|
self.log_stats_signal.emit(self.stats)
|
2011-05-07 19:14:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class StatusLogger (object):
|
|
|
|
|
"""GUI status logger, signaling to progress labels."""
|
|
|
|
|
|
|
|
|
|
def __init__ (self, signal):
|
|
|
|
|
"""Store given signal object."""
|
|
|
|
|
self.signal = signal
|
|
|
|
|
|
2014-03-14 20:06:10 +00:00
|
|
|
def log_status (self, checked, in_progress, queued, duration,
|
|
|
|
|
downloaded_bytes):
|
2011-05-07 19:14:08 +00:00
|
|
|
"""Emit signal with given status information."""
|
2014-03-14 20:06:10 +00:00
|
|
|
self.signal.emit(checked, in_progress, queued, duration,
|
|
|
|
|
downloaded_bytes)
|