Plugins/WizardPlugins/PyRegExpWizard/PyRegExpWizardDialog.py

branch
Py2 comp.
changeset 2791
a9577f248f04
parent 2525
8b507a9a2d40
parent 2774
72fab2c15e28
child 2847
1843ef6e2656
equal deleted inserted replaced
2790:6686a3326df8 2791:a9577f248f04
82 self.nextButton.setToolTip( 82 self.nextButton.setToolTip(
83 self.trUtf8("Show the next match of the regular expression")) 83 self.trUtf8("Show the next match of the regular expression"))
84 self.nextButton.setEnabled(False) 84 self.nextButton.setEnabled(False)
85 85
86 if fromEric: 86 if fromEric:
87 self.buttonBox.button(QDialogButtonBox.Close).hide() 87 self.buttonBox.setStandardButtons(
88 QDialogButtonBox.Cancel | QDialogButtonBox.Ok)
88 self.copyButton = None 89 self.copyButton = None
89 else: 90 else:
90 self.copyButton = \ 91 self.copyButton = \
91 self.buttonBox.addButton(self.trUtf8("Copy"), QDialogButtonBox.ActionRole) 92 self.buttonBox.addButton(self.trUtf8("Copy"), QDialogButtonBox.ActionRole)
92 self.copyButton.setToolTip( 93 self.copyButton.setToolTip(
93 self.trUtf8("Copy the regular expression to the clipboard")) 94 self.trUtf8("Copy the regular expression to the clipboard"))
94 self.buttonBox.button(QDialogButtonBox.Ok).hide() 95 self.buttonBox.setStandardButtons(QDialogButtonBox.Close)
95 self.buttonBox.button(QDialogButtonBox.Cancel).hide()
96 self.variableLabel.hide() 96 self.variableLabel.hide()
97 self.variableLineEdit.hide() 97 self.variableLineEdit.hide()
98 self.variableLine.hide() 98 self.variableLine.hide()
99 self.importCheckBox.hide() 99 self.importCheckBox.hide()
100 self.regexpTextEdit.setFocus() 100 self.regexpTextEdit.setFocus()
377 Private slot to validate the entered regexp. 377 Private slot to validate the entered regexp.
378 """ 378 """
379 regex = self.regexpTextEdit.toPlainText() 379 regex = self.regexpTextEdit.toPlainText()
380 if regex: 380 if regex:
381 try: 381 try:
382 flags = 0
383 if not self.caseSensitiveCheckBox.isChecked():
384 flags |= re.IGNORECASE
385 if self.multilineCheckBox.isChecked():
386 flags |= re.MULTILINE
387 if self.dotallCheckBox.isChecked():
388 flags |= re.DOTALL
389 if self.verboseCheckBox.isChecked():
390 flags |= re.VERBOSE
382 if self.py2Button.isChecked(): 391 if self.py2Button.isChecked():
383 re.compile(regex, 392 if self.localeCheckBox.isChecked():
384 (not self.caseSensitiveCheckBox.isChecked() and re.IGNORECASE or 0) | \ 393 flags |= re.LOCALE
385 self.multilineCheckBox.isChecked() and re.MULTILINE or 0 | \ 394 if self.unicodeCheckBox.isChecked():
386 self.dotallCheckBox.isChecked() and re.DOTALL or 0 | \ 395 flags |= re.UNICODE
387 self.verboseCheckBox.isChecked() and re.VERBOSE or 0 | \
388 self.localeCheckBox.isChecked() and re.LOCALE or 0 | \
389 self.unicodeCheckBox.isChecked() and re.UNICODE or 0)
390 else: 396 else:
391 re.compile(regex, 397 if self.unicodeCheckBox.isChecked():
392 (not self.caseSensitiveCheckBox.isChecked() and re.IGNORECASE or 0) | \ 398 flags |= re.ASCII
393 self.multilineCheckBox.isChecked() and re.MULTILINE or 0 | \ 399 re.compile(regex, flags)
394 self.dotallCheckBox.isChecked() and re.DOTALL or 0 | \
395 self.verboseCheckBox.isChecked() and re.VERBOSE or 0 | \
396 (not self.unicodeCheckBox.isChecked() and re.UNICODE or 0))
397 E5MessageBox.information(self, 400 E5MessageBox.information(self,
398 self.trUtf8("Validation"), 401 self.trUtf8("Validation"),
399 self.trUtf8("""The regular expression is valid.""")) 402 self.trUtf8("""The regular expression is valid."""))
400 except re.error as e: 403 except re.error as e:
401 E5MessageBox.critical(self, 404 E5MessageBox.critical(self,
425 """ 428 """
426 regex = self.regexpTextEdit.toPlainText() 429 regex = self.regexpTextEdit.toPlainText()
427 text = self.textTextEdit.toPlainText() 430 text = self.textTextEdit.toPlainText()
428 if regex and text: 431 if regex and text:
429 try: 432 try:
433 flags = 0
434 if not self.caseSensitiveCheckBox.isChecked():
435 flags |= re.IGNORECASE
436 if self.multilineCheckBox.isChecked():
437 flags |= re.MULTILINE
438 if self.dotallCheckBox.isChecked():
439 flags |= re.DOTALL
440 if self.verboseCheckBox.isChecked():
441 flags |= re.VERBOSE
430 if self.py2Button.isChecked(): 442 if self.py2Button.isChecked():
431 regobj = re.compile(regex, 443 if self.localeCheckBox.isChecked():
432 (not self.caseSensitiveCheckBox.isChecked() and re.IGNORECASE or 0) | \ 444 flags |= re.LOCALE
433 self.multilineCheckBox.isChecked() and re.MULTILINE or 0 | \ 445 if self.unicodeCheckBox.isChecked():
434 self.dotallCheckBox.isChecked() and re.DOTALL or 0 | \ 446 flags |= re.UNICODE
435 self.verboseCheckBox.isChecked() and re.VERBOSE or 0 | \
436 self.localeCheckBox.isChecked() and re.LOCALE or 0 | \
437 self.unicodeCheckBox.isChecked() and re.UNICODE or 0)
438 else: 447 else:
439 regobj = re.compile(regex, 448 if self.unicodeCheckBox.isChecked():
440 (not self.caseSensitiveCheckBox.isChecked() and re.IGNORECASE or 0) | \ 449 flags |= re.ASCII
441 self.multilineCheckBox.isChecked() and re.MULTILINE or 0 | \ 450 regobj = re.compile(regex, flags)
442 self.dotallCheckBox.isChecked() and re.DOTALL or 0 | \
443 self.verboseCheckBox.isChecked() and re.VERBOSE or 0 | \
444 (not self.unicodeCheckBox.isChecked() and re.UNICODE or 0))
445 matchobj = regobj.search(text, startpos) 451 matchobj = regobj.search(text, startpos)
446 if matchobj is not None: 452 if matchobj is not None:
447 captures = len(matchobj.groups()) 453 captures = len(matchobj.groups())
448 if captures is None: 454 if captures is None:
449 captures = 0 455 captures = 0

eric ide

mercurial