eric7/Plugins/WizardPlugins/QRegularExpressionWizard/QRegularExpressionWizardDialog.py

branch
eric7
changeset 8415
c6236bed1b50
parent 8358
144a6b854f70
child 8459
0ae07748dbe8
equal deleted inserted replaced
8414:8c3b52d1b4b6 8415:c6236bed1b50
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,
182 def shutdown(self): 182 def shutdown(self):
183 """ 183 """
184 Public method to shut down the PyQt5 server part. 184 Public method to shut down the PyQt5 server part.
185 """ 185 """
186 self.__sendCommand("exit") 186 self.__sendCommand("exit")
187 self.__pyqt5Server.waitForFinished(5000) 187 self.__pyqt6Server.waitForFinished(5000)
188 188
189 def __insertString(self, s, steps=0): 189 def __insertString(self, s, steps=0):
190 """ 190 """
191 Private method to insert a string into line edit and move cursor. 191 Private method to insert a string into line edit and move cursor.
192 192
479 @pyqtSlot() 479 @pyqtSlot()
480 def on_validateButton_clicked(self): 480 def on_validateButton_clicked(self):
481 """ 481 """
482 Private slot to validate the entered QRegularExpression. 482 Private slot to validate the entered QRegularExpression.
483 """ 483 """
484 if not self.__pyqt5Available: 484 if not self.__pyqt6Available:
485 # only available for PyQt5 485 # only available for PyQt6
486 return 486 return
487 487
488 regexp = self.regexpTextEdit.toPlainText() 488 regexp = self.regexpTextEdit.toPlainText()
489 if regexp: 489 if regexp:
490 options = [] 490 options = []
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 """

eric ide

mercurial