77 self.undoButton.setIcon(UI.PixmapCache.getIcon("editUndo")) |
77 self.undoButton.setIcon(UI.PixmapCache.getIcon("editUndo")) |
78 self.redoButton.setIcon(UI.PixmapCache.getIcon("editRedo")) |
78 self.redoButton.setIcon(UI.PixmapCache.getIcon("editRedo")) |
79 |
79 |
80 self.namedGroups = re.compile(r"""\(?P<([^>]+)>""").findall |
80 self.namedGroups = re.compile(r"""\(?P<([^>]+)>""").findall |
81 |
81 |
82 # start the PyQt5 server part |
82 # start the PyQt6 server part |
83 self.__pyqt5Available = False |
83 self.__pyqt6Available = False |
84 self.__pyqt5Server = QProcess(self) |
84 self.__pyqt6Server = QProcess(self) |
85 self.__pyqt5Server.start( |
85 self.__pyqt6Server.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.__pyqt6Server.waitForStarted(5000): |
90 self.__pyqt5Server.setReadChannel( |
90 self.__pyqt6Server.setReadChannel( |
91 QProcess.ProcessChannel.StandardOutput) |
91 QProcess.ProcessChannel.StandardOutput) |
92 if self.__sendCommand("available"): |
92 if self.__sendCommand("available"): |
93 response = self.__receiveResponse() |
93 response = self.__receiveResponse() |
94 if response and response["available"]: |
94 if response and response["available"]: |
95 self.__pyqt5Available = True |
95 self.__pyqt6Available = True |
96 |
96 |
97 self.saveButton = self.buttonBox.addButton( |
97 self.saveButton = self.buttonBox.addButton( |
98 self.tr("Save"), QDialogButtonBox.ButtonRole.ActionRole) |
98 self.tr("Save"), QDialogButtonBox.ButtonRole.ActionRole) |
99 self.saveButton.setToolTip( |
99 self.saveButton.setToolTip( |
100 self.tr("Save the regular expression to a file")) |
100 self.tr("Save the regular expression to a file")) |
101 self.loadButton = self.buttonBox.addButton( |
101 self.loadButton = self.buttonBox.addButton( |
102 self.tr("Load"), QDialogButtonBox.ButtonRole.ActionRole) |
102 self.tr("Load"), QDialogButtonBox.ButtonRole.ActionRole) |
103 self.loadButton.setToolTip( |
103 self.loadButton.setToolTip( |
104 self.tr("Load a regular expression from a file")) |
104 self.tr("Load a regular expression from a file")) |
105 if self.__pyqt5Available: |
105 if self.__pyqt6Available: |
106 self.validateButton = self.buttonBox.addButton( |
106 self.validateButton = self.buttonBox.addButton( |
107 self.tr("Validate"), QDialogButtonBox.ButtonRole.ActionRole) |
107 self.tr("Validate"), QDialogButtonBox.ButtonRole.ActionRole) |
108 self.validateButton.setToolTip( |
108 self.validateButton.setToolTip( |
109 self.tr("Validate the regular expression")) |
109 self.tr("Validate the regular expression")) |
110 self.executeButton = self.buttonBox.addButton( |
110 self.executeButton = self.buttonBox.addButton( |
151 if command: |
151 if command: |
152 commandDict = {"command": command} |
152 commandDict = {"command": command} |
153 commandDict.update(kw) |
153 commandDict.update(kw) |
154 commandStr = json.dumps(commandDict) + "\n" |
154 commandStr = json.dumps(commandDict) + "\n" |
155 data = QByteArray(commandStr.encode("utf-8")) |
155 data = QByteArray(commandStr.encode("utf-8")) |
156 self.__pyqt5Server.write(data) |
156 self.__pyqt6Server.write(data) |
157 result = self.__pyqt5Server.waitForBytesWritten(10000) |
157 result = self.__pyqt6Server.waitForBytesWritten(10000) |
158 return result |
158 return result |
159 |
159 |
160 def __receiveResponse(self): |
160 def __receiveResponse(self): |
161 """ |
161 """ |
162 Private method to receive a response from the PyQt5 server. |
162 Private method to receive a response from the PyQt5 server. |
163 |
163 |
164 @return response dictionary (dict) |
164 @return response dictionary (dict) |
165 """ |
165 """ |
166 responseDict = {} |
166 responseDict = {} |
167 if self.__pyqt5Server.waitForReadyRead(10000): |
167 if self.__pyqt6Server.waitForReadyRead(10000): |
168 data = bytes(self.__pyqt5Server.readAllStandardOutput()) |
168 data = bytes(self.__pyqt6Server.readAllStandardOutput()) |
169 responseStr = data.decode("utf-8") |
169 responseStr = data.decode("utf-8") |
170 responseDict = json.loads(responseStr) |
170 responseDict = json.loads(responseStr) |
171 if responseDict["error"]: |
171 if responseDict["error"]: |
172 EricMessageBox.critical( |
172 EricMessageBox.critical( |
173 self, |
173 self, |
552 This slot will execute the entered QRegularExpression on the entered |
552 This slot will execute the entered QRegularExpression on the entered |
553 test data and will display the result in the table part of the dialog. |
553 test data and will display the result in the table part of the dialog. |
554 |
554 |
555 @param startpos starting position for the QRegularExpression matching |
555 @param startpos starting position for the QRegularExpression matching |
556 """ |
556 """ |
557 if not self.__pyqt5Available: |
557 if not self.__pyqt6Available: |
558 # only available for PyQt5 |
558 # only available for PyQt6 |
559 return |
559 return |
560 |
560 |
561 regexp = self.regexpTextEdit.toPlainText() |
561 regexp = self.regexpTextEdit.toPlainText() |
562 text = self.textTextEdit.toPlainText() |
562 text = self.textTextEdit.toPlainText() |
563 if regexp and text: |
563 if regexp and text: |
778 code += '{0}{1}r"""{2}""",'.format( |
778 code += '{0}{1}r"""{2}""",'.format( |
779 os.linesep, i1string, regexp.replace('"', '\\"')) |
779 os.linesep, i1string, regexp.replace('"', '\\"')) |
780 code += '{0}{1}{2}'.format(os.linesep, i1string, options) |
780 code += '{0}{1}{2}'.format(os.linesep, i1string, options) |
781 else: |
781 else: |
782 code += 'r"""{0}"""'.format(regexp.replace('"', '\\"')) |
782 code += 'r"""{0}"""'.format(regexp.replace('"', '\\"')) |
783 code += '){0}'.format(estring) |
783 code += '{0}){0}'.format(estring) |
784 return code |
784 return code |
785 |
785 |
786 |
786 |
787 class QRegularExpressionWizardDialog(QDialog): |
787 class QRegularExpressionWizardDialog(QDialog): |
788 """ |
788 """ |