mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-04-04 23:20:34 +00:00
Save parent URL source in local file.
This commit is contained in:
parent
d47aa6335f
commit
cc3eea535f
4 changed files with 139 additions and 13 deletions
|
|
@ -16,7 +16,7 @@ Changes:
|
|||
redirects any more.
|
||||
|
||||
Features:
|
||||
|
||||
- gui: Add command to save the parent URL source in a local file.
|
||||
|
||||
5.4 "How to train your dragon" (released 26.10.2010)
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
from PyQt4 import Qsci, QtGui
|
||||
from PyQt4 import Qsci, QtGui, QtCore
|
||||
from .linkchecker_ui_editor import Ui_EditorDialog
|
||||
|
||||
|
||||
|
|
@ -23,7 +23,7 @@ ContentTypeLexers = {
|
|||
"application/x-shellscript": Qsci.QsciLexerBash,
|
||||
"application/x-sh": Qsci.QsciLexerBash,
|
||||
"application/x-msdos-program": Qsci.QsciLexerBatch,
|
||||
"": Qsci.QsciLexerCMake,
|
||||
#"": Qsci.QsciLexerCMake,
|
||||
"text/x-c++src": Qsci.QsciLexerCPP,
|
||||
"text/css": Qsci.QsciLexerCSS,
|
||||
#"": Qsci.QsciLexerCSharp,
|
||||
|
|
@ -41,8 +41,8 @@ ContentTypeLexers = {
|
|||
#"": Qsci.QsciLexerPOV,
|
||||
"text/x-pascal": Qsci.QsciLexerPascal,
|
||||
"text/x-perl": Qsci.QsciLexerPerl,
|
||||
"": Qsci.QsciLexerPostScript,
|
||||
"": Qsci.QsciLexerProperties,
|
||||
"application/postscript": Qsci.QsciLexerPostScript,
|
||||
"text/plain+ini": Qsci.QsciLexerProperties,
|
||||
"text/x-python": Qsci.QsciLexerPython,
|
||||
"application/x-ruby": Qsci.QsciLexerRuby,
|
||||
#"": Qsci.QsciLexerSQL,
|
||||
|
|
@ -94,18 +94,19 @@ class Editor (Qsci.QsciScintilla):
|
|||
# folding margin colors (foreground,background)
|
||||
self.setFoldMarginColors(QtGui.QColor("#f5f5dc"),QtGui.QColor("#aaaaaa"))
|
||||
|
||||
# No editing (yet) in this window, since the source is taken
|
||||
# from an online URL.
|
||||
# XXX allow editing and saving to a local file.
|
||||
self.setReadOnly(True)
|
||||
|
||||
class EditorWindow (QtGui.QDialog, Ui_EditorDialog):
|
||||
|
||||
def __init__ (self, parent=None):
|
||||
super(EditorWindow, self).__init__(parent)
|
||||
self.setupUi(self)
|
||||
self.editor = Editor(parent=self)
|
||||
self.verticalLayout.addWidget(self.editor)
|
||||
# filename used for saving
|
||||
self.filename = None
|
||||
# the Scintilla editor widget
|
||||
self.editor = Editor(parent=self.frame)
|
||||
layout = QtGui.QVBoxLayout(self.frame)
|
||||
layout.setMargin(0)
|
||||
layout.addWidget(self.editor)
|
||||
# for debugging
|
||||
#self.setText(("1234567890"*8) + "\n<html><head>\n<title>x</title>\n</head>\n")
|
||||
#lexer = Qsci.QsciLexerHTML()
|
||||
|
|
@ -128,3 +129,55 @@ class EditorWindow (QtGui.QDialog, Ui_EditorDialog):
|
|||
def setText (self, text, line=1, col=1):
|
||||
self.editor.setText(text)
|
||||
self.editor.setCursorPosition(line-1, col-1)
|
||||
self.editor.setModified(False)
|
||||
|
||||
@QtCore.pyqtSignature("")
|
||||
def on_actionSave_triggered (self):
|
||||
"""Save editor contents."""
|
||||
if self.editor.isModified() or not self.filename:
|
||||
self.save()
|
||||
|
||||
def save (self):
|
||||
if not self.filename:
|
||||
res = QtGui.QFileDialog.getSaveFileName(self, "Save File As")
|
||||
if not res:
|
||||
return
|
||||
self.filename = res
|
||||
self.setWindowTitle(self.filename)
|
||||
fh = None
|
||||
try:
|
||||
try:
|
||||
fh = QtCore.QFile(self.filename)
|
||||
if not fh.open(QtCore.QIODevice.WriteOnly):
|
||||
raise IOError(fh.errorString())
|
||||
stream = QtCore.QTextStream(fh)
|
||||
stream.setCodec("UTF-8")
|
||||
stream << self.editor.text()
|
||||
self.editor.setModified(False)
|
||||
except (IOError, OSError), e:
|
||||
err = QtGui.QMessageBox(self)
|
||||
err.setText(str(e))
|
||||
err.exec_()
|
||||
finally:
|
||||
if fh is not None:
|
||||
fh.close()
|
||||
|
||||
def load (self, filename):
|
||||
self.filename = filename
|
||||
self.setWindowTitle(self.filename)
|
||||
fh = None
|
||||
try:
|
||||
try:
|
||||
fh = QtCore.QFile(self.filename)
|
||||
if not fh.open(QtCore.QIODevice.ReadOnly):
|
||||
raise IOError(fh.errorString())
|
||||
stream = QtCore.QTextStream(fh)
|
||||
stream.setCodec("UTF-8")
|
||||
self.setText(stream.readAll())
|
||||
except (IOError, OSError), e:
|
||||
err = QtGui.QMessageBox(self)
|
||||
err.setText(str(e))
|
||||
err.exec_()
|
||||
finally:
|
||||
if fh is not None:
|
||||
fh.close()
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
# Form implementation generated from reading ui file 'ui/editor.ui'
|
||||
#
|
||||
# Created: Sun Oct 3 09:27:19 2010
|
||||
# Created: Fri Nov 5 00:55:45 2010
|
||||
# by: PyQt4 UI code generator 4.7.3
|
||||
#
|
||||
# WARNING! All changes made in this file will be lost!
|
||||
|
|
@ -14,12 +14,40 @@ class Ui_EditorDialog(object):
|
|||
EditorDialog.setObjectName("EditorDialog")
|
||||
EditorDialog.setWindowModality(QtCore.Qt.ApplicationModal)
|
||||
EditorDialog.resize(640, 600)
|
||||
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
|
||||
sizePolicy.setHorizontalStretch(0)
|
||||
sizePolicy.setVerticalStretch(0)
|
||||
sizePolicy.setHeightForWidth(EditorDialog.sizePolicy().hasHeightForWidth())
|
||||
EditorDialog.setSizePolicy(sizePolicy)
|
||||
self.verticalLayout = QtGui.QVBoxLayout(EditorDialog)
|
||||
self.verticalLayout.setMargin(0)
|
||||
self.verticalLayout.setObjectName("verticalLayout")
|
||||
self.menubar = QtGui.QMenuBar(EditorDialog)
|
||||
self.menubar.setObjectName("menubar")
|
||||
self.menuFile = QtGui.QMenu(self.menubar)
|
||||
self.menuFile.setObjectName("menuFile")
|
||||
self.verticalLayout.addWidget(self.menubar)
|
||||
self.frame = QtGui.QFrame(EditorDialog)
|
||||
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
|
||||
sizePolicy.setHorizontalStretch(0)
|
||||
sizePolicy.setVerticalStretch(0)
|
||||
sizePolicy.setHeightForWidth(self.frame.sizePolicy().hasHeightForWidth())
|
||||
self.frame.setSizePolicy(sizePolicy)
|
||||
self.frame.setFrameShape(QtGui.QFrame.NoFrame)
|
||||
self.frame.setFrameShadow(QtGui.QFrame.Plain)
|
||||
self.frame.setLineWidth(0)
|
||||
self.frame.setObjectName("frame")
|
||||
self.verticalLayout.addWidget(self.frame)
|
||||
self.actionSave = QtGui.QAction(EditorDialog)
|
||||
self.actionSave.setObjectName("actionSave")
|
||||
self.menuFile.addAction(self.actionSave)
|
||||
self.menubar.addAction(self.menuFile.menuAction())
|
||||
|
||||
self.retranslateUi(EditorDialog)
|
||||
QtCore.QMetaObject.connectSlotsByName(EditorDialog)
|
||||
|
||||
def retranslateUi(self, EditorDialog):
|
||||
EditorDialog.setWindowTitle(_("LinkChecker source view"))
|
||||
self.menuFile.setTitle(_("File"))
|
||||
self.actionSave.setText(_("Save"))
|
||||
|
||||
|
|
|
|||
|
|
@ -13,10 +13,55 @@
|
|||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>LinkChecker source view</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout"/>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<widget class="QMenu" name="menuFile">
|
||||
<property name="title">
|
||||
<string>File</string>
|
||||
</property>
|
||||
<addaction name="actionSave"/>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<action name="actionSave">
|
||||
<property name="text">
|
||||
<string>Save</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
|
|
|||
Loading…
Reference in a new issue