10 import os |
10 import os |
11 import re |
11 import re |
12 |
12 |
13 from PyQt4.QtCore import * |
13 from PyQt4.QtCore import * |
14 from PyQt4.QtGui import * |
14 from PyQt4.QtGui import * |
|
15 |
|
16 from E5Gui import E5MessageBox |
15 |
17 |
16 from .Ui_PyRegExpWizardDialog import Ui_PyRegExpWizardDialog |
18 from .Ui_PyRegExpWizardDialog import Ui_PyRegExpWizardDialog |
17 |
19 |
18 from .PyRegExpWizardRepeatDialog import PyRegExpWizardRepeatDialog |
20 from .PyRegExpWizardRepeatDialog import PyRegExpWizardRepeatDialog |
19 from .PyRegExpWizardCharactersDialog import PyRegExpWizardCharactersDialog |
21 from .PyRegExpWizardCharactersDialog import PyRegExpWizardCharactersDialog |
160 |
162 |
161 # only present group names that occur before the current cursor position |
163 # only present group names that occur before the current cursor position |
162 regex = self.regexpTextEdit.toPlainText()[:length] |
164 regex = self.regexpTextEdit.toPlainText()[:length] |
163 names = self.namedGroups(regex) |
165 names = self.namedGroups(regex) |
164 if not names: |
166 if not names: |
165 QMessageBox.information(None, |
167 E5MessageBox.information(self, |
166 self.trUtf8("Named reference"), |
168 self.trUtf8("Named reference"), |
167 self.trUtf8("""No named groups have been defined yet.""")) |
169 self.trUtf8("""No named groups have been defined yet.""")) |
168 return |
170 return |
169 |
171 |
170 groupName, ok = QInputDialog.getItem(\ |
172 groupName, ok = QInputDialog.getItem(\ |
171 None, |
173 self, |
172 self.trUtf8("Named reference"), |
174 self.trUtf8("Named reference"), |
173 self.trUtf8("Select group name:"), |
175 self.trUtf8("Select group name:"), |
174 names, |
176 names, |
175 0, True) |
177 0, True) |
176 if ok and groupName: |
178 if ok and groupName: |
323 try: |
325 try: |
324 f=open(Utilities.toNativeSeparators(fname), "w", encoding = "utf-8") |
326 f=open(Utilities.toNativeSeparators(fname), "w", encoding = "utf-8") |
325 f.write(self.regexpTextEdit.toPlainText()) |
327 f.write(self.regexpTextEdit.toPlainText()) |
326 f.close() |
328 f.close() |
327 except IOError as err: |
329 except IOError as err: |
328 QMessageBox.information(self, |
330 E5MessageBox.information(self, |
329 self.trUtf8("Save regular expression"), |
331 self.trUtf8("Save regular expression"), |
330 self.trUtf8("""<p>The regular expression could not be saved.</p>""" |
332 self.trUtf8("""<p>The regular expression could not be saved.</p>""" |
331 """<p>Reason: {0}</p>""").format(str(err))) |
333 """<p>Reason: {0}</p>""").format(str(err))) |
332 |
334 |
333 @pyqtSlot() |
335 @pyqtSlot() |
345 f=open(Utilities.toNativeSeparators(fname), "r", encoding = "utf-8") |
347 f=open(Utilities.toNativeSeparators(fname), "r", encoding = "utf-8") |
346 regexp = f.read() |
348 regexp = f.read() |
347 f.close() |
349 f.close() |
348 self.regexpTextEdit.setPlainText(regexp) |
350 self.regexpTextEdit.setPlainText(regexp) |
349 except IOError as err: |
351 except IOError as err: |
350 QMessageBox.information(self, |
352 E5MessageBox.information(self, |
351 self.trUtf8("Save regular expression"), |
353 self.trUtf8("Save regular expression"), |
352 self.trUtf8("""<p>The regular expression could not be saved.</p>""" |
354 self.trUtf8("""<p>The regular expression could not be saved.</p>""" |
353 """<p>Reason: {0}</p>""").format(str(err))) |
355 """<p>Reason: {0}</p>""").format(str(err))) |
354 |
356 |
355 @pyqtSlot() |
357 @pyqtSlot() |
388 (not self.caseSensitiveCheckBox.isChecked() and re.IGNORECASE or 0) | \ |
390 (not self.caseSensitiveCheckBox.isChecked() and re.IGNORECASE or 0) | \ |
389 self.multilineCheckBox.isChecked() and re.MULTILINE or 0 | \ |
391 self.multilineCheckBox.isChecked() and re.MULTILINE or 0 | \ |
390 self.dotallCheckBox.isChecked() and re.DOTALL or 0 | \ |
392 self.dotallCheckBox.isChecked() and re.DOTALL or 0 | \ |
391 self.verboseCheckBox.isChecked() and re.VERBOSE or 0 | \ |
393 self.verboseCheckBox.isChecked() and re.VERBOSE or 0 | \ |
392 (not self.unicodeCheckBox.isChecked() and re.UNICODE or 0)) |
394 (not self.unicodeCheckBox.isChecked() and re.UNICODE or 0)) |
393 QMessageBox.information(None, |
395 E5MessageBox.information(self, |
394 self.trUtf8(""), |
396 self.trUtf8(""), |
395 self.trUtf8("""The regular expression is valid.""")) |
397 self.trUtf8("""The regular expression is valid.""")) |
396 except re.error as e: |
398 except re.error as e: |
397 QMessageBox.critical(None, |
399 QMessageBox.critical(self, |
398 self.trUtf8("Error"), |
400 self.trUtf8("Error"), |
399 self.trUtf8("""Invalid regular expression: {0}""") |
401 self.trUtf8("""Invalid regular expression: {0}""") |
400 .format(str(e))) |
402 .format(str(e))) |
401 return |
403 return |
402 except IndexError: |
404 except IndexError: |
403 QMessageBox.critical(None, |
405 QMessageBox.critical(self, |
404 self.trUtf8("Error"), |
406 self.trUtf8("Error"), |
405 self.trUtf8("""Invalid regular expression: missing group name""")) |
407 self.trUtf8("""Invalid regular expression: missing group name""")) |
406 return |
408 return |
407 else: |
409 else: |
408 QMessageBox.critical(None, |
410 QMessageBox.critical(self, |
409 self.trUtf8("Error"), |
411 self.trUtf8("Error"), |
410 self.trUtf8("""A regular expression must be given.""")) |
412 self.trUtf8("""A regular expression must be given.""")) |
411 |
413 |
412 @pyqtSlot() |
414 @pyqtSlot() |
413 def on_executeButton_clicked(self, startpos = 0): |
415 def on_executeButton_clicked(self, startpos = 0): |