mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-04-09 17:10:58 +00:00
Log GUI output to a treewidget
git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@3976 e7d03fd6-7b0d-0410-9947-9c21f3af8025
This commit is contained in:
parent
6ec61c5bad
commit
9adaadde4b
4 changed files with 52 additions and 48 deletions
3
TODO.txt
3
TODO.txt
|
|
@ -1,4 +1,5 @@
|
|||
- [GUI] Store checked links in urldata list; display in a QTreeWidget;
|
||||
columns result (as icon), URL, name; doubleclick opens property popup
|
||||
signal "foo(PyQt_PyObject)"
|
||||
http://doc.trolltech.com/4.4/qtreewidget.html
|
||||
http://doc.trolltech.com/4.4/qtreewidgetitem.html
|
||||
- [GUI] Display log messages in text box.
|
||||
|
|
|
|||
|
|
@ -47,21 +47,29 @@ class LinkCheckerMain (QtGui.QMainWindow, Ui_MainWindow):
|
|||
self.urlinput.setText(url)
|
||||
self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowContextHelpButtonHint)
|
||||
self.setWindowTitle(configuration.App)
|
||||
# init subdialogs
|
||||
self.options = LinkCheckerOptions(parent=self)
|
||||
self.progress = LinkCheckerProgress(parent=self)
|
||||
set_fixed_font(self.output)
|
||||
self.checker = Checker()
|
||||
# Note: we can't use QT assistant here because of the .exe packaging
|
||||
self.assistant = HelpWindow(self, "doc/lccollection.qhc")
|
||||
# setup this widget
|
||||
self.init_treewidget()
|
||||
self.read_settings()
|
||||
self.connect_widgets()
|
||||
self.status = Status.idle
|
||||
|
||||
def read_settings (self):
|
||||
settings = QtCore.QSettings('bfk', configuration.AppName)
|
||||
settings.beginGroup('mainwindow')
|
||||
if settings.contains('size'):
|
||||
self.resize(settings.value('size').toSize())
|
||||
self.move(settings.value('pos').toPoint())
|
||||
settings.endGroup()
|
||||
# Note: we can't use QT assistant here because of the .exe packaging
|
||||
self.assistant = HelpWindow(self, "doc/lccollection.qhc")
|
||||
|
||||
def connect_widgets (self):
|
||||
self.connect(self.checker, QtCore.SIGNAL("finished()"), self.set_status_idle)
|
||||
self.connect(self.checker, QtCore.SIGNAL("terminated()"), self.set_status_idle)
|
||||
self.connect(self.checker, QtCore.SIGNAL("add_message(QString)"), self.add_message)
|
||||
self.connect(self.checker, QtCore.SIGNAL("log_url(PyQt_PyObject)"), self.log_url)
|
||||
self.connect(self.checker, QtCore.SIGNAL("status(QString)"), self.progress.status)
|
||||
self.connect(self.controlButton, QtCore.SIGNAL("clicked()"), self.start)
|
||||
|
|
@ -69,12 +77,16 @@ class LinkCheckerMain (QtGui.QMainWindow, Ui_MainWindow):
|
|||
self.connect(self.actionQuit, QtCore.SIGNAL("triggered()"), self.close)
|
||||
self.connect(self.actionAbout, QtCore.SIGNAL("triggered()"), self.about)
|
||||
self.connect(self.actionHelp, QtCore.SIGNAL("triggered()"), self.showDocumentation)
|
||||
self.status = Status.idle
|
||||
#self.controlButton.setText(_("Start"))
|
||||
#icon = QtGui.QIcon()
|
||||
#icon.addPixmap(QtGui.QPixmap(":/icons/start.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||
#self.controlButton.setIcon(icon)
|
||||
|
||||
def init_treewidget (self):
|
||||
from ..logger import Fields
|
||||
self.treeWidget.setColumnCount(3)
|
||||
self.treeWidget.setHeaderLabels((Fields["url"], Fields["name"], Fields["result"]))
|
||||
|
||||
def get_status (self):
|
||||
return self._status
|
||||
|
||||
|
|
@ -138,12 +150,12 @@ Version 2 or later.</p>
|
|||
"""Check given URL."""
|
||||
self.controlButton.setEnabled(False)
|
||||
self.optionsButton.setEnabled(False)
|
||||
self.output.setText("")
|
||||
self.treeWidget.clear()
|
||||
config = self.get_config()
|
||||
aggregate = director.get_aggregate(config)
|
||||
url = unicode(self.urlinput.text()).strip()
|
||||
if not url:
|
||||
self.output.setText(_("Error, empty URL"))
|
||||
self.set_statusbar(_("Error, empty URL"))
|
||||
self.status = Status.idle
|
||||
return
|
||||
if url.startswith(u"www."):
|
||||
|
|
@ -155,7 +167,7 @@ Version 2 or later.</p>
|
|||
try:
|
||||
add_intern_pattern(url_data, config)
|
||||
except UnicodeError:
|
||||
self.output.setText(_("Error, invalid URL '%s'.") %
|
||||
self.set_statusbar(_("Error, invalid URL '%s'.") %
|
||||
strformat.limit(url, 40))
|
||||
self.status = Status.idle
|
||||
return
|
||||
|
|
@ -179,14 +191,18 @@ Version 2 or later.</p>
|
|||
config["status"] = True
|
||||
return config
|
||||
|
||||
def add_message (self, msg):
|
||||
"""Add new log message to text edit widget."""
|
||||
text = self.output.toPlainText()
|
||||
self.output.setText(text+msg)
|
||||
self.output.moveCursor(QtGui.QTextCursor.End)
|
||||
|
||||
def log_url (self, url_data):
|
||||
pass # XXX log url_data
|
||||
"""Add URL data to tree widget."""
|
||||
url = url_data.base_url or u""
|
||||
name = url_data.name
|
||||
if url_data.valid:
|
||||
result = u"Valid"
|
||||
else:
|
||||
result = u"Error"
|
||||
if url_data.result:
|
||||
result += u": %s" % url_data.result
|
||||
item = QtGui.QTreeWidgetItem((url, name, result))
|
||||
self.treeWidget.addTopLevelItem(item)
|
||||
|
||||
def set_statusbar (self, msg):
|
||||
"""Show status message in status bar."""
|
||||
|
|
@ -320,9 +336,9 @@ class Checker (QtCore.QThread):
|
|||
director.check_urls(self.aggregate)
|
||||
|
||||
|
||||
from linkcheck.logger.text import TextLogger
|
||||
from ..logger import Logger
|
||||
|
||||
class GuiLogger (TextLogger):
|
||||
class GuiLogger (Logger):
|
||||
"""Custom logger class to delegate log messages to the UI."""
|
||||
|
||||
def __init__ (self, **args):
|
||||
|
|
@ -330,28 +346,21 @@ class GuiLogger (TextLogger):
|
|||
self.widget = args["widget"]
|
||||
self.end_output_called = False
|
||||
|
||||
def write (self, s, **args):
|
||||
self.widget.emit(QtCore.SIGNAL("add_message(QString)"), s)
|
||||
|
||||
def start_fileoutput (self):
|
||||
pass
|
||||
|
||||
def close_fileoutput (self):
|
||||
pass
|
||||
|
||||
def end_output (self):
|
||||
# The linkchecker director thread is not the main thread, and
|
||||
# it can call end_output() twice, from director.check_urls() and
|
||||
# from director.abort(). This happends when LinkCheckerMain.stop()
|
||||
# is called. The flag prevents double printing of the output.
|
||||
if not self.end_output_called:
|
||||
self.end_output_called = True
|
||||
super(GuiLogger, self).end_output()
|
||||
|
||||
def log_url (self, url_data):
|
||||
super(GuiLogger, self).log_url(url_data)
|
||||
self.widget.emit(QtCore.SIGNAL("log_url(PyQt_PyObject)"), url_data)
|
||||
|
||||
def end_output (self):
|
||||
pass
|
||||
|
||||
def start_output (self):
|
||||
pass
|
||||
|
||||
|
||||
class StatusLogger (object):
|
||||
"""Custom status logger to delegate status message to the UI."""
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
# Form implementation generated from reading ui file 'ui/main.ui'
|
||||
#
|
||||
# Created: Wed Feb 18 23:00:36 2009
|
||||
# Created: Thu Feb 19 11:02:50 2009
|
||||
# by: PyQt4 UI code generator 4.4.4
|
||||
#
|
||||
# WARNING! All changes made in this file will be lost!
|
||||
|
|
@ -50,12 +50,9 @@ class Ui_MainWindow(object):
|
|||
self.controlButton.setObjectName("controlButton")
|
||||
self.horizontalLayout_3.addWidget(self.controlButton)
|
||||
self.gridLayout.addLayout(self.horizontalLayout_3, 0, 1, 1, 1)
|
||||
self.output = QtGui.QTextEdit(self.centralwidget)
|
||||
self.output.setUndoRedoEnabled(False)
|
||||
self.output.setLineWrapMode(QtGui.QTextEdit.NoWrap)
|
||||
self.output.setReadOnly(True)
|
||||
self.output.setObjectName("output")
|
||||
self.gridLayout.addWidget(self.output, 1, 0, 1, 2)
|
||||
self.treeWidget = QtGui.QTreeWidget(self.centralwidget)
|
||||
self.treeWidget.setObjectName("treeWidget")
|
||||
self.gridLayout.addWidget(self.treeWidget, 1, 0, 1, 2)
|
||||
MainWindow.setCentralWidget(self.centralwidget)
|
||||
self.menubar = QtGui.QMenuBar(MainWindow)
|
||||
self.menubar.setGeometry(QtCore.QRect(0, 0, 408, 29))
|
||||
|
|
@ -90,6 +87,7 @@ class Ui_MainWindow(object):
|
|||
self.optionsButton.setText(QtGui.QApplication.translate("MainWindow", "Options...", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.controlButton.setToolTip(QtGui.QApplication.translate("MainWindow", "Start checking the given URL.", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.controlButton.setText(QtGui.QApplication.translate("MainWindow", "Start", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.treeWidget.headerItem().setText(0, QtGui.QApplication.translate("MainWindow", "1", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.menuLinkChecka.setTitle(QtGui.QApplication.translate("MainWindow", "File", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.menuHelp.setTitle(QtGui.QApplication.translate("MainWindow", "Help", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.actionQuit.setText(QtGui.QApplication.translate("MainWindow", "Quit", None, QtGui.QApplication.UnicodeUTF8))
|
||||
|
|
|
|||
|
|
@ -89,16 +89,12 @@
|
|||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2" >
|
||||
<widget class="QTextEdit" name="output" >
|
||||
<property name="undoRedoEnabled" >
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="lineWrapMode" >
|
||||
<enum>QTextEdit::NoWrap</enum>
|
||||
</property>
|
||||
<property name="readOnly" >
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QTreeWidget" name="treeWidget" >
|
||||
<column>
|
||||
<property name="text" >
|
||||
<string>1</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
|
|
|||
Loading…
Reference in a new issue