eric6/Plugins/WizardPlugins/QRegularExpressionWizard/QRegularExpressionWizardDialog.py

changeset 8143
2c730d5fd177
parent 7960
e8fc383322f7
child 8218
7c09585bd960
equal deleted inserted replaced
8141:27f636beebad 8143:2c730d5fd177
85 self.__pyqt5Server.start( 85 self.__pyqt5Server.start(
86 sys.executable, [os.path.join( 86 sys.executable, [os.path.join(
87 os.path.dirname(__file__), "QRegularExpressionWizardServer.py") 87 os.path.dirname(__file__), "QRegularExpressionWizardServer.py")
88 ]) 88 ])
89 if self.__pyqt5Server.waitForStarted(5000): 89 if self.__pyqt5Server.waitForStarted(5000):
90 self.__pyqt5Server.setReadChannel(QProcess.StandardOutput) 90 self.__pyqt5Server.setReadChannel(
91 QProcess.ProcessChannel.StandardOutput)
91 if self.__sendCommand("available"): 92 if self.__sendCommand("available"):
92 response = self.__receiveResponse() 93 response = self.__receiveResponse()
93 if response and response["available"]: 94 if response and response["available"]:
94 self.__pyqt5Available = True 95 self.__pyqt5Available = True
95 96
96 self.saveButton = self.buttonBox.addButton( 97 self.saveButton = self.buttonBox.addButton(
97 self.tr("Save"), QDialogButtonBox.ActionRole) 98 self.tr("Save"), QDialogButtonBox.ButtonRole.ActionRole)
98 self.saveButton.setToolTip( 99 self.saveButton.setToolTip(
99 self.tr("Save the regular expression to a file")) 100 self.tr("Save the regular expression to a file"))
100 self.loadButton = self.buttonBox.addButton( 101 self.loadButton = self.buttonBox.addButton(
101 self.tr("Load"), QDialogButtonBox.ActionRole) 102 self.tr("Load"), QDialogButtonBox.ButtonRole.ActionRole)
102 self.loadButton.setToolTip( 103 self.loadButton.setToolTip(
103 self.tr("Load a regular expression from a file")) 104 self.tr("Load a regular expression from a file"))
104 if self.__pyqt5Available: 105 if self.__pyqt5Available:
105 self.validateButton = self.buttonBox.addButton( 106 self.validateButton = self.buttonBox.addButton(
106 self.tr("Validate"), QDialogButtonBox.ActionRole) 107 self.tr("Validate"), QDialogButtonBox.ButtonRole.ActionRole)
107 self.validateButton.setToolTip( 108 self.validateButton.setToolTip(
108 self.tr("Validate the regular expression")) 109 self.tr("Validate the regular expression"))
109 self.executeButton = self.buttonBox.addButton( 110 self.executeButton = self.buttonBox.addButton(
110 self.tr("Execute"), QDialogButtonBox.ActionRole) 111 self.tr("Execute"), QDialogButtonBox.ButtonRole.ActionRole)
111 self.executeButton.setToolTip( 112 self.executeButton.setToolTip(
112 self.tr("Execute the regular expression")) 113 self.tr("Execute the regular expression"))
113 self.nextButton = self.buttonBox.addButton( 114 self.nextButton = self.buttonBox.addButton(
114 self.tr("Next match"), QDialogButtonBox.ActionRole) 115 self.tr("Next match"), QDialogButtonBox.ButtonRole.ActionRole)
115 self.nextButton.setToolTip( 116 self.nextButton.setToolTip(
116 self.tr("Show the next match of the regular expression")) 117 self.tr("Show the next match of the regular expression"))
117 self.nextButton.setEnabled(False) 118 self.nextButton.setEnabled(False)
118 else: 119 else:
119 self.validateButton = None 120 self.validateButton = None
120 self.executeButton = None 121 self.executeButton = None
121 self.nextButton = None 122 self.nextButton = None
122 123
123 if fromEric: 124 if fromEric:
124 self.buttonBox.setStandardButtons( 125 self.buttonBox.setStandardButtons(
125 QDialogButtonBox.Cancel | QDialogButtonBox.Ok) 126 QDialogButtonBox.StandardButton.Cancel |
127 QDialogButtonBox.StandardButton.Ok)
126 self.copyButton = None 128 self.copyButton = None
127 else: 129 else:
128 self.copyButton = self.buttonBox.addButton( 130 self.copyButton = self.buttonBox.addButton(
129 self.tr("Copy"), QDialogButtonBox.ActionRole) 131 self.tr("Copy"), QDialogButtonBox.ButtonRole.ActionRole)
130 self.copyButton.setToolTip( 132 self.copyButton.setToolTip(
131 self.tr("Copy the regular expression to the clipboard")) 133 self.tr("Copy the regular expression to the clipboard"))
132 self.buttonBox.setStandardButtons(QDialogButtonBox.Close) 134 self.buttonBox.setStandardButtons(
135 QDialogButtonBox.StandardButton.Close)
133 self.variableLabel.hide() 136 self.variableLabel.hide()
134 self.variableLineEdit.hide() 137 self.variableLineEdit.hide()
135 self.variableLine.hide() 138 self.variableLine.hide()
136 self.regexpTextEdit.setFocus() 139 self.regexpTextEdit.setFocus()
137 140
194 """ 197 """
195 self.regexpTextEdit.insertPlainText(s) 198 self.regexpTextEdit.insertPlainText(s)
196 tc = self.regexpTextEdit.textCursor() 199 tc = self.regexpTextEdit.textCursor()
197 if steps != 0: 200 if steps != 0:
198 if steps < 0: 201 if steps < 0:
199 act = QTextCursor.Left 202 act = QTextCursor.MoveOperation.Left
200 steps = abs(steps) 203 steps = abs(steps)
201 else: 204 else:
202 act = QTextCursor.Right 205 act = QTextCursor.MoveOperation.Right
203 for _ in range(steps): 206 for _ in range(steps):
204 tc.movePosition(act) 207 tc.movePosition(act)
205 self.regexpTextEdit.setTextCursor(tc) 208 self.regexpTextEdit.setTextCursor(tc)
206 209
207 @pyqtSlot() 210 @pyqtSlot()
218 """ 221 """
219 from .QRegularExpressionWizardCharactersDialog import ( 222 from .QRegularExpressionWizardCharactersDialog import (
220 QRegularExpressionWizardCharactersDialog 223 QRegularExpressionWizardCharactersDialog
221 ) 224 )
222 dlg = QRegularExpressionWizardCharactersDialog(self) 225 dlg = QRegularExpressionWizardCharactersDialog(self)
223 if dlg.exec() == QDialog.Accepted: 226 if dlg.exec() == QDialog.DialogCode.Accepted:
224 self.__insertString(dlg.getCharacters()) 227 self.__insertString(dlg.getCharacters())
225 228
226 @pyqtSlot() 229 @pyqtSlot()
227 def on_anycharButton_clicked(self): 230 def on_anycharButton_clicked(self):
228 """ 231 """
237 """ 240 """
238 from .QRegularExpressionWizardRepeatDialog import ( 241 from .QRegularExpressionWizardRepeatDialog import (
239 QRegularExpressionWizardRepeatDialog 242 QRegularExpressionWizardRepeatDialog
240 ) 243 )
241 dlg = QRegularExpressionWizardRepeatDialog(self) 244 dlg = QRegularExpressionWizardRepeatDialog(self)
242 if dlg.exec() == QDialog.Accepted: 245 if dlg.exec() == QDialog.DialogCode.Accepted:
243 self.__insertString(dlg.getRepeat()) 246 self.__insertString(dlg.getRepeat())
244 247
245 @pyqtSlot() 248 @pyqtSlot()
246 def on_nonGroupButton_clicked(self): 249 def on_nonGroupButton_clicked(self):
247 """ 250 """
467 """ 470 """
468 escaped = self.regexpTextEdit.toPlainText() 471 escaped = self.regexpTextEdit.toPlainText()
469 if escaped: 472 if escaped:
470 escaped = escaped.replace("\\", "\\\\") 473 escaped = escaped.replace("\\", "\\\\")
471 cb = QApplication.clipboard() 474 cb = QApplication.clipboard()
472 cb.setText(escaped, QClipboard.Clipboard) 475 cb.setText(escaped, QClipboard.Mode.Clipboard)
473 if cb.supportsSelection(): 476 if cb.supportsSelection():
474 cb.setText(escaped, QClipboard.Selection) 477 cb.setText(escaped, QClipboard.Mode.Selection)
475 478
476 @pyqtSlot() 479 @pyqtSlot()
477 def on_validateButton_clicked(self): 480 def on_validateButton_clicked(self):
478 """ 481 """
479 Private slot to validate the entered QRegularExpression. 482 Private slot to validate the entered QRegularExpression.
664 667
665 # highlight the matched text 668 # highlight the matched text
666 tc = self.textTextEdit.textCursor() 669 tc = self.textTextEdit.textCursor()
667 tc.setPosition(offset) 670 tc.setPosition(offset)
668 tc.setPosition( 671 tc.setPosition(
669 self.lastMatchEnd, QTextCursor.KeepAnchor) 672 self.lastMatchEnd,
673 QTextCursor.MoveMode.KeepAnchor)
670 self.textTextEdit.setTextCursor(tc) 674 self.textTextEdit.setTextCursor(tc)
671 else: 675 else:
672 self.nextButton.setEnabled(False) 676 self.nextButton.setEnabled(False)
673 self.resultTable.setRowCount(2) 677 self.resultTable.setRowCount(2)
674 row += 1 678 row += 1
745 749
746 regexp = self.regexpTextEdit.toPlainText() 750 regexp = self.regexpTextEdit.toPlainText()
747 751
748 options = [] 752 options = []
749 if self.caseInsensitiveCheckBox.isChecked(): 753 if self.caseInsensitiveCheckBox.isChecked():
750 options.append("QRegularExpression.CaseInsensitiveOption") 754 options.append(
755 "QRegularExpression.PatternOption.CaseInsensitiveOption")
751 if self.multilineCheckBox.isChecked(): 756 if self.multilineCheckBox.isChecked():
752 options.append("QRegularExpression.MultilineOption") 757 options.append(
758 "QRegularExpression.PatternOption.MultilineOption")
753 if self.dotallCheckBox.isChecked(): 759 if self.dotallCheckBox.isChecked():
754 options.append("QRegularExpression.DotMatchesEverythingOption") 760 options.append(
761 "QRegularExpression.PatternOption.DotMatchesEverythingOption")
755 if self.extendedCheckBox.isChecked(): 762 if self.extendedCheckBox.isChecked():
756 options.append("QRegularExpression.ExtendedPatternSyntaxOption") 763 options.append(
764 "QRegularExpression.PatternOption.ExtendedPatternSyntaxOption")
757 if self.greedinessCheckBox.isChecked(): 765 if self.greedinessCheckBox.isChecked():
758 options.append("QRegularExpression.InvertedGreedinessOption") 766 options.append(
767 "QRegularExpression.PatternOption.InvertedGreedinessOption")
759 if self.unicodeCheckBox.isChecked(): 768 if self.unicodeCheckBox.isChecked():
760 options.append("QRegularExpression.UseUnicodePropertiesOption") 769 options.append(
770 "QRegularExpression.PatternOption.UseUnicodePropertiesOption")
761 if self.captureCheckBox.isChecked(): 771 if self.captureCheckBox.isChecked():
762 options.append("QRegularExpression.DontCaptureOption") 772 options.append(
773 "QRegularExpression.PatternOption.DontCaptureOption")
763 options = " |{0}{1}".format(os.linesep, i1string).join(options) 774 options = " |{0}{1}".format(os.linesep, i1string).join(options)
764 775
765 code = '{0} = QRegularExpression('.format(reVar) 776 code = '{0} = QRegularExpression('.format(reVar)
766 if options: 777 if options:
767 code += '{0}{1}r"""{2}""",'.format( 778 code += '{0}{1}r"""{2}""",'.format(

eric ide

mercurial