Plugins/WizardPlugins/PyRegExpWizard/PyRegExpWizardDialog.py

changeset 12
1d8dd9706f46
parent 6
52e8c820d0dd
child 13
1af94a91f439
equal deleted inserted replaced
11:b0996e4a289e 12:1d8dd9706f46
12 import re 12 import re
13 13
14 from PyQt4.QtCore import * 14 from PyQt4.QtCore import *
15 from PyQt4.QtGui import * 15 from PyQt4.QtGui import *
16 16
17 from Ui_PyRegExpWizardDialog import Ui_PyRegExpWizardDialog 17 from .Ui_PyRegExpWizardDialog import Ui_PyRegExpWizardDialog
18 18
19 from PyRegExpWizardRepeatDialog import PyRegExpWizardRepeatDialog 19 from .PyRegExpWizardRepeatDialog import PyRegExpWizardRepeatDialog
20 from PyRegExpWizardCharactersDialog import PyRegExpWizardCharactersDialog 20 from .PyRegExpWizardCharactersDialog import PyRegExpWizardCharactersDialog
21 21
22 import UI.PixmapCache 22 import UI.PixmapCache
23 23
24 import Utilities 24 import Utilities
25 25
320 QMessageBox.Abort) 320 QMessageBox.Abort)
321 if res == QMessageBox.Abort or res == QMessageBox.Cancel: 321 if res == QMessageBox.Abort or res == QMessageBox.Cancel:
322 return 322 return
323 323
324 try: 324 try:
325 f=open(Utilities.toNativeSeparators(fname), "wb") 325 f=open(Utilities.toNativeSeparators(fname), "w")
326 f.write(self.regexpTextEdit.toPlainText()) 326 f.write(self.regexpTextEdit.toPlainText())
327 f.close() 327 f.close()
328 except IOError, err: 328 except IOError as err:
329 QMessageBox.information(self, 329 QMessageBox.information(self,
330 self.trUtf8("Save regular expression"), 330 self.trUtf8("Save regular expression"),
331 self.trUtf8("""<p>The regular expression could not be saved.</p>""" 331 self.trUtf8("""<p>The regular expression could not be saved.</p>"""
332 """<p>Reason: {0}</p>""").format(unicode(err))) 332 """<p>Reason: {0}</p>""").format(str(err)))
333 333
334 @pyqtSlot() 334 @pyqtSlot()
335 def on_loadButton_clicked(self): 335 def on_loadButton_clicked(self):
336 """ 336 """
337 Private slot to load a regexp from a file. 337 Private slot to load a regexp from a file.
341 self.trUtf8("Load regular expression"), 341 self.trUtf8("Load regular expression"),
342 "", 342 "",
343 self.trUtf8("RegExp Files (*.rx);;All Files (*)")) 343 self.trUtf8("RegExp Files (*.rx);;All Files (*)"))
344 if fname: 344 if fname:
345 try: 345 try:
346 f=open(Utilities.toNativeSeparators(fname), "rb") 346 f=open(Utilities.toNativeSeparators(fname), "r")
347 regexp = f.read() 347 regexp = f.read()
348 f.close() 348 f.close()
349 self.regexpTextEdit.setPlainText(regexp) 349 self.regexpTextEdit.setPlainText(regexp)
350 except IOError, err: 350 except IOError as err:
351 QMessageBox.information(self, 351 QMessageBox.information(self,
352 self.trUtf8("Save regular expression"), 352 self.trUtf8("Save regular expression"),
353 self.trUtf8("""<p>The regular expression could not be saved.</p>""" 353 self.trUtf8("""<p>The regular expression could not be saved.</p>"""
354 """<p>Reason: {0}</p>""").format(unicode(err))) 354 """<p>Reason: {0}</p>""").format(str(err)))
355 355
356 @pyqtSlot() 356 @pyqtSlot()
357 def on_copyButton_clicked(self): 357 def on_copyButton_clicked(self):
358 """ 358 """
359 Private slot to copy the regexp string into the clipboard. 359 Private slot to copy the regexp string into the clipboard.
392 self.verboseCheckBox.isChecked() and re.VERBOSE or 0 | \ 392 self.verboseCheckBox.isChecked() and re.VERBOSE or 0 | \
393 (not self.unicodeCheckBox.isChecked() and re.UNICODE or 0)) 393 (not self.unicodeCheckBox.isChecked() and re.UNICODE or 0))
394 QMessageBox.information(None, 394 QMessageBox.information(None,
395 self.trUtf8(""), 395 self.trUtf8(""),
396 self.trUtf8("""The regular expression is valid.""")) 396 self.trUtf8("""The regular expression is valid."""))
397 except re.error, e: 397 except re.error as e:
398 QMessageBox.critical(None, 398 QMessageBox.critical(None,
399 self.trUtf8("Error"), 399 self.trUtf8("Error"),
400 self.trUtf8("""Invalid regular expression: {0}""") 400 self.trUtf8("""Invalid regular expression: {0}""")
401 .format(unicode(e))) 401 .format(str(e)))
402 return 402 return
403 except IndexError: 403 except IndexError:
404 QMessageBox.critical(None, 404 QMessageBox.critical(None,
405 self.trUtf8("Error"), 405 self.trUtf8("Error"),
406 self.trUtf8("""Invalid regular expression: missing group name""")) 406 self.trUtf8("""Invalid regular expression: missing group name"""))
519 519
520 self.resultTable.resizeColumnsToContents() 520 self.resultTable.resizeColumnsToContents()
521 self.resultTable.resizeRowsToContents() 521 self.resultTable.resizeRowsToContents()
522 self.resultTable.verticalHeader().hide() 522 self.resultTable.verticalHeader().hide()
523 self.resultTable.horizontalHeader().hide() 523 self.resultTable.horizontalHeader().hide()
524 except re.error, e: 524 except re.error as e:
525 QMessageBox.critical(None, 525 QMessageBox.critical(None,
526 self.trUtf8("Error"), 526 self.trUtf8("Error"),
527 self.trUtf8("""Invalid regular expression: {0}""") 527 self.trUtf8("""Invalid regular expression: {0}""")
528 .format(unicode(e))) 528 .format(str(e)))
529 return 529 return
530 except IndexError: 530 except IndexError:
531 QMessageBox.critical(None, 531 QMessageBox.critical(None,
532 self.trUtf8("Error"), 532 self.trUtf8("Error"),
533 self.trUtf8("""Invalid regular expression: missing group name""")) 533 self.trUtf8("""Invalid regular expression: missing group name"""))

eric ide

mercurial