Sat, 07 Sep 2013 15:47:53 +0200
Some changes to code generation wizards.
--- a/Plugins/WizardPlugins/E5MessageBoxWizard/E5MessageBoxWizardDialog.py Sat Sep 07 14:50:51 2013 +0200 +++ b/Plugins/WizardPlugins/E5MessageBoxWizard/E5MessageBoxWizardDialog.py Sat Sep 07 15:47:53 2013 +0200 @@ -97,8 +97,8 @@ self.defaultCombo.addItems(self.buttonsList) - self.bTest = \ - self.buttonBox.addButton(self.trUtf8("Test"), QDialogButtonBox.ActionRole) + self.bTest = self.buttonBox.addButton( + self.trUtf8("Test"), QDialogButtonBox.ActionRole) self.__enabledGroups() @@ -134,7 +134,8 @@ @pyqtSlot(bool) def on_rInformation_toggled(self, checked): """ - Private slot to handle the toggled signal of the rInformation radio button. + Private slot to handle the toggled signal of the rInformation + radio button. @param on toggle state (boolean) (ignored) """ @@ -143,7 +144,8 @@ @pyqtSlot(bool) def on_rQuestion_toggled(self, checked): """ - Private slot to handle the toggled signal of the rQuestion radio button. + Private slot to handle the toggled signal of the rQuestion + radio button. @param on toggle state (boolean) (ignored) """ @@ -152,7 +154,8 @@ @pyqtSlot(bool) def on_rWarning_toggled(self, checked): """ - Private slot to handle the toggled signal of the rWarning radio button. + Private slot to handle the toggled signal of the rWarning + radio button. @param on toggle state (boolean) (ignored) """ @@ -161,7 +164,8 @@ @pyqtSlot(bool) def on_rCritical_toggled(self, checked): """ - Private slot to handle the toggled signal of the rCritical radio button. + Private slot to handle the toggled signal of the rCritical + radio button. @param on toggle state (boolean) (ignored) """ @@ -170,7 +174,8 @@ @pyqtSlot(bool) def on_rYesNo_toggled(self, checked): """ - Private slot to handle the toggled signal of the rYesNo radio button. + Private slot to handle the toggled signal of the rYesNo + radio button. @param on toggle state (boolean) (ignored) """ @@ -179,7 +184,8 @@ @pyqtSlot(bool) def on_rRetryAbort_toggled(self, checked): """ - Private slot to handle the toggled signal of the rRetryAbort radio button. + Private slot to handle the toggled signal of the rRetryAbort + radio button. @param on toggle state (boolean) (ignored) """ @@ -188,7 +194,8 @@ @pyqtSlot(bool) def on_rOkToClearData_toggled(self, checked): """ - Private slot to handle the toggled signal of the rOkToClearData radio button. + Private slot to handle the toggled signal of the rOkToClearData + radio button. @param on toggle state (boolean) (ignored) """ @@ -197,7 +204,8 @@ @pyqtSlot(bool) def on_rAbout_toggled(self, checked): """ - Private slot to handle the toggled signal of the rAbout radio button. + Private slot to handle the toggled signal of the rAbout + radio button. @param on toggle state (boolean) (ignored) """ @@ -206,7 +214,8 @@ @pyqtSlot(bool) def on_rAboutQt_toggled(self, checked): """ - Private slot to handle the toggled signal of the rAboutQt radio button. + Private slot to handle the toggled signal of the rAboutQt + radio button. @param on toggle state (boolean) (ignored) """ @@ -215,7 +224,8 @@ @pyqtSlot(bool) def on_rStandard_toggled(self, checked): """ - Private slot to handle the toggled signal of the rStandard radio button. + Private slot to handle the toggled signal of the rStandard + radio button. @param on toggle state (boolean) (ignored) """ @@ -289,7 +299,8 @@ if buttons == E5MessageBox.NoButton: buttons = E5MessageBox.Ok - defaultButton = self.buttonsCodeListBinary[self.defaultCombo.currentIndex()] + defaultButton = self.buttonsCodeListBinary[ + self.defaultCombo.currentIndex()] if self.rInformation.isChecked(): E5MessageBox.information(self, @@ -403,10 +414,13 @@ istring2 = istring + indString joinstring = ' | \\{0}{1}'.format(os.linesep, istring2) if withIntro: - btnCode = ',{0}{1}E5MessageBox.StandardButtons('.format(os.linesep, istring) + btnCode = ',{0}{1}E5MessageBox.StandardButtons('.format( + os.linesep, istring) else: - btnCode = 'E5MessageBox.StandardButtons('.format(os.linesep, istring) - btnCode += '{0}{1}{2})'.format(os.linesep, istring2, joinstring.join(buttons)) + btnCode = 'E5MessageBox.StandardButtons('.format( + os.linesep, istring) + btnCode += '{0}{1}{2})'.format( + os.linesep, istring2, joinstring.join(buttons)) return btnCode @@ -459,27 +473,29 @@ if not self.rStandard.isChecked(): if self.rAbout.isChecked(): - msgdlg = "E5MessageBox.about({0},{1}".format(parent, os.linesep) + msgdlg = "E5MessageBox.about({0}".format(os.linesep) elif self.rAboutQt.isChecked(): - msgdlg = "E5MessageBox.aboutQt({0},{1}".format(parent, os.linesep) + msgdlg = "E5MessageBox.aboutQt({0}".format(os.linesep) elif self.rInformation.isChecked(): - msgdlg = "res = E5MessageBox.information({0},{1}".format( - parent, os.linesep) + msgdlg = "res = E5MessageBox.information({0}".format( + os.linesep) elif self.rQuestion.isChecked(): - msgdlg = "res = E5MessageBox.question({0},{1}".format(parent, os.linesep) + msgdlg = "res = E5MessageBox.question({0}".format(os.linesep) elif self.rWarning.isChecked(): - msgdlg = "res = E5MessageBox.warning({0},{1}".format(parent, os.linesep) + msgdlg = "res = E5MessageBox.warning({0}".format(os.linesep) elif self.rCritical.isChecked(): - msgdlg = "res = E5MessageBox.critical({0},{1}".format(parent, os.linesep) + msgdlg = "res = E5MessageBox.critical({0}".format(os.linesep) elif self.rYesNo.isChecked(): - msgdlg = "res = E5MessageBox.yesNo({0},{1}".format(parent, os.linesep) + msgdlg = "res = E5MessageBox.yesNo({0}".format(os.linesep) elif self.rRetryAbort.isChecked(): - msgdlg = "res = E5MessageBox.retryAbort({0},{1}".format(parent, os.linesep) + msgdlg = "res = E5MessageBox.retryAbort({0}".format(os.linesep) elif self.rOkToClearData.isChecked(): - msgdlg = "res = E5MessageBox.okToClearData({0},{1}".format( - parent, os.linesep) + msgdlg = "res = E5MessageBox.okToClearData({0}".format( + os.linesep) - msgdlg += '{0}self.trUtf8("{1}")'.format(istring, self.eCaption.text()) + msgdlg += '{0}{1}{2}'.format(istring, parent, os.linesep) + msgdlg += '{0}self.trUtf8("{1}")'.format( + istring, self.eCaption.text()) if not self.rAboutQt.isChecked(): msgdlg += ',{0}{1}self.trUtf8("""{2}""")'.format( @@ -493,29 +509,37 @@ msgdlg += self.__getDefaultButtonCode(istring) elif self.rYesNo.isChecked(): if not self.iconQuestion.isChecked(): - msgdlg += ',{0}{1}icon={2}'.format(os.linesep, istring, icon) + msgdlg += ',{0}{1}icon={2}'.format( + os.linesep, istring, icon) if self.yesDefaultCheck.isChecked(): - msgdlg += ',{0}{1}yesDefault=True'.format(os.linesep, istring) + msgdlg += ',{0}{1}yesDefault=True'.format( + os.linesep, istring) elif self.rRetryAbort.isChecked(): if not self.iconQuestion.isChecked(): - msgdlg += ',{0}{1}icon={2}'.format(os.linesep, istring, icon) + msgdlg += ',{0}{1}icon={2}'.format( + os.linesep, istring, icon) elif self.rOkToClearData.isChecked(): saveFunc = self.saveFuncEdit.text() if saveFunc == "": saveFunc = "lambda: True" msgdlg += ',{0}{1}{2}'.format(os.linesep, istring, saveFunc) else: - msgdlg = "E5MessageBox.E5MessageBox({0}, {1}".format(icon, os.linesep) - msgdlg += '{0}self.trUtf8("{1}")'.format(istring, self.eCaption.text()) + msgdlg = "E5MessageBox.E5MessageBox({0}".format(os.linesep) + msgdlg += '{0}{1}{2}'.format(istring, icon, os.linesep) + msgdlg += '{0}self.trUtf8("{1}")'.format( + istring, self.eCaption.text()) msgdlg += ',{0}{1}self.trUtf8("""{2}""")'.format( os.linesep, istring, self.eMessage.toPlainText()) if self.modalCheck.isChecked(): msgdlg += ',{0}{1}modal=True'.format(os.linesep, istring) - btnCode = self.__getStandardButtonCode(istring, indString, withIntro=False) + btnCode = self.__getStandardButtonCode( + istring, indString, withIntro=False) if btnCode: - msgdlg += ',{0}{1}buttons={2}'.format(os.linesep, istring, btnCode) + msgdlg += ',{0}{1}buttons={2}'.format( + os.linesep, istring, btnCode) if not self.parentNone.isChecked(): - msgdlg += ',{0}{1}parent={2}'.format(os.linesep, istring, parent) + msgdlg += ',{0}{1}parent={2}'.format( + os.linesep, istring, parent) msgdlg += '){0}'.format(estring) return msgdlg
--- a/Plugins/WizardPlugins/FileDialogWizard/FileDialogWizardDialog.py Sat Sep 07 14:50:51 2013 +0200 +++ b/Plugins/WizardPlugins/FileDialogWizard/FileDialogWizardDialog.py Sat Sep 07 15:47:53 2013 +0200 @@ -45,8 +45,8 @@ self.cWorkDir.toggled[bool].connect(self.__toggleGroupsAndTest) self.cFilters.toggled[bool].connect(self.__toggleGroupsAndTest) - self.bTest = \ - self.buttonBox.addButton(self.trUtf8("Test"), QDialogButtonBox.ActionRole) + self.bTest = self.buttonBox.addButton( + self.trUtf8("Test"), QDialogButtonBox.ActionRole) def __adjustOptions(self, options): """ @@ -164,7 +164,8 @@ if self.rOpenFile.isChecked(): code += 'getOpenFileName({0}{1}'.format(os.linesep, istring) else: - code += 'getOpenFileNameAndFilter({0}{1}'.format(os.linesep, istring) + code += 'getOpenFileNameAndFilter({0}{1}'.format( + os.linesep, istring) code += 'None,{0}{1}'.format(os.linesep, istring) if not self.eCaption.text(): code += '"",{0}{1}'.format(os.linesep, istring) @@ -190,14 +191,17 @@ if self.rfOpenFile.isChecked(): code += ',{0}{1}None'.format(os.linesep, istring) if not self.cSymlinks.isChecked(): - code += ',{0}{1}QFileDialog.Options(QFileDialog.DontResolveSymlinks)'\ - .format(os.linesep, istring) + code += \ + ',{0}{1}QFileDialog.Options(' \ + 'QFileDialog.DontResolveSymlinks)' \ + .format(os.linesep, istring) code += '){0}'.format(estring) elif self.rOpenFiles.isChecked() or self.rfOpenFiles.isChecked(): if self.rOpenFiles.isChecked(): code += 'getOpenFileNames({0}{1}'.format(os.linesep, istring) else: - code += 'getOpenFileNamesAndFilter({0}{1}'.format(os.linesep, istring) + code += 'getOpenFileNamesAndFilter({0}{1}'.format( + os.linesep, istring) code += 'None,{0}{1}'.format(os.linesep, istring) if not self.eCaption.text(): code += '"",{0}{1}'.format(os.linesep, istring) @@ -223,14 +227,17 @@ if self.rfOpenFiles.isChecked(): code += ',{0}{1}None'.format(os.linesep, istring) if not self.cSymlinks.isChecked(): - code += ',{0}{1}QFileDialog.Options(QFileDialog.DontResolveSymlinks)'\ - .format(os.linesep, istring) + code += \ + ',{0}{1}QFileDialog.Options(' \ + 'QFileDialog.DontResolveSymlinks)' \ + .format(os.linesep, istring) code += '){0}'.format(estring) elif self.rSaveFile.isChecked() or self.rfSaveFile.isChecked(): if self.rSaveFile.isChecked(): code += 'getSaveFileName({0}{1}'.format(os.linesep, istring) else: - code += 'getSaveFileNameAndFilter({0}{1}'.format(os.linesep, istring) + code += 'getSaveFileNameAndFilter({0}{1}'.format( + os.linesep, istring) code += 'None,{0}{1}'.format(os.linesep, istring) if not self.eCaption.text(): code += '"",{0}{1}'.format(os.linesep, istring) @@ -257,7 +264,8 @@ code += ',{0}{1}None'.format(os.linesep, istring) if (not self.cSymlinks.isChecked()) or \ (not self.cConfirmOverwrite.isChecked()): - code += ',{0}{1}QFileDialog.Options('.format(os.linesep, istring) + code += ',{0}{1}QFileDialog.Options('.format( + os.linesep, istring) if not self.cSymlinks.isChecked(): code += 'QFileDialog.DontResolveSymlinks' if (not self.cSymlinks.isChecked()) and \
--- a/Plugins/WizardPlugins/FontDialogWizard/FontDialogWizardDialog.py Sat Sep 07 14:50:51 2013 +0200 +++ b/Plugins/WizardPlugins/FontDialogWizard/FontDialogWizardDialog.py Sat Sep 07 15:47:53 2013 +0200 @@ -31,8 +31,8 @@ super().__init__(parent) self.setupUi(self) - self.bTest = \ - self.buttonBox.addButton(self.trUtf8("Test"), QDialogButtonBox.ActionRole) + self.bTest = self.buttonBox.addButton( + self.trUtf8("Test"), QDialogButtonBox.ActionRole) self.font = None @@ -69,8 +69,8 @@ @pyqtSlot() def on_fontButton_clicked(self): """ - Private slot to handle the button press to select a font via a font selection - dialog. + Private slot to handle the button press to select a font via a + font selection dialog. """ if self.font is None: font, ok = QFontDialog.getFont()
--- a/Plugins/WizardPlugins/InputDialogWizard/InputDialogWizardDialog.py Sat Sep 07 14:50:51 2013 +0200 +++ b/Plugins/WizardPlugins/InputDialogWizard/InputDialogWizardDialog.py Sat Sep 07 15:47:53 2013 +0200 @@ -40,8 +40,8 @@ self.eDoubleTo.setValidator( QDoubleValidator(-2147483647, 2147483647, 99, self.eDoubleTo)) - self.bTest = \ - self.buttonBox.addButton(self.trUtf8("Test"), QDialogButtonBox.ActionRole) + self.bTest = self.buttonBox.addButton( + self.trUtf8("Test"), QDialogButtonBox.ActionRole) @pyqtSlot(bool) def on_rItem_toggled(self, checked): @@ -181,7 +181,8 @@ self.eCaption.text(), os.linesep, istring) code += 'self.trUtf8("{0}"),{1}{2}'.format( self.eLabel.text(), os.linesep, istring) - code += '{0},{1}{2}'.format(self.eVariable.text(), os.linesep, istring) + code += '{0},{1}{2}'.format( + self.eVariable.text(), os.linesep, istring) code += '{0:d}, {1}){2}'.format( self.sCurrentItem.value(), self.cEditable.isChecked(), estring)
--- a/Plugins/WizardPlugins/MessageBoxWizard/MessageBoxWizardDialog.py Sat Sep 07 14:50:51 2013 +0200 +++ b/Plugins/WizardPlugins/MessageBoxWizard/MessageBoxWizardDialog.py Sat Sep 07 15:47:53 2013 +0200 @@ -98,8 +98,8 @@ self.defaultCombo.addItems(self.buttonsList) - self.bTest = \ - self.buttonBox.addButton(self.trUtf8("Test"), QDialogButtonBox.ActionRole) + self.bTest = self.buttonBox.addButton( + self.trUtf8("Test"), QDialogButtonBox.ActionRole) def __testQt42(self): """ @@ -145,31 +145,36 @@ if buttons == QMessageBox.NoButton: buttons = QMessageBox.Ok - defaultButton = self.buttonsCodeListBinary[self.defaultCombo.currentIndex()] + defaultButton = self.buttonsCodeListBinary[ + self.defaultCombo.currentIndex()] if self.rInformation.isChecked(): - QMessageBox.information(self, + QMessageBox.information( + self, self.eCaption.text(), self.eMessage.toPlainText(), QMessageBox.StandardButtons(buttons), defaultButton ) elif self.rQuestion.isChecked(): - QMessageBox.question(self, + QMessageBox.question( + self, self.eCaption.text(), self.eMessage.toPlainText(), QMessageBox.StandardButtons(buttons), defaultButton ) elif self.rWarning.isChecked(): - QMessageBox.warning(self, + QMessageBox.warning( + self, self.eCaption.text(), self.eMessage.toPlainText(), QMessageBox.StandardButtons(buttons), defaultButton ) elif self.rCritical.isChecked(): - QMessageBox.critical(self, + QMessageBox.critical( + self, self.eCaption.text(), self.eMessage.toPlainText(), QMessageBox.StandardButtons(buttons), @@ -191,12 +196,14 @@ Private method to test the selected options. """ if self.rAbout.isChecked(): - QMessageBox.about(None, + QMessageBox.about( + None, self.eCaption.text(), self.eMessage.toPlainText() ) elif self.rAboutQt.isChecked(): - QMessageBox.aboutQt(None, + QMessageBox.aboutQt( + None, self.eCaption.text() ) else: @@ -206,9 +213,9 @@ """ Private method to enable/disable some group boxes. """ - self.standardButtons.setEnabled(not self.rAbout.isChecked() and \ + self.standardButtons.setEnabled(not self.rAbout.isChecked() and not self.rAboutQt.isChecked() - ) + ) self.eMessage.setEnabled(not self.rAboutQt.isChecked()) @@ -278,11 +285,14 @@ istring2 = istring + indString joinstring = ' | \\{0}{1}'.format(os.linesep, istring2) - btnCode = ',{0}{1}QMessageBox.StandardButtons('.format(os.linesep, istring) - btnCode += '{0}{1}{2})'.format(os.linesep, istring2, joinstring.join(buttons)) + btnCode = ',{0}{1}QMessageBox.StandardButtons('.format( + os.linesep, istring) + btnCode += '{0}{1}{2})'.format( + os.linesep, istring2, joinstring.join(buttons)) defaultIndex = self.defaultCombo.currentIndex() if defaultIndex: - btnCode += ',{0}{1}{2}'.format(os.linesep, istring, + btnCode += ',{0}{1}{2}'.format( + os.linesep, istring, self.buttonsCodeListText[defaultIndex]) return btnCode @@ -310,18 +320,19 @@ parent = "None" if self.rAbout.isChecked(): - msgdlg = "QMessageBox.about({0},{1}".format(parent, os.linesep) + msgdlg = "QMessageBox.about({0}".format(os.linesep) elif self.rAboutQt.isChecked(): - msgdlg = "QMessageBox.aboutQt({0},{1}".format(parent, os.linesep) + msgdlg = "QMessageBox.aboutQt({0}".format(os.linesep) elif self.rInformation.isChecked(): - msgdlg = "res = QMessageBox.information({0},{1}".format(parent, os.linesep) + msgdlg = "res = QMessageBox.information({0}".format(os.linesep) elif self.rQuestion.isChecked(): - msgdlg = "res = QMessageBox.question({0},{1}".format(parent, os.linesep) + msgdlg = "res = QMessageBox.question({0}".format(os.linesep) elif self.rWarning.isChecked(): - msgdlg = "res = QMessageBox.warning({0},{1}".format(parent, os.linesep) + msgdlg = "res = QMessageBox.warning({0}".format(os.linesep) else: - msgdlg = "res = QMessageBox.critical({0},{1}".format(parent, os.linesep) + msgdlg = "res = QMessageBox.critical({0}".format(os.linesep) + msgdlg += '{0}{1}{2}'.format(istring, parent, os.linesep) msgdlg += '{0}self.trUtf8("{1}")'.format(istring, self.eCaption.text()) if not self.rAboutQt.isChecked(): msgdlg += ',{0}{1}self.trUtf8("""{2}""")'.format(
--- a/Plugins/WizardPlugins/PyRegExpWizard/PyRegExpWizardDialog.py Sat Sep 07 14:50:51 2013 +0200 +++ b/Plugins/WizardPlugins/PyRegExpWizard/PyRegExpWizardDialog.py Sat Sep 07 15:47:53 2013 +0200 @@ -11,8 +11,8 @@ import re from PyQt4.QtCore import QFileInfo, pyqtSlot -from PyQt4.QtGui import QWidget, QDialog, QInputDialog, QApplication, QClipboard, \ - QTextCursor, QDialogButtonBox, QVBoxLayout, QTableWidgetItem +from PyQt4.QtGui import QWidget, QDialog, QInputDialog, QApplication, \ + QClipboard, QTextCursor, QDialogButtonBox, QVBoxLayout, QTableWidgetItem from E5Gui import E5MessageBox, E5FileDialog from E5Gui.E5MainWindow import E5MainWindow @@ -47,36 +47,46 @@ self.nonGroupButton.setIcon(UI.PixmapCache.getIcon("nongroup.png")) self.groupButton.setIcon(UI.PixmapCache.getIcon("group.png")) self.namedGroupButton.setIcon(UI.PixmapCache.getIcon("namedgroup.png")) - self.namedReferenceButton.setIcon(UI.PixmapCache.getIcon("namedreference.png")) + self.namedReferenceButton.setIcon( + UI.PixmapCache.getIcon("namedreference.png")) 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.poslookbehindButton.setIcon(UI.PixmapCache.getIcon("poslookbehind.png")) - self.neglookbehindButton.setIcon(UI.PixmapCache.getIcon("neglookbehind.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.poslookbehindButton.setIcon( + UI.PixmapCache.getIcon("poslookbehind.png")) + self.neglookbehindButton.setIcon( + UI.PixmapCache.getIcon("neglookbehind.png")) self.undoButton.setIcon(UI.PixmapCache.getIcon("editUndo.png")) self.redoButton.setIcon(UI.PixmapCache.getIcon("editRedo.png")) self.namedGroups = re.compile(r"""\(?P<([^>]+)>""").findall - 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) @@ -86,8 +96,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) @@ -161,11 +171,13 @@ # determine cursor position as length into text length = self.regexpTextEdit.textCursor().position() - # only present group names that occur before the current cursor position + # only present group names that occur before the + # current cursor position regex = self.regexpTextEdit.toPlainText()[:length] names = self.namedGroups(regex) if not names: - E5MessageBox.information(self, + E5MessageBox.information( + self, self.trUtf8("Named reference"), self.trUtf8("""No named groups have been defined yet.""")) return @@ -257,7 +269,8 @@ """ Private slot to handle the characters toolbutton. """ - from .PyRegExpWizardCharactersDialog import PyRegExpWizardCharactersDialog + from .PyRegExpWizardCharactersDialog import \ + PyRegExpWizardCharactersDialog dlg = PyRegExpWizardCharactersDialog(self) if dlg.exec_() == QDialog.Accepted: self.__insertString(dlg.getCharacters()) @@ -314,23 +327,27 @@ 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 try: - f = open(Utilities.toNativeSeparators(fname), "w", encoding="utf-8") + f = open( + Utilities.toNativeSeparators(fname), "w", encoding="utf-8") f.write(self.regexpTextEdit.toPlainText()) 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): @@ -344,15 +361,18 @@ 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() self.regexpTextEdit.setPlainText(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): @@ -395,22 +415,27 @@ if self.unicodeCheckBox.isChecked(): flags |= re.ASCII re.compile(regex, flags) - E5MessageBox.information(self, + E5MessageBox.information( + self, self.trUtf8("Validation"), self.trUtf8("""The regular expression is valid.""")) except re.error as e: - E5MessageBox.critical(self, + E5MessageBox.critical( + self, self.trUtf8("Error"), self.trUtf8("""Invalid regular expression: {0}""") - .format(str(e))) + .format(str(e))) return except IndexError: - E5MessageBox.critical(self, + E5MessageBox.critical( + self, self.trUtf8("Error"), - self.trUtf8("""Invalid regular expression: missing group name""")) + self.trUtf8("""Invalid regular expression: missing""" + """ group name""")) return else: - E5MessageBox.critical(self, + E5MessageBox.critical( + self, self.trUtf8("Error"), self.trUtf8("""A regular expression must be given.""")) @@ -460,48 +485,63 @@ 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, 1, QTableWidgetItem(regex)) + self.resultTable.setItem( + row, 0, QTableWidgetItem(self.trUtf8("Regexp"))) + self.resultTable.setItem( + row, 1, QTableWidgetItem(regex)) if matchobj is not None: offset = matchobj.start() self.lastMatchEnd = matchobj.end() self.nextButton.setEnabled(True) row += 1 - self.resultTable.setItem(row, 0, + self.resultTable.setItem( + row, 0, QTableWidgetItem(self.trUtf8("Offset"))) - self.resultTable.setItem(row, 1, + self.resultTable.setItem( + row, 1, QTableWidgetItem("{0:d}".format(matchobj.start(0)))) row += 1 - self.resultTable.setItem(row, 0, + self.resultTable.setItem( + row, 0, QTableWidgetItem(self.trUtf8("Captures"))) - self.resultTable.setItem(row, 1, + self.resultTable.setItem( + row, 1, QTableWidgetItem("{0:d}".format(captures))) row += 1 - self.resultTable.setItem(row, 1, + self.resultTable.setItem( + row, 1, QTableWidgetItem(self.trUtf8("Text"))) - self.resultTable.setItem(row, 2, + self.resultTable.setItem( + row, 2, QTableWidgetItem(self.trUtf8("Characters"))) row += 1 - self.resultTable.setItem(row, 0, + self.resultTable.setItem( + row, 0, QTableWidgetItem(self.trUtf8("Match"))) - self.resultTable.setItem(row, 1, + self.resultTable.setItem( + row, 1, QTableWidgetItem(matchobj.group(0))) - self.resultTable.setItem(row, 2, - QTableWidgetItem("{0:d}".format(len(matchobj.group(0))))) + self.resultTable.setItem( + row, 2, + QTableWidgetItem( + "{0:d}".format(len(matchobj.group(0))))) for i in range(1, captures + 1): if matchobj.group(i) is not None: row += 1 self.resultTable.insertRow(row) - self.resultTable.setItem(row, 0, - QTableWidgetItem(self.trUtf8("Capture #{0}").format(i))) - self.resultTable.setItem(row, 1, - QTableWidgetItem(matchobj.group(i))) - self.resultTable.setItem(row, 2, - QTableWidgetItem("{0:d}".format(len(matchobj.group(i))))) + self.resultTable.setItem( + row, 0, + QTableWidgetItem( + self.trUtf8("Capture #{0}").format(i))) + self.resultTable.setItem( + row, 1, QTableWidgetItem(matchobj.group(i))) + self.resultTable.setItem( + row, 2, QTableWidgetItem( + "{0:d}".format(len(matchobj.group(i))))) # highlight the matched text tc = self.textTextEdit.textCursor() @@ -513,10 +553,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 @@ -529,20 +571,25 @@ self.resultTable.verticalHeader().hide() self.resultTable.horizontalHeader().hide() except re.error as e: - E5MessageBox.critical(self, + E5MessageBox.critical( + self, self.trUtf8("Error"), self.trUtf8("""Invalid regular expression: {0}""") - .format(str(e))) + .format(str(e))) return except IndexError: - E5MessageBox.critical(self, + E5MessageBox.critical( + self, self.trUtf8("Error"), - self.trUtf8("""Invalid regular expression: missing group name""")) + self.trUtf8("""Invalid regular expression: missing""" + """ group name""")) return 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): @@ -687,7 +734,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)
--- 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)
--- a/Plugins/WizardPlugins/QRegularExpressionWizard/QRegularExpressionWizardDialog.py Sat Sep 07 14:50:51 2013 +0200 +++ b/Plugins/WizardPlugins/QRegularExpressionWizard/QRegularExpressionWizardDialog.py Sat Sep 07 15:47:53 2013 +0200 @@ -13,13 +13,14 @@ import json from PyQt4.QtCore import QFileInfo, pyqtSlot, qVersion, QProcess, QByteArray -from PyQt4.QtGui import QWidget, QDialog, QInputDialog, QApplication, QClipboard, \ - QTextCursor, QDialogButtonBox, QVBoxLayout, QTableWidgetItem +from PyQt4.QtGui import QWidget, QDialog, QInputDialog, QApplication, \ + QClipboard, QTextCursor, QDialogButtonBox, QVBoxLayout, QTableWidgetItem from E5Gui import E5MessageBox, E5FileDialog from E5Gui.E5MainWindow import E5MainWindow -from .Ui_QRegularExpressionWizardDialog import Ui_QRegularExpressionWizardDialog +from .Ui_QRegularExpressionWizardDialog import \ + Ui_QRegularExpressionWizardDialog import UI.PixmapCache @@ -27,7 +28,8 @@ import Preferences -class QRegularExpressionWizardWidget(QWidget, Ui_QRegularExpressionWizardDialog): +class QRegularExpressionWizardWidget(QWidget, + Ui_QRegularExpressionWizardDialog): """ Class implementing the QRegularExpression wizard dialog. """ @@ -47,19 +49,27 @@ self.anycharButton.setIcon(UI.PixmapCache.getIcon("anychar.png")) self.repeatButton.setIcon(UI.PixmapCache.getIcon("repeat.png")) self.nonGroupButton.setIcon(UI.PixmapCache.getIcon("nongroup.png")) - self.atomicGroupButton.setIcon(UI.PixmapCache.getIcon("atomicgroup.png")) + self.atomicGroupButton.setIcon( + UI.PixmapCache.getIcon("atomicgroup.png")) self.groupButton.setIcon(UI.PixmapCache.getIcon("group.png")) self.namedGroupButton.setIcon(UI.PixmapCache.getIcon("namedgroup.png")) - self.namedReferenceButton.setIcon(UI.PixmapCache.getIcon("namedreference.png")) + self.namedReferenceButton.setIcon( + UI.PixmapCache.getIcon("namedreference.png")) 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.poslookbehindButton.setIcon(UI.PixmapCache.getIcon("poslookbehind.png")) - self.neglookbehindButton.setIcon(UI.PixmapCache.getIcon("neglookbehind.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.poslookbehindButton.setIcon( + UI.PixmapCache.getIcon("poslookbehind.png")) + self.neglookbehindButton.setIcon( + UI.PixmapCache.getIcon("neglookbehind.png")) self.undoButton.setIcon(UI.PixmapCache.getIcon("editUndo.png")) self.redoButton.setIcon(UI.PixmapCache.getIcon("editRedo.png")) @@ -68,8 +78,10 @@ # start the PyQt5 server part self.__pyqt5Available = False self.__pyqt5Server = QProcess(self) - self.__pyqt5Server.start(sys.executable, [ - os.path.join(os.path.dirname(__file__), "QRegularExpressionWizardServer.py")]) + self.__pyqt5Server.start( + sys.executable, [os.path.join( + os.path.dirname(__file__), "QRegularExpressionWizardServer.py") + ]) if self.__pyqt5Server.waitForStarted(5000): self.__pyqt5Server.setReadChannel(QProcess.StandardOutput) if self.__sendCommand("available"): @@ -77,19 +89,23 @@ if response and response["available"]: self.__pyqt5Available = True - 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.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")) if qVersion() >= "5.0.0" and self.__pyqt5Available: self.validateButton = self.buttonBox.addButton( self.trUtf8("Validate"), QDialogButtonBox.ActionRole) - self.validateButton.setToolTip(self.trUtf8("Validate the regular expression")) + 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.executeButton.setToolTip( + self.trUtf8("Execute the regular expression")) self.nextButton = self.buttonBox.addButton( self.trUtf8("Next match"), QDialogButtonBox.ActionRole) self.nextButton.setToolTip( @@ -105,8 +121,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) @@ -119,7 +135,8 @@ """ Private method to send a command to the PyQt5 server. - @param commandDict dictionary with command string and related data (dict) + @param commandDict dictionary with command string and related + data (dict) @return flag indicating a successful transmission (boolean) """ result = False @@ -144,10 +161,12 @@ responseStr = data.decode("utf-8") responseDict = json.loads(responseStr) if responseDict["error"]: - E5MessageBox.critical(self, + E5MessageBox.critical( + self, self.trUtf8("Communication Error"), - self.trUtf8("""<p>The PyQt5 backend reported an error.</p>""" - """<p>{0}</p>""").format(responseDict["error"])) + self.trUtf8("""<p>The PyQt5 backend reported""" + """ an error.</p><p>{0}</p>""") + .format(responseDict["error"])) responseDict = {} return responseDict @@ -252,11 +271,13 @@ # determine cursor position as length into text length = self.regexpTextEdit.textCursor().position() - # only present group names that occur before the current cursor position + # only present group names that occur before the current + # cursor position regex = self.regexpTextEdit.toPlainText()[:length] names = self.namedGroups(regex) if not names: - E5MessageBox.information(self, + E5MessageBox.information( + self, self.trUtf8("Named reference"), self.trUtf8("""No named groups have been defined yet.""")) return @@ -385,23 +406,27 @@ 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 try: - f = open(Utilities.toNativeSeparators(fname), "w", encoding="utf-8") + f = open( + Utilities.toNativeSeparators(fname), "w", encoding="utf-8") f.write(self.regexpTextEdit.toPlainText()) 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): @@ -415,15 +440,18 @@ 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() self.regexpTextEdit.setPlainText(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): @@ -471,14 +499,17 @@ response = self.__receiveResponse() if response and "valid" in response: if response["valid"]: - E5MessageBox.information(self, + E5MessageBox.information( + self, self.trUtf8("Validation"), - self.trUtf8("""The regular expression is valid.""")) + self.trUtf8( + """The regular expression is valid.""")) else: - E5MessageBox.critical(self, + E5MessageBox.critical( + self, self.trUtf8("Error"), self.trUtf8("""Invalid regular expression: {0}""") - .format(response["errorMessage"])) + .format(response["errorMessage"])) # move cursor to error offset offset = response["errorOffset"] tc = self.regexpTextEdit.textCursor() @@ -487,25 +518,31 @@ self.regexpTextEdit.setFocus() return else: - E5MessageBox.critical(self, + E5MessageBox.critical( + self, self.trUtf8("Communication Error"), - self.trUtf8("""Invalid response received from PyQt5 backend.""")) + self.trUtf8("""Invalid response received from""" + """ PyQt5 backend.""")) else: - E5MessageBox.critical(self, + E5MessageBox.critical( + self, self.trUtf8("Communication Error"), - self.trUtf8("""Communication with PyQt5 backend failed.""")) + self.trUtf8("""Communication with PyQt5 backend""" + """ failed.""")) else: - E5MessageBox.critical(self, + E5MessageBox.critical( + self, self.trUtf8("Error"), self.trUtf8("""A regular expression must be given.""")) @pyqtSlot() def on_executeButton_clicked(self, startpos=0): """ - Private slot to execute the entered QRegularExpression on the test text. + Private slot to execute the entered QRegularExpression on the test + text. - This slot will execute the entered QRegularExpression on the entered test - data and will display the result in the table part of the dialog. + This slot will execute the entered QRegularExpression on the entered + test data and will display the result in the table part of the dialog. @param startpos starting position for the QRegularExpression matching """ @@ -537,10 +574,11 @@ response = self.__receiveResponse() if response and ("valid" in response or "matched" in response): if "valid" in response: - E5MessageBox.critical(self, + E5MessageBox.critical( + self, self.trUtf8("Error"), self.trUtf8("""Invalid regular expression: {0}""") - .format(response["errorMessage"])) + .format(response["errorMessage"])) # move cursor to error offset offset = response["errorOffset"] tc = self.regexpTextEdit.textCursor() @@ -567,57 +605,78 @@ self.lastMatchEnd = captures[0][2] self.nextButton.setEnabled(True) row += 1 - self.resultTable.setItem(row, 0, + self.resultTable.setItem( + row, 0, QTableWidgetItem(self.trUtf8("Offset"))) - self.resultTable.setItem(row, 1, + self.resultTable.setItem( + row, 1, QTableWidgetItem("{0:d}".format(offset))) row += 1 - self.resultTable.setItem(row, 0, + self.resultTable.setItem( + row, 0, QTableWidgetItem(self.trUtf8("Captures"))) - self.resultTable.setItem(row, 1, - QTableWidgetItem("{0:d}".format(len(captures) - 1))) + self.resultTable.setItem( + row, 1, + QTableWidgetItem( + "{0:d}".format(len(captures) - 1))) row += 1 - self.resultTable.setItem(row, 1, + self.resultTable.setItem( + row, 1, QTableWidgetItem(self.trUtf8("Text"))) - self.resultTable.setItem(row, 2, + self.resultTable.setItem( + row, 2, QTableWidgetItem(self.trUtf8("Characters"))) row += 1 - self.resultTable.setItem(row, 0, + self.resultTable.setItem( + row, 0, QTableWidgetItem(self.trUtf8("Match"))) - self.resultTable.setItem(row, 1, + self.resultTable.setItem( + row, 1, QTableWidgetItem(captures[0][0])) - self.resultTable.setItem(row, 2, - QTableWidgetItem("{0:d}".format(captures[0][3]))) + self.resultTable.setItem( + row, 2, + QTableWidgetItem( + "{0:d}".format(captures[0][3]))) for i in range(1, len(captures)): if captures[i][0]: row += 1 self.resultTable.insertRow(row) - self.resultTable.setItem(row, 0, + self.resultTable.setItem( + row, 0, QTableWidgetItem( - self.trUtf8("Capture #{0}").format(i))) - self.resultTable.setItem(row, 1, + self.trUtf8("Capture #{0}") + .format(i))) + self.resultTable.setItem( + row, 1, QTableWidgetItem(captures[i][0])) - self.resultTable.setItem(row, 2, - QTableWidgetItem("{0:d}".format(captures[i][3]))) + self.resultTable.setItem( + row, 2, + QTableWidgetItem( + "{0:d}".format(captures[i][3]))) # highlight the matched text tc = self.textTextEdit.textCursor() tc.setPosition(offset) - tc.setPosition(self.lastMatchEnd, QTextCursor.KeepAnchor) + tc.setPosition( + self.lastMatchEnd, QTextCursor.KeepAnchor) self.textTextEdit.setTextCursor(tc) else: self.nextButton.setEnabled(False) self.resultTable.setRowCount(2) row += 1 if startpos > 0: - self.resultTable.setItem(row, 0, - QTableWidgetItem(self.trUtf8("No more matches"))) + self.resultTable.setItem( + row, 0, + QTableWidgetItem( + self.trUtf8("No more matches"))) else: - self.resultTable.setItem(row, 0, - QTableWidgetItem(self.trUtf8("No matches"))) + self.resultTable.setItem( + row, 0, + QTableWidgetItem( + self.trUtf8("No matches"))) # remove the highlight tc = self.textTextEdit.textCursor() @@ -629,17 +688,23 @@ self.resultTable.verticalHeader().hide() self.resultTable.horizontalHeader().hide() else: - E5MessageBox.critical(self, + E5MessageBox.critical( + self, self.trUtf8("Communication Error"), - self.trUtf8("""Invalid response received from PyQt5 backend.""")) + self.trUtf8("""Invalid response received from""" + """ PyQt5 backend.""")) else: - E5MessageBox.critical(self, + E5MessageBox.critical( + self, self.trUtf8("Communication Error"), - self.trUtf8("""Communication with PyQt5 backend failed.""")) + self.trUtf8("""Communication with PyQt5""" + """ backend failed.""")) 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): @@ -770,7 +835,8 @@ self.resize(size) self.setWindowTitle(self.cw.windowTitle()) - 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)