82 self.syntaxCombo.addItem("W3C XML Schema 1.1", QRegExp.W3CXmlSchema11) |
82 self.syntaxCombo.addItem("W3C XML Schema 1.1", QRegExp.W3CXmlSchema11) |
83 if qVersion() >= "5.0.0": |
83 if qVersion() >= "5.0.0": |
84 self.syntaxCombo.setCurrentIndex(1) |
84 self.syntaxCombo.setCurrentIndex(1) |
85 |
85 |
86 self.saveButton = self.buttonBox.addButton( |
86 self.saveButton = self.buttonBox.addButton( |
87 self.trUtf8("Save"), QDialogButtonBox.ActionRole) |
87 self.tr("Save"), QDialogButtonBox.ActionRole) |
88 self.saveButton.setToolTip( |
88 self.saveButton.setToolTip( |
89 self.trUtf8("Save the regular expression to a file")) |
89 self.tr("Save the regular expression to a file")) |
90 self.loadButton = self.buttonBox.addButton( |
90 self.loadButton = self.buttonBox.addButton( |
91 self.trUtf8("Load"), QDialogButtonBox.ActionRole) |
91 self.tr("Load"), QDialogButtonBox.ActionRole) |
92 self.loadButton.setToolTip( |
92 self.loadButton.setToolTip( |
93 self.trUtf8("Load a regular expression from a file")) |
93 self.tr("Load a regular expression from a file")) |
94 self.validateButton = self.buttonBox.addButton( |
94 self.validateButton = self.buttonBox.addButton( |
95 self.trUtf8("Validate"), QDialogButtonBox.ActionRole) |
95 self.tr("Validate"), QDialogButtonBox.ActionRole) |
96 self.validateButton.setToolTip( |
96 self.validateButton.setToolTip( |
97 self.trUtf8("Validate the regular expression")) |
97 self.tr("Validate the regular expression")) |
98 self.executeButton = self.buttonBox.addButton( |
98 self.executeButton = self.buttonBox.addButton( |
99 self.trUtf8("Execute"), QDialogButtonBox.ActionRole) |
99 self.tr("Execute"), QDialogButtonBox.ActionRole) |
100 self.executeButton.setToolTip( |
100 self.executeButton.setToolTip( |
101 self.trUtf8("Execute the regular expression")) |
101 self.tr("Execute the regular expression")) |
102 self.nextButton = self.buttonBox.addButton( |
102 self.nextButton = self.buttonBox.addButton( |
103 self.trUtf8("Next match"), QDialogButtonBox.ActionRole) |
103 self.tr("Next match"), QDialogButtonBox.ActionRole) |
104 self.nextButton.setToolTip( |
104 self.nextButton.setToolTip( |
105 self.trUtf8("Show the next match of the regular expression")) |
105 self.tr("Show the next match of the regular expression")) |
106 self.nextButton.setEnabled(False) |
106 self.nextButton.setEnabled(False) |
107 |
107 |
108 if fromEric: |
108 if fromEric: |
109 self.buttonBox.setStandardButtons( |
109 self.buttonBox.setStandardButtons( |
110 QDialogButtonBox.Cancel | QDialogButtonBox.Ok) |
110 QDialogButtonBox.Cancel | QDialogButtonBox.Ok) |
111 self.copyButton = None |
111 self.copyButton = None |
112 else: |
112 else: |
113 self.copyButton = self.buttonBox.addButton( |
113 self.copyButton = self.buttonBox.addButton( |
114 self.trUtf8("Copy"), QDialogButtonBox.ActionRole) |
114 self.tr("Copy"), QDialogButtonBox.ActionRole) |
115 self.copyButton.setToolTip( |
115 self.copyButton.setToolTip( |
116 self.trUtf8("Copy the regular expression to the clipboard")) |
116 self.tr("Copy the regular expression to the clipboard")) |
117 self.buttonBox.setStandardButtons(QDialogButtonBox.Close) |
117 self.buttonBox.setStandardButtons(QDialogButtonBox.Close) |
118 self.variableLabel.hide() |
118 self.variableLabel.hide() |
119 self.variableLineEdit.hide() |
119 self.variableLineEdit.hide() |
120 self.variableLine.hide() |
120 self.variableLine.hide() |
121 self.regexpLineEdit.setFocus() |
121 self.regexpLineEdit.setFocus() |
367 f.write(self.regexpLineEdit.text()) |
367 f.write(self.regexpLineEdit.text()) |
368 f.close() |
368 f.close() |
369 except IOError as err: |
369 except IOError as err: |
370 E5MessageBox.information( |
370 E5MessageBox.information( |
371 self, |
371 self, |
372 self.trUtf8("Save regular expression"), |
372 self.tr("Save regular expression"), |
373 self.trUtf8("""<p>The regular expression could not""" |
373 self.tr("""<p>The regular expression could not""" |
374 """ be saved.</p><p>Reason: {0}</p>""") |
374 """ be saved.</p><p>Reason: {0}</p>""") |
375 .format(str(err))) |
375 .format(str(err))) |
376 |
376 |
377 @pyqtSlot() |
377 @pyqtSlot() |
378 def on_loadButton_clicked(self): |
378 def on_loadButton_clicked(self): |
379 """ |
379 """ |
380 Private slot to load a regexp from a file. |
380 Private slot to load a regexp from a file. |
381 """ |
381 """ |
382 fname = E5FileDialog.getOpenFileName( |
382 fname = E5FileDialog.getOpenFileName( |
383 self, |
383 self, |
384 self.trUtf8("Load regular expression"), |
384 self.tr("Load regular expression"), |
385 "", |
385 "", |
386 self.trUtf8("RegExp Files (*.rx);;All Files (*)")) |
386 self.tr("RegExp Files (*.rx);;All Files (*)")) |
387 if fname: |
387 if fname: |
388 try: |
388 try: |
389 f = open( |
389 f = open( |
390 Utilities.toNativeSeparators(fname), "r", encoding="utf-8") |
390 Utilities.toNativeSeparators(fname), "r", encoding="utf-8") |
391 regexp = f.read() |
391 regexp = f.read() |
436 re.setPatternSyntax( |
436 re.setPatternSyntax( |
437 self.syntaxCombo.itemData(self.syntaxCombo.currentIndex())) |
437 self.syntaxCombo.itemData(self.syntaxCombo.currentIndex())) |
438 if re.isValid(): |
438 if re.isValid(): |
439 E5MessageBox.information( |
439 E5MessageBox.information( |
440 self, |
440 self, |
441 self.trUtf8("Validation"), |
441 self.tr("Validation"), |
442 self.trUtf8("""The regular expression is valid.""")) |
442 self.tr("""The regular expression is valid.""")) |
443 else: |
443 else: |
444 E5MessageBox.critical( |
444 E5MessageBox.critical( |
445 self, |
445 self, |
446 self.trUtf8("Error"), |
446 self.tr("Error"), |
447 self.trUtf8("""Invalid regular expression: {0}""") |
447 self.tr("""Invalid regular expression: {0}""") |
448 .format(re.errorString())) |
448 .format(re.errorString())) |
449 return |
449 return |
450 else: |
450 else: |
451 E5MessageBox.critical( |
451 E5MessageBox.critical( |
452 self, |
452 self, |
453 self.trUtf8("Error"), |
453 self.tr("Error"), |
454 self.trUtf8("""A regular expression must be given.""")) |
454 self.tr("""A regular expression must be given.""")) |
455 |
455 |
456 @pyqtSlot() |
456 @pyqtSlot() |
457 def on_executeButton_clicked(self, startpos=0): |
457 def on_executeButton_clicked(self, startpos=0): |
458 """ |
458 """ |
459 Private slot to execute the entered regexp on the test text. |
459 Private slot to execute the entered regexp on the test text. |
476 wildcard = syntax in [QRegExp.Wildcard, QRegExp.WildcardUnix] |
476 wildcard = syntax in [QRegExp.Wildcard, QRegExp.WildcardUnix] |
477 re.setPatternSyntax(syntax) |
477 re.setPatternSyntax(syntax) |
478 if not re.isValid(): |
478 if not re.isValid(): |
479 E5MessageBox.critical( |
479 E5MessageBox.critical( |
480 self, |
480 self, |
481 self.trUtf8("Error"), |
481 self.tr("Error"), |
482 self.trUtf8("""Invalid regular expression: {0}""") |
482 self.tr("""Invalid regular expression: {0}""") |
483 .format(re.errorString())) |
483 .format(re.errorString())) |
484 return |
484 return |
485 offset = re.indexIn(text, startpos) |
485 offset = re.indexIn(text, startpos) |
486 captures = re.captureCount() |
486 captures = re.captureCount() |
487 row = 0 |
487 row = 0 |
490 self.resultTable.setColumnCount(0) |
490 self.resultTable.setColumnCount(0) |
491 self.resultTable.setColumnCount(3) |
491 self.resultTable.setColumnCount(3) |
492 self.resultTable.setRowCount(0) |
492 self.resultTable.setRowCount(0) |
493 self.resultTable.setRowCount(OFFSET) |
493 self.resultTable.setRowCount(OFFSET) |
494 self.resultTable.setItem( |
494 self.resultTable.setItem( |
495 row, 0, QTableWidgetItem(self.trUtf8("Regexp"))) |
495 row, 0, QTableWidgetItem(self.tr("Regexp"))) |
496 self.resultTable.setItem(row, 1, QTableWidgetItem(regex)) |
496 self.resultTable.setItem(row, 1, QTableWidgetItem(regex)) |
497 |
497 |
498 if offset != -1: |
498 if offset != -1: |
499 self.lastMatchEnd = offset + re.matchedLength() |
499 self.lastMatchEnd = offset + re.matchedLength() |
500 self.nextButton.setEnabled(True) |
500 self.nextButton.setEnabled(True) |
501 row += 1 |
501 row += 1 |
502 self.resultTable.setItem( |
502 self.resultTable.setItem( |
503 row, 0, QTableWidgetItem(self.trUtf8("Offset"))) |
503 row, 0, QTableWidgetItem(self.tr("Offset"))) |
504 self.resultTable.setItem( |
504 self.resultTable.setItem( |
505 row, 1, QTableWidgetItem("{0:d}".format(offset))) |
505 row, 1, QTableWidgetItem("{0:d}".format(offset))) |
506 |
506 |
507 if not wildcard: |
507 if not wildcard: |
508 row += 1 |
508 row += 1 |
509 self.resultTable.setItem( |
509 self.resultTable.setItem( |
510 row, 0, QTableWidgetItem(self.trUtf8("Captures"))) |
510 row, 0, QTableWidgetItem(self.tr("Captures"))) |
511 self.resultTable.setItem( |
511 self.resultTable.setItem( |
512 row, 1, QTableWidgetItem("{0:d}".format(captures))) |
512 row, 1, QTableWidgetItem("{0:d}".format(captures))) |
513 row += 1 |
513 row += 1 |
514 self.resultTable.setItem( |
514 self.resultTable.setItem( |
515 row, 1, QTableWidgetItem(self.trUtf8("Text"))) |
515 row, 1, QTableWidgetItem(self.tr("Text"))) |
516 self.resultTable.setItem( |
516 self.resultTable.setItem( |
517 row, 2, QTableWidgetItem(self.trUtf8("Characters"))) |
517 row, 2, QTableWidgetItem(self.tr("Characters"))) |
518 |
518 |
519 row += 1 |
519 row += 1 |
520 self.resultTable.setItem( |
520 self.resultTable.setItem( |
521 row, 0, QTableWidgetItem(self.trUtf8("Match"))) |
521 row, 0, QTableWidgetItem(self.tr("Match"))) |
522 self.resultTable.setItem( |
522 self.resultTable.setItem( |
523 row, 1, QTableWidgetItem(re.cap(0))) |
523 row, 1, QTableWidgetItem(re.cap(0))) |
524 self.resultTable.setItem( |
524 self.resultTable.setItem( |
525 row, 2, |
525 row, 2, |
526 QTableWidgetItem("{0:d}".format(re.matchedLength()))) |
526 QTableWidgetItem("{0:d}".format(re.matchedLength()))) |
677 |
677 |
678 self.cw = QRegExpWizardWidget(self, fromEric) |
678 self.cw = QRegExpWizardWidget(self, fromEric) |
679 size = self.cw.size() |
679 size = self.cw.size() |
680 self.__layout.addWidget(self.cw) |
680 self.__layout.addWidget(self.cw) |
681 self.resize(size) |
681 self.resize(size) |
682 |
682 self.setWindowTitle(self.cw.windowTitle()) |
683 self.cw.buttonBox.accepted[()].connect(self.accept) |
683 |
684 self.cw.buttonBox.rejected[()].connect(self.reject) |
684 self.cw.buttonBox.accepted.connect(self.accept) |
|
685 self.cw.buttonBox.rejected.connect(self.reject) |
685 |
686 |
686 def getCode(self, indLevel, indString): |
687 def getCode(self, indLevel, indString): |
687 """ |
688 """ |
688 Public method to get the source code. |
689 Public method to get the source code. |
689 |
690 |
707 super(QRegExpWizardWindow, self).__init__(parent) |
708 super(QRegExpWizardWindow, self).__init__(parent) |
708 self.cw = QRegExpWizardWidget(self, fromEric=False) |
709 self.cw = QRegExpWizardWidget(self, fromEric=False) |
709 size = self.cw.size() |
710 size = self.cw.size() |
710 self.setCentralWidget(self.cw) |
711 self.setCentralWidget(self.cw) |
711 self.resize(size) |
712 self.resize(size) |
|
713 self.setWindowTitle(self.cw.windowTitle()) |
712 |
714 |
713 self.setStyle( |
715 self.setStyle( |
714 Preferences.getUI("Style"), Preferences.getUI("StyleSheet")) |
716 Preferences.getUI("Style"), Preferences.getUI("StyleSheet")) |
715 |
717 |
716 self.cw.buttonBox.accepted[()].connect(self.close) |
718 self.cw.buttonBox.accepted.connect(self.close) |
717 self.cw.buttonBox.rejected[()].connect(self.close) |
719 self.cw.buttonBox.rejected.connect(self.close) |