--- a/Plugins/WizardPlugins/QRegExpWizard/QRegExpWizardDialog.py Sat Sep 07 14:50:51 2013 +0200 +++ b/Plugins/WizardPlugins/QRegExpWizard/QRegExpWizardDialog.py Sat Sep 07 15:47:53 2013 +0200 @@ -10,8 +10,8 @@ import os from PyQt4.QtCore import QFileInfo, QRegExp, Qt, pyqtSlot, qVersion -from PyQt4.QtGui import QWidget, QDialog, QApplication, QClipboard, QTextCursor, \ - QDialogButtonBox, QVBoxLayout, QTableWidgetItem +from PyQt4.QtGui import QWidget, QDialog, QApplication, QClipboard, \ + QTextCursor, QDialogButtonBox, QVBoxLayout, QTableWidgetItem from E5Gui import E5MessageBox, E5FileDialog from E5Gui.E5MainWindow import E5MainWindow @@ -48,15 +48,21 @@ self.altnButton.setIcon(UI.PixmapCache.getIcon("altn.png")) self.beglineButton.setIcon(UI.PixmapCache.getIcon("begline.png")) self.endlineButton.setIcon(UI.PixmapCache.getIcon("endline.png")) - self.wordboundButton.setIcon(UI.PixmapCache.getIcon("wordboundary.png")) - self.nonwordboundButton.setIcon(UI.PixmapCache.getIcon("nonwordboundary.png")) - self.poslookaheadButton.setIcon(UI.PixmapCache.getIcon("poslookahead.png")) - self.neglookaheadButton.setIcon(UI.PixmapCache.getIcon("neglookahead.png")) + self.wordboundButton.setIcon( + UI.PixmapCache.getIcon("wordboundary.png")) + self.nonwordboundButton.setIcon( + UI.PixmapCache.getIcon("nonwordboundary.png")) + self.poslookaheadButton.setIcon( + UI.PixmapCache.getIcon("poslookahead.png")) + self.neglookaheadButton.setIcon( + UI.PixmapCache.getIcon("neglookahead.png")) self.undoButton.setIcon(UI.PixmapCache.getIcon("editUndo.png")) self.redoButton.setIcon(UI.PixmapCache.getIcon("editRedo.png")) # wildcard tool buttons - self.wildcardCharButton.setIcon(UI.PixmapCache.getIcon("characters.png")) - self.wildcardAnycharButton.setIcon(UI.PixmapCache.getIcon("anychar.png")) + self.wildcardCharButton.setIcon( + UI.PixmapCache.getIcon("characters.png")) + self.wildcardAnycharButton.setIcon( + UI.PixmapCache.getIcon("anychar.png")) self.wildcardRepeatButton.setIcon(UI.PixmapCache.getIcon("repeat.png")) # W3C tool buttons self.w3cCharButton.setIcon(UI.PixmapCache.getIcon("characters.png")) @@ -75,21 +81,24 @@ if qVersion() >= "5.0.0": self.syntaxCombo.setCurrentIndex(1) - self.saveButton = \ - self.buttonBox.addButton(self.trUtf8("Save"), QDialogButtonBox.ActionRole) - self.saveButton.setToolTip(self.trUtf8("Save the regular expression to a file")) - self.loadButton = \ - self.buttonBox.addButton(self.trUtf8("Load"), QDialogButtonBox.ActionRole) - self.loadButton.setToolTip(self.trUtf8("Load a regular expression from a file")) - self.validateButton = \ - self.buttonBox.addButton(self.trUtf8("Validate"), QDialogButtonBox.ActionRole) - self.validateButton.setToolTip(self.trUtf8("Validate the regular expression")) - self.executeButton = \ - self.buttonBox.addButton(self.trUtf8("Execute"), QDialogButtonBox.ActionRole) - self.executeButton.setToolTip(self.trUtf8("Execute the regular expression")) - self.nextButton = \ - self.buttonBox.addButton(self.trUtf8("Next match"), - QDialogButtonBox.ActionRole) + self.saveButton = self.buttonBox.addButton( + self.trUtf8("Save"), QDialogButtonBox.ActionRole) + self.saveButton.setToolTip( + self.trUtf8("Save the regular expression to a file")) + self.loadButton = self.buttonBox.addButton( + self.trUtf8("Load"), QDialogButtonBox.ActionRole) + self.loadButton.setToolTip( + self.trUtf8("Load a regular expression from a file")) + self.validateButton = self.buttonBox.addButton( + self.trUtf8("Validate"), QDialogButtonBox.ActionRole) + self.validateButton.setToolTip( + self.trUtf8("Validate the regular expression")) + self.executeButton = self.buttonBox.addButton( + self.trUtf8("Execute"), QDialogButtonBox.ActionRole) + self.executeButton.setToolTip( + self.trUtf8("Execute the regular expression")) + self.nextButton = self.buttonBox.addButton( + self.trUtf8("Next match"), QDialogButtonBox.ActionRole) self.nextButton.setToolTip( self.trUtf8("Show the next match of the regular expression")) self.nextButton.setEnabled(False) @@ -99,8 +108,8 @@ QDialogButtonBox.Cancel | QDialogButtonBox.Ok) self.copyButton = None else: - self.copyButton = \ - self.buttonBox.addButton(self.trUtf8("Copy"), QDialogButtonBox.ActionRole) + self.copyButton = self.buttonBox.addButton( + self.trUtf8("Copy"), QDialogButtonBox.ActionRole) self.copyButton.setToolTip( self.trUtf8("Copy the regular expression to the clipboard")) self.buttonBox.setStandardButtons(QDialogButtonBox.Close) @@ -225,7 +234,8 @@ """ Private slot to handle the characters toolbutton. """ - from .QRegExpWizardCharactersDialog import QRegExpWizardCharactersDialog + from .QRegExpWizardCharactersDialog import \ + QRegExpWizardCharactersDialog dlg = QRegExpWizardCharactersDialog( mode=QRegExpWizardCharactersDialog.RegExpMode, parent=self) if dlg.exec_() == QDialog.Accepted: @@ -236,7 +246,8 @@ """ Private slot to handle the wildcard characters toolbutton. """ - from .QRegExpWizardCharactersDialog import QRegExpWizardCharactersDialog + from .QRegExpWizardCharactersDialog import \ + QRegExpWizardCharactersDialog dlg = QRegExpWizardCharactersDialog( mode=QRegExpWizardCharactersDialog.WildcardMode, parent=self) if dlg.exec_() == QDialog.Accepted: @@ -261,7 +272,8 @@ """ Private slot to handle the wildcard characters toolbutton. """ - from .QRegExpWizardCharactersDialog import QRegExpWizardCharactersDialog + from .QRegExpWizardCharactersDialog import \ + QRegExpWizardCharactersDialog dlg = QRegExpWizardCharactersDialog( mode=QRegExpWizardCharactersDialog.W3CMode, parent=self) if dlg.exec_() == QDialog.Accepted: @@ -336,25 +348,29 @@ if ex: fname += ex if QFileInfo(fname).exists(): - res = E5MessageBox.yesNo(self, + res = E5MessageBox.yesNo( + self, self.trUtf8("Save regular expression"), self.trUtf8("<p>The file <b>{0}</b> already exists." - " Overwrite it?</p>").format(fname), + " Overwrite it?</p>").format(fname), icon=E5MessageBox.Warning) if not res: return syntax = self.syntaxCombo.itemData(self.syntaxCombo.currentIndex()) try: - f = open(Utilities.toNativeSeparators(fname), "w", encoding="utf-8") + f = open( + Utilities.toNativeSeparators(fname), "w", encoding="utf-8") f.write("syntax={0}\n".format(syntax)) f.write(self.regexpLineEdit.text()) f.close() except IOError as err: - E5MessageBox.information(self, + E5MessageBox.information( + self, self.trUtf8("Save regular expression"), - self.trUtf8("""<p>The regular expression could not be saved.</p>""" - """<p>Reason: {0}</p>""").format(str(err))) + self.trUtf8("""<p>The regular expression could not""" + """ be saved.</p><p>Reason: {0}</p>""") + .format(str(err))) @pyqtSlot() def on_loadButton_clicked(self): @@ -368,7 +384,8 @@ self.trUtf8("RegExp Files (*.rx);;All Files (*)")) if fname: try: - f = open(Utilities.toNativeSeparators(fname), "r", encoding="utf-8") + f = open( + Utilities.toNativeSeparators(fname), "r", encoding="utf-8") regexp = f.read() f.close() if regexp.startswith("syntax="): @@ -379,10 +396,12 @@ regexp = lines[1] self.regexpLineEdit.setText(regexp) except IOError as err: - E5MessageBox.information(self, + E5MessageBox.information( + self, self.trUtf8("Save regular expression"), - self.trUtf8("""<p>The regular expression could not be saved.</p>""" - """<p>Reason: {0}</p>""").format(str(err))) + self.trUtf8("""<p>The regular expression could not""" + """ be saved.</p><p>Reason: {0}</p>""") + .format(str(err))) @pyqtSlot() def on_copyButton_clicked(self): @@ -412,19 +431,23 @@ else: re.setCaseSensitivity(Qt.CaseInsensitive) re.setMinimal(self.minimalCheckBox.isChecked()) - re.setPatternSyntax(self.syntaxCombo.itemData(self.syntaxCombo.currentIndex())) + re.setPatternSyntax( + self.syntaxCombo.itemData(self.syntaxCombo.currentIndex())) if re.isValid(): - E5MessageBox.information(self, + E5MessageBox.information( + self, self.trUtf8("Validation"), self.trUtf8("""The regular expression is valid.""")) else: - E5MessageBox.critical(self, + E5MessageBox.critical( + self, self.trUtf8("Error"), self.trUtf8("""Invalid regular expression: {0}""") - .format(re.errorString())) + .format(re.errorString())) return else: - E5MessageBox.critical(self, + E5MessageBox.critical( + self, self.trUtf8("Error"), self.trUtf8("""A regular expression must be given.""")) @@ -451,10 +474,11 @@ wildcard = syntax in [QRegExp.Wildcard, QRegExp.WildcardUnix] re.setPatternSyntax(syntax) if not re.isValid(): - E5MessageBox.critical(self, + E5MessageBox.critical( + self, self.trUtf8("Error"), self.trUtf8("""Invalid regular expression: {0}""") - .format(re.errorString())) + .format(re.errorString())) return offset = re.indexIn(text, startpos) captures = re.captureCount() @@ -465,34 +489,38 @@ self.resultTable.setColumnCount(3) self.resultTable.setRowCount(0) self.resultTable.setRowCount(OFFSET) - self.resultTable.setItem(row, 0, QTableWidgetItem(self.trUtf8("Regexp"))) + self.resultTable.setItem( + row, 0, QTableWidgetItem(self.trUtf8("Regexp"))) self.resultTable.setItem(row, 1, QTableWidgetItem(regex)) if offset != -1: self.lastMatchEnd = offset + re.matchedLength() self.nextButton.setEnabled(True) row += 1 - self.resultTable.setItem(row, 0, QTableWidgetItem(self.trUtf8("Offset"))) - self.resultTable.setItem(row, 1, QTableWidgetItem("{0:d}".format(offset))) + self.resultTable.setItem( + row, 0, QTableWidgetItem(self.trUtf8("Offset"))) + self.resultTable.setItem( + row, 1, QTableWidgetItem("{0:d}".format(offset))) if not wildcard: row += 1 - self.resultTable.setItem(row, 0, - QTableWidgetItem(self.trUtf8("Captures"))) - self.resultTable.setItem(row, 1, - QTableWidgetItem("{0:d}".format(captures))) + self.resultTable.setItem( + row, 0, QTableWidgetItem(self.trUtf8("Captures"))) + self.resultTable.setItem( + row, 1, QTableWidgetItem("{0:d}".format(captures))) row += 1 - self.resultTable.setItem(row, 1, - QTableWidgetItem(self.trUtf8("Text"))) - self.resultTable.setItem(row, 2, - QTableWidgetItem(self.trUtf8("Characters"))) + self.resultTable.setItem( + row, 1, QTableWidgetItem(self.trUtf8("Text"))) + self.resultTable.setItem( + row, 2, QTableWidgetItem(self.trUtf8("Characters"))) row += 1 - self.resultTable.setItem(row, 0, - QTableWidgetItem(self.trUtf8("Match"))) - self.resultTable.setItem(row, 1, - QTableWidgetItem(re.cap(0))) - self.resultTable.setItem(row, 2, + self.resultTable.setItem( + row, 0, QTableWidgetItem(self.trUtf8("Match"))) + self.resultTable.setItem( + row, 1, QTableWidgetItem(re.cap(0))) + self.resultTable.setItem( + row, 2, QTableWidgetItem("{0:d}".format(re.matchedLength()))) if not wildcard: @@ -500,12 +528,17 @@ if len(re.cap(i)) > 0: row += 1 self.resultTable.insertRow(row) - self.resultTable.setItem(row, 0, - QTableWidgetItem(self.trUtf8("Capture #{0}").format(i))) - self.resultTable.setItem(row, 1, + self.resultTable.setItem( + row, 0, + QTableWidgetItem( + self.trUtf8("Capture #{0}").format(i))) + self.resultTable.setItem( + row, 1, QTableWidgetItem(re.cap(i))) - self.resultTable.setItem(row, 2, - QTableWidgetItem("{0:d}".format(len(re.cap(i))))) + self.resultTable.setItem( + row, 2, + QTableWidgetItem( + "{0:d}".format(len(re.cap(i))))) else: self.resultTable.setRowCount(3) @@ -519,10 +552,12 @@ self.resultTable.setRowCount(2) row += 1 if startpos > 0: - self.resultTable.setItem(row, 0, + self.resultTable.setItem( + row, 0, QTableWidgetItem(self.trUtf8("No more matches"))) else: - self.resultTable.setItem(row, 0, + self.resultTable.setItem( + row, 0, QTableWidgetItem(self.trUtf8("No matches"))) # remove the highlight @@ -535,9 +570,11 @@ self.resultTable.verticalHeader().hide() self.resultTable.horizontalHeader().hide() else: - E5MessageBox.critical(self, + E5MessageBox.critical( + self, self.trUtf8("Error"), - self.trUtf8("""A regular expression and a text must be given.""")) + self.trUtf8("""A regular expression and a text must""" + """ be given.""")) @pyqtSlot() def on_nextButton_clicked(self): @@ -556,7 +593,8 @@ def __getPatternSyntaxCode(self, syntaxValue): """ - Private method to convert a pattern syntax value into a pattern syntax string. + Private method to convert a pattern syntax value into a + pattern syntax string. @param syntaxValue pattern syntax value (integer) @return pattern syntax string (string) @@ -601,7 +639,8 @@ code += '{0}{1}.setCaseSensitivity(Qt.CaseInsensitive){2}'.format( istring, reVar, os.linesep) if self.minimalCheckBox.isChecked(): - code += '{0}{1}.setMinimal(True){2}'.format(istring, reVar, os.linesep) + code += '{0}{1}.setMinimal(True){2}'.format( + istring, reVar, os.linesep) syntax = self.syntaxCombo.itemData(self.syntaxCombo.currentIndex()) needPatternSyntax = True if qVersion() < "5.0.0" and syntax == QRegExp.RegExp or \ @@ -610,7 +649,8 @@ needPatternSyntax = False if needPatternSyntax: code += '{0}{1}.setPatternSyntax({2}){3}'.format( - istring, reVar, self.__getPatternSyntaxCode(syntax), estring) + istring, reVar, self.__getPatternSyntaxCode(syntax), + estring) return code @@ -668,7 +708,8 @@ self.setCentralWidget(self.cw) self.resize(size) - self.setStyle(Preferences.getUI("Style"), Preferences.getUI("StyleSheet")) + self.setStyle( + Preferences.getUI("Style"), Preferences.getUI("StyleSheet")) self.cw.buttonBox.accepted[()].connect(self.close) self.cw.buttonBox.rejected[()].connect(self.close)