Plugins/WizardPlugins/QRegExpWizard/QRegExpWizardDialog.py

branch
Py2 comp.
changeset 3056
9986ec0e559a
parent 2847
1843ef6e2656
parent 2893
150de635fa29
child 3145
a9de05d4a22f
equal deleted inserted replaced
2911:ce77f0b1ee67 3056:9986ec0e559a
10 from __future__ import unicode_literals # __IGNORE_WARNING__ 10 from __future__ import unicode_literals # __IGNORE_WARNING__
11 11
12 import os 12 import os
13 13
14 from PyQt4.QtCore import QFileInfo, QRegExp, Qt, pyqtSlot, qVersion 14 from PyQt4.QtCore import QFileInfo, QRegExp, Qt, pyqtSlot, qVersion
15 from PyQt4.QtGui import QWidget, QDialog, QApplication, QClipboard, QTextCursor, \ 15 from PyQt4.QtGui import QWidget, QDialog, QApplication, QClipboard, \
16 QDialogButtonBox, QVBoxLayout, QTableWidgetItem 16 QTextCursor, QDialogButtonBox, QVBoxLayout, QTableWidgetItem
17 17
18 from E5Gui import E5MessageBox, E5FileDialog 18 from E5Gui import E5MessageBox, E5FileDialog
19 from E5Gui.E5MainWindow import E5MainWindow 19 from E5Gui.E5MainWindow import E5MainWindow
20 20
21 from .Ui_QRegExpWizardDialog import Ui_QRegExpWizardWidget 21 from .Ui_QRegExpWizardDialog import Ui_QRegExpWizardWidget
48 self.nonGroupButton.setIcon(UI.PixmapCache.getIcon("nongroup.png")) 48 self.nonGroupButton.setIcon(UI.PixmapCache.getIcon("nongroup.png"))
49 self.groupButton.setIcon(UI.PixmapCache.getIcon("group.png")) 49 self.groupButton.setIcon(UI.PixmapCache.getIcon("group.png"))
50 self.altnButton.setIcon(UI.PixmapCache.getIcon("altn.png")) 50 self.altnButton.setIcon(UI.PixmapCache.getIcon("altn.png"))
51 self.beglineButton.setIcon(UI.PixmapCache.getIcon("begline.png")) 51 self.beglineButton.setIcon(UI.PixmapCache.getIcon("begline.png"))
52 self.endlineButton.setIcon(UI.PixmapCache.getIcon("endline.png")) 52 self.endlineButton.setIcon(UI.PixmapCache.getIcon("endline.png"))
53 self.wordboundButton.setIcon(UI.PixmapCache.getIcon("wordboundary.png")) 53 self.wordboundButton.setIcon(
54 self.nonwordboundButton.setIcon(UI.PixmapCache.getIcon("nonwordboundary.png")) 54 UI.PixmapCache.getIcon("wordboundary.png"))
55 self.poslookaheadButton.setIcon(UI.PixmapCache.getIcon("poslookahead.png")) 55 self.nonwordboundButton.setIcon(
56 self.neglookaheadButton.setIcon(UI.PixmapCache.getIcon("neglookahead.png")) 56 UI.PixmapCache.getIcon("nonwordboundary.png"))
57 self.poslookaheadButton.setIcon(
58 UI.PixmapCache.getIcon("poslookahead.png"))
59 self.neglookaheadButton.setIcon(
60 UI.PixmapCache.getIcon("neglookahead.png"))
57 self.undoButton.setIcon(UI.PixmapCache.getIcon("editUndo.png")) 61 self.undoButton.setIcon(UI.PixmapCache.getIcon("editUndo.png"))
58 self.redoButton.setIcon(UI.PixmapCache.getIcon("editRedo.png")) 62 self.redoButton.setIcon(UI.PixmapCache.getIcon("editRedo.png"))
59 # wildcard tool buttons 63 # wildcard tool buttons
60 self.wildcardCharButton.setIcon(UI.PixmapCache.getIcon("characters.png")) 64 self.wildcardCharButton.setIcon(
61 self.wildcardAnycharButton.setIcon(UI.PixmapCache.getIcon("anychar.png")) 65 UI.PixmapCache.getIcon("characters.png"))
66 self.wildcardAnycharButton.setIcon(
67 UI.PixmapCache.getIcon("anychar.png"))
62 self.wildcardRepeatButton.setIcon(UI.PixmapCache.getIcon("repeat.png")) 68 self.wildcardRepeatButton.setIcon(UI.PixmapCache.getIcon("repeat.png"))
63 # W3C tool buttons 69 # W3C tool buttons
64 self.w3cCharButton.setIcon(UI.PixmapCache.getIcon("characters.png")) 70 self.w3cCharButton.setIcon(UI.PixmapCache.getIcon("characters.png"))
65 self.w3cAnycharButton.setIcon(UI.PixmapCache.getIcon("anychar.png")) 71 self.w3cAnycharButton.setIcon(UI.PixmapCache.getIcon("anychar.png"))
66 self.w3cRepeatButton.setIcon(UI.PixmapCache.getIcon("repeat.png")) 72 self.w3cRepeatButton.setIcon(UI.PixmapCache.getIcon("repeat.png"))
75 self.syntaxCombo.addItem("Fixed String", QRegExp.FixedString) 81 self.syntaxCombo.addItem("Fixed String", QRegExp.FixedString)
76 self.syntaxCombo.addItem("W3C XML Schema 1.1", QRegExp.W3CXmlSchema11) 82 self.syntaxCombo.addItem("W3C XML Schema 1.1", QRegExp.W3CXmlSchema11)
77 if qVersion() >= "5.0.0": 83 if qVersion() >= "5.0.0":
78 self.syntaxCombo.setCurrentIndex(1) 84 self.syntaxCombo.setCurrentIndex(1)
79 85
80 self.saveButton = \ 86 self.saveButton = self.buttonBox.addButton(
81 self.buttonBox.addButton(self.trUtf8("Save"), QDialogButtonBox.ActionRole) 87 self.trUtf8("Save"), QDialogButtonBox.ActionRole)
82 self.saveButton.setToolTip(self.trUtf8("Save the regular expression to a file")) 88 self.saveButton.setToolTip(
83 self.loadButton = \ 89 self.trUtf8("Save the regular expression to a file"))
84 self.buttonBox.addButton(self.trUtf8("Load"), QDialogButtonBox.ActionRole) 90 self.loadButton = self.buttonBox.addButton(
85 self.loadButton.setToolTip(self.trUtf8("Load a regular expression from a file")) 91 self.trUtf8("Load"), QDialogButtonBox.ActionRole)
86 self.validateButton = \ 92 self.loadButton.setToolTip(
87 self.buttonBox.addButton(self.trUtf8("Validate"), QDialogButtonBox.ActionRole) 93 self.trUtf8("Load a regular expression from a file"))
88 self.validateButton.setToolTip(self.trUtf8("Validate the regular expression")) 94 self.validateButton = self.buttonBox.addButton(
89 self.executeButton = \ 95 self.trUtf8("Validate"), QDialogButtonBox.ActionRole)
90 self.buttonBox.addButton(self.trUtf8("Execute"), QDialogButtonBox.ActionRole) 96 self.validateButton.setToolTip(
91 self.executeButton.setToolTip(self.trUtf8("Execute the regular expression")) 97 self.trUtf8("Validate the regular expression"))
92 self.nextButton = \ 98 self.executeButton = self.buttonBox.addButton(
93 self.buttonBox.addButton(self.trUtf8("Next match"), 99 self.trUtf8("Execute"), QDialogButtonBox.ActionRole)
94 QDialogButtonBox.ActionRole) 100 self.executeButton.setToolTip(
101 self.trUtf8("Execute the regular expression"))
102 self.nextButton = self.buttonBox.addButton(
103 self.trUtf8("Next match"), QDialogButtonBox.ActionRole)
95 self.nextButton.setToolTip( 104 self.nextButton.setToolTip(
96 self.trUtf8("Show the next match of the regular expression")) 105 self.trUtf8("Show the next match of the regular expression"))
97 self.nextButton.setEnabled(False) 106 self.nextButton.setEnabled(False)
98 107
99 if fromEric: 108 if fromEric:
100 self.buttonBox.setStandardButtons( 109 self.buttonBox.setStandardButtons(
101 QDialogButtonBox.Cancel | QDialogButtonBox.Ok) 110 QDialogButtonBox.Cancel | QDialogButtonBox.Ok)
102 self.copyButton = None 111 self.copyButton = None
103 else: 112 else:
104 self.copyButton = \ 113 self.copyButton = self.buttonBox.addButton(
105 self.buttonBox.addButton(self.trUtf8("Copy"), QDialogButtonBox.ActionRole) 114 self.trUtf8("Copy"), QDialogButtonBox.ActionRole)
106 self.copyButton.setToolTip( 115 self.copyButton.setToolTip(
107 self.trUtf8("Copy the regular expression to the clipboard")) 116 self.trUtf8("Copy the regular expression to the clipboard"))
108 self.buttonBox.setStandardButtons(QDialogButtonBox.Close) 117 self.buttonBox.setStandardButtons(QDialogButtonBox.Close)
109 self.variableLabel.hide() 118 self.variableLabel.hide()
110 self.variableLineEdit.hide() 119 self.variableLineEdit.hide()
225 @pyqtSlot() 234 @pyqtSlot()
226 def on_charButton_clicked(self): 235 def on_charButton_clicked(self):
227 """ 236 """
228 Private slot to handle the characters toolbutton. 237 Private slot to handle the characters toolbutton.
229 """ 238 """
230 from .QRegExpWizardCharactersDialog import QRegExpWizardCharactersDialog 239 from .QRegExpWizardCharactersDialog import \
240 QRegExpWizardCharactersDialog
231 dlg = QRegExpWizardCharactersDialog( 241 dlg = QRegExpWizardCharactersDialog(
232 mode=QRegExpWizardCharactersDialog.RegExpMode, parent=self) 242 mode=QRegExpWizardCharactersDialog.RegExpMode, parent=self)
233 if dlg.exec_() == QDialog.Accepted: 243 if dlg.exec_() == QDialog.Accepted:
234 self.__insertString(dlg.getCharacters()) 244 self.__insertString(dlg.getCharacters())
235 245
236 @pyqtSlot() 246 @pyqtSlot()
237 def on_wildcardCharButton_clicked(self): 247 def on_wildcardCharButton_clicked(self):
238 """ 248 """
239 Private slot to handle the wildcard characters toolbutton. 249 Private slot to handle the wildcard characters toolbutton.
240 """ 250 """
241 from .QRegExpWizardCharactersDialog import QRegExpWizardCharactersDialog 251 from .QRegExpWizardCharactersDialog import \
252 QRegExpWizardCharactersDialog
242 dlg = QRegExpWizardCharactersDialog( 253 dlg = QRegExpWizardCharactersDialog(
243 mode=QRegExpWizardCharactersDialog.WildcardMode, parent=self) 254 mode=QRegExpWizardCharactersDialog.WildcardMode, parent=self)
244 if dlg.exec_() == QDialog.Accepted: 255 if dlg.exec_() == QDialog.Accepted:
245 self.__insertString(dlg.getCharacters()) 256 self.__insertString(dlg.getCharacters())
246 257
261 @pyqtSlot() 272 @pyqtSlot()
262 def on_w3cCharButton_clicked(self): 273 def on_w3cCharButton_clicked(self):
263 """ 274 """
264 Private slot to handle the wildcard characters toolbutton. 275 Private slot to handle the wildcard characters toolbutton.
265 """ 276 """
266 from .QRegExpWizardCharactersDialog import QRegExpWizardCharactersDialog 277 from .QRegExpWizardCharactersDialog import \
278 QRegExpWizardCharactersDialog
267 dlg = QRegExpWizardCharactersDialog( 279 dlg = QRegExpWizardCharactersDialog(
268 mode=QRegExpWizardCharactersDialog.W3CMode, parent=self) 280 mode=QRegExpWizardCharactersDialog.W3CMode, parent=self)
269 if dlg.exec_() == QDialog.Accepted: 281 if dlg.exec_() == QDialog.Accepted:
270 self.__insertString(dlg.getCharacters()) 282 self.__insertString(dlg.getCharacters())
271 283
336 if not ext: 348 if not ext:
337 ex = selectedFilter.split("(*")[1].split(")")[0] 349 ex = selectedFilter.split("(*")[1].split(")")[0]
338 if ex: 350 if ex:
339 fname += ex 351 fname += ex
340 if QFileInfo(fname).exists(): 352 if QFileInfo(fname).exists():
341 res = E5MessageBox.yesNo(self, 353 res = E5MessageBox.yesNo(
354 self,
342 self.trUtf8("Save regular expression"), 355 self.trUtf8("Save regular expression"),
343 self.trUtf8("<p>The file <b>{0}</b> already exists." 356 self.trUtf8("<p>The file <b>{0}</b> already exists."
344 " Overwrite it?</p>").format(fname), 357 " Overwrite it?</p>").format(fname),
345 icon=E5MessageBox.Warning) 358 icon=E5MessageBox.Warning)
346 if not res: 359 if not res:
347 return 360 return
348 361
349 syntax = self.syntaxCombo.itemData(self.syntaxCombo.currentIndex()) 362 syntax = self.syntaxCombo.itemData(self.syntaxCombo.currentIndex())
350 try: 363 try:
351 f = open(Utilities.toNativeSeparators(fname), "w", encoding="utf-8") 364 f = open(
365 Utilities.toNativeSeparators(fname), "w", encoding="utf-8")
352 f.write("syntax={0}\n".format(syntax)) 366 f.write("syntax={0}\n".format(syntax))
353 f.write(self.regexpLineEdit.text()) 367 f.write(self.regexpLineEdit.text())
354 f.close() 368 f.close()
355 except IOError as err: 369 except IOError as err:
356 E5MessageBox.information(self, 370 E5MessageBox.information(
371 self,
357 self.trUtf8("Save regular expression"), 372 self.trUtf8("Save regular expression"),
358 self.trUtf8("""<p>The regular expression could not be saved.</p>""" 373 self.trUtf8("""<p>The regular expression could not"""
359 """<p>Reason: {0}</p>""").format(str(err))) 374 """ be saved.</p><p>Reason: {0}</p>""")
375 .format(str(err)))
360 376
361 @pyqtSlot() 377 @pyqtSlot()
362 def on_loadButton_clicked(self): 378 def on_loadButton_clicked(self):
363 """ 379 """
364 Private slot to load a regexp from a file. 380 Private slot to load a regexp from a file.
368 self.trUtf8("Load regular expression"), 384 self.trUtf8("Load regular expression"),
369 "", 385 "",
370 self.trUtf8("RegExp Files (*.rx);;All Files (*)")) 386 self.trUtf8("RegExp Files (*.rx);;All Files (*)"))
371 if fname: 387 if fname:
372 try: 388 try:
373 f = open(Utilities.toNativeSeparators(fname), "r", encoding="utf-8") 389 f = open(
390 Utilities.toNativeSeparators(fname), "r", encoding="utf-8")
374 regexp = f.read() 391 regexp = f.read()
375 f.close() 392 f.close()
376 if regexp.startswith("syntax="): 393 if regexp.startswith("syntax="):
377 lines = regexp.splitlines() 394 lines = regexp.splitlines()
378 syntax = int(lines[0].replace("syntax=", "")) 395 syntax = int(lines[0].replace("syntax=", ""))
379 index = self.syntaxCombo.findData(syntax) 396 index = self.syntaxCombo.findData(syntax)
380 self.syntaxCombo.setCurrentIndex(index) 397 self.syntaxCombo.setCurrentIndex(index)
381 regexp = lines[1] 398 regexp = lines[1]
382 self.regexpLineEdit.setText(regexp) 399 self.regexpLineEdit.setText(regexp)
383 except IOError as err: 400 except IOError as err:
384 E5MessageBox.information(self, 401 E5MessageBox.information(
402 self,
385 self.trUtf8("Save regular expression"), 403 self.trUtf8("Save regular expression"),
386 self.trUtf8("""<p>The regular expression could not be saved.</p>""" 404 self.trUtf8("""<p>The regular expression could not"""
387 """<p>Reason: {0}</p>""").format(str(err))) 405 """ be saved.</p><p>Reason: {0}</p>""")
406 .format(str(err)))
388 407
389 @pyqtSlot() 408 @pyqtSlot()
390 def on_copyButton_clicked(self): 409 def on_copyButton_clicked(self):
391 """ 410 """
392 Private slot to copy the regexp string into the clipboard. 411 Private slot to copy the regexp string into the clipboard.
412 if self.caseSensitiveCheckBox.isChecked(): 431 if self.caseSensitiveCheckBox.isChecked():
413 re.setCaseSensitivity(Qt.CaseSensitive) 432 re.setCaseSensitivity(Qt.CaseSensitive)
414 else: 433 else:
415 re.setCaseSensitivity(Qt.CaseInsensitive) 434 re.setCaseSensitivity(Qt.CaseInsensitive)
416 re.setMinimal(self.minimalCheckBox.isChecked()) 435 re.setMinimal(self.minimalCheckBox.isChecked())
417 re.setPatternSyntax(self.syntaxCombo.itemData(self.syntaxCombo.currentIndex())) 436 re.setPatternSyntax(
437 self.syntaxCombo.itemData(self.syntaxCombo.currentIndex()))
418 if re.isValid(): 438 if re.isValid():
419 E5MessageBox.information(self, 439 E5MessageBox.information(
440 self,
420 self.trUtf8("Validation"), 441 self.trUtf8("Validation"),
421 self.trUtf8("""The regular expression is valid.""")) 442 self.trUtf8("""The regular expression is valid."""))
422 else: 443 else:
423 E5MessageBox.critical(self, 444 E5MessageBox.critical(
445 self,
424 self.trUtf8("Error"), 446 self.trUtf8("Error"),
425 self.trUtf8("""Invalid regular expression: {0}""") 447 self.trUtf8("""Invalid regular expression: {0}""")
426 .format(re.errorString())) 448 .format(re.errorString()))
427 return 449 return
428 else: 450 else:
429 E5MessageBox.critical(self, 451 E5MessageBox.critical(
452 self,
430 self.trUtf8("Error"), 453 self.trUtf8("Error"),
431 self.trUtf8("""A regular expression must be given.""")) 454 self.trUtf8("""A regular expression must be given."""))
432 455
433 @pyqtSlot() 456 @pyqtSlot()
434 def on_executeButton_clicked(self, startpos=0): 457 def on_executeButton_clicked(self, startpos=0):
451 re.setMinimal(self.minimalCheckBox.isChecked()) 474 re.setMinimal(self.minimalCheckBox.isChecked())
452 syntax = self.syntaxCombo.itemData(self.syntaxCombo.currentIndex()) 475 syntax = self.syntaxCombo.itemData(self.syntaxCombo.currentIndex())
453 wildcard = syntax in [QRegExp.Wildcard, QRegExp.WildcardUnix] 476 wildcard = syntax in [QRegExp.Wildcard, QRegExp.WildcardUnix]
454 re.setPatternSyntax(syntax) 477 re.setPatternSyntax(syntax)
455 if not re.isValid(): 478 if not re.isValid():
456 E5MessageBox.critical(self, 479 E5MessageBox.critical(
480 self,
457 self.trUtf8("Error"), 481 self.trUtf8("Error"),
458 self.trUtf8("""Invalid regular expression: {0}""") 482 self.trUtf8("""Invalid regular expression: {0}""")
459 .format(re.errorString())) 483 .format(re.errorString()))
460 return 484 return
461 offset = re.indexIn(text, startpos) 485 offset = re.indexIn(text, startpos)
462 captures = re.captureCount() 486 captures = re.captureCount()
463 row = 0 487 row = 0
464 OFFSET = 5 488 OFFSET = 5
465 489
466 self.resultTable.setColumnCount(0) 490 self.resultTable.setColumnCount(0)
467 self.resultTable.setColumnCount(3) 491 self.resultTable.setColumnCount(3)
468 self.resultTable.setRowCount(0) 492 self.resultTable.setRowCount(0)
469 self.resultTable.setRowCount(OFFSET) 493 self.resultTable.setRowCount(OFFSET)
470 self.resultTable.setItem(row, 0, QTableWidgetItem(self.trUtf8("Regexp"))) 494 self.resultTable.setItem(
495 row, 0, QTableWidgetItem(self.trUtf8("Regexp")))
471 self.resultTable.setItem(row, 1, QTableWidgetItem(regex)) 496 self.resultTable.setItem(row, 1, QTableWidgetItem(regex))
472 497
473 if offset != -1: 498 if offset != -1:
474 self.lastMatchEnd = offset + re.matchedLength() 499 self.lastMatchEnd = offset + re.matchedLength()
475 self.nextButton.setEnabled(True) 500 self.nextButton.setEnabled(True)
476 row += 1 501 row += 1
477 self.resultTable.setItem(row, 0, QTableWidgetItem(self.trUtf8("Offset"))) 502 self.resultTable.setItem(
478 self.resultTable.setItem(row, 1, QTableWidgetItem("{0:d}".format(offset))) 503 row, 0, QTableWidgetItem(self.trUtf8("Offset")))
504 self.resultTable.setItem(
505 row, 1, QTableWidgetItem("{0:d}".format(offset)))
479 506
480 if not wildcard: 507 if not wildcard:
481 row += 1 508 row += 1
482 self.resultTable.setItem(row, 0, 509 self.resultTable.setItem(
483 QTableWidgetItem(self.trUtf8("Captures"))) 510 row, 0, QTableWidgetItem(self.trUtf8("Captures")))
484 self.resultTable.setItem(row, 1, 511 self.resultTable.setItem(
485 QTableWidgetItem("{0:d}".format(captures))) 512 row, 1, QTableWidgetItem("{0:d}".format(captures)))
486 row += 1 513 row += 1
487 self.resultTable.setItem(row, 1, 514 self.resultTable.setItem(
488 QTableWidgetItem(self.trUtf8("Text"))) 515 row, 1, QTableWidgetItem(self.trUtf8("Text")))
489 self.resultTable.setItem(row, 2, 516 self.resultTable.setItem(
490 QTableWidgetItem(self.trUtf8("Characters"))) 517 row, 2, QTableWidgetItem(self.trUtf8("Characters")))
491 518
492 row += 1 519 row += 1
493 self.resultTable.setItem(row, 0, 520 self.resultTable.setItem(
494 QTableWidgetItem(self.trUtf8("Match"))) 521 row, 0, QTableWidgetItem(self.trUtf8("Match")))
495 self.resultTable.setItem(row, 1, 522 self.resultTable.setItem(
496 QTableWidgetItem(re.cap(0))) 523 row, 1, QTableWidgetItem(re.cap(0)))
497 self.resultTable.setItem(row, 2, 524 self.resultTable.setItem(
525 row, 2,
498 QTableWidgetItem("{0:d}".format(re.matchedLength()))) 526 QTableWidgetItem("{0:d}".format(re.matchedLength())))
499 527
500 if not wildcard: 528 if not wildcard:
501 for i in range(1, captures + 1): 529 for i in range(1, captures + 1):
502 if len(re.cap(i)) > 0: 530 if len(re.cap(i)) > 0:
503 row += 1 531 row += 1
504 self.resultTable.insertRow(row) 532 self.resultTable.insertRow(row)
505 self.resultTable.setItem(row, 0, 533 self.resultTable.setItem(
506 QTableWidgetItem(self.trUtf8("Capture #{0}").format(i))) 534 row, 0,
507 self.resultTable.setItem(row, 1, 535 QTableWidgetItem(
536 self.trUtf8("Capture #{0}").format(i)))
537 self.resultTable.setItem(
538 row, 1,
508 QTableWidgetItem(re.cap(i))) 539 QTableWidgetItem(re.cap(i)))
509 self.resultTable.setItem(row, 2, 540 self.resultTable.setItem(
510 QTableWidgetItem("{0:d}".format(len(re.cap(i))))) 541 row, 2,
542 QTableWidgetItem(
543 "{0:d}".format(len(re.cap(i)))))
511 else: 544 else:
512 self.resultTable.setRowCount(3) 545 self.resultTable.setRowCount(3)
513 546
514 # highlight the matched text 547 # highlight the matched text
515 tc = self.textTextEdit.textCursor() 548 tc = self.textTextEdit.textCursor()
519 else: 552 else:
520 self.nextButton.setEnabled(False) 553 self.nextButton.setEnabled(False)
521 self.resultTable.setRowCount(2) 554 self.resultTable.setRowCount(2)
522 row += 1 555 row += 1
523 if startpos > 0: 556 if startpos > 0:
524 self.resultTable.setItem(row, 0, 557 self.resultTable.setItem(
558 row, 0,
525 QTableWidgetItem(self.trUtf8("No more matches"))) 559 QTableWidgetItem(self.trUtf8("No more matches")))
526 else: 560 else:
527 self.resultTable.setItem(row, 0, 561 self.resultTable.setItem(
562 row, 0,
528 QTableWidgetItem(self.trUtf8("No matches"))) 563 QTableWidgetItem(self.trUtf8("No matches")))
529 564
530 # remove the highlight 565 # remove the highlight
531 tc = self.textTextEdit.textCursor() 566 tc = self.textTextEdit.textCursor()
532 tc.setPosition(0) 567 tc.setPosition(0)
535 self.resultTable.resizeColumnsToContents() 570 self.resultTable.resizeColumnsToContents()
536 self.resultTable.resizeRowsToContents() 571 self.resultTable.resizeRowsToContents()
537 self.resultTable.verticalHeader().hide() 572 self.resultTable.verticalHeader().hide()
538 self.resultTable.horizontalHeader().hide() 573 self.resultTable.horizontalHeader().hide()
539 else: 574 else:
540 E5MessageBox.critical(self, 575 E5MessageBox.critical(
576 self,
541 self.trUtf8("Error"), 577 self.trUtf8("Error"),
542 self.trUtf8("""A regular expression and a text must be given.""")) 578 self.trUtf8("""A regular expression and a text must"""
579 """ be given."""))
543 580
544 @pyqtSlot() 581 @pyqtSlot()
545 def on_nextButton_clicked(self): 582 def on_nextButton_clicked(self):
546 """ 583 """
547 Private slot to find the next match. 584 Private slot to find the next match.
556 """ 593 """
557 self.nextButton.setEnabled(False) 594 self.nextButton.setEnabled(False)
558 595
559 def __getPatternSyntaxCode(self, syntaxValue): 596 def __getPatternSyntaxCode(self, syntaxValue):
560 """ 597 """
561 Private method to convert a pattern syntax value into a pattern syntax string. 598 Private method to convert a pattern syntax value into a
599 pattern syntax string.
562 600
563 @param syntaxValue pattern syntax value (integer) 601 @param syntaxValue pattern syntax value (integer)
564 @return pattern syntax string (string) 602 @return pattern syntax string (string)
565 """ 603 """
566 syntax = "QRegExp." 604 syntax = "QRegExp."
601 reVar, regexp.replace('"', '\\"'), os.linesep) 639 reVar, regexp.replace('"', '\\"'), os.linesep)
602 if not self.caseSensitiveCheckBox.isChecked(): 640 if not self.caseSensitiveCheckBox.isChecked():
603 code += '{0}{1}.setCaseSensitivity(Qt.CaseInsensitive){2}'.format( 641 code += '{0}{1}.setCaseSensitivity(Qt.CaseInsensitive){2}'.format(
604 istring, reVar, os.linesep) 642 istring, reVar, os.linesep)
605 if self.minimalCheckBox.isChecked(): 643 if self.minimalCheckBox.isChecked():
606 code += '{0}{1}.setMinimal(True){2}'.format(istring, reVar, os.linesep) 644 code += '{0}{1}.setMinimal(True){2}'.format(
645 istring, reVar, os.linesep)
607 syntax = self.syntaxCombo.itemData(self.syntaxCombo.currentIndex()) 646 syntax = self.syntaxCombo.itemData(self.syntaxCombo.currentIndex())
608 needPatternSyntax = True 647 needPatternSyntax = True
609 if qVersion() < "5.0.0" and syntax == QRegExp.RegExp or \ 648 if qVersion() < "5.0.0" and syntax == QRegExp.RegExp or \
610 qVersion() >= "5.0.0" and syntax == QRegExp.RegExp2: 649 qVersion() >= "5.0.0" and syntax == QRegExp.RegExp2:
611 # default value selected 650 # default value selected
612 needPatternSyntax = False 651 needPatternSyntax = False
613 if needPatternSyntax: 652 if needPatternSyntax:
614 code += '{0}{1}.setPatternSyntax({2}){3}'.format( 653 code += '{0}{1}.setPatternSyntax({2}){3}'.format(
615 istring, reVar, self.__getPatternSyntaxCode(syntax), estring) 654 istring, reVar, self.__getPatternSyntaxCode(syntax),
655 estring)
616 return code 656 return code
617 657
618 658
619 class QRegExpWizardDialog(QDialog): 659 class QRegExpWizardDialog(QDialog):
620 """ 660 """
668 self.cw = QRegExpWizardWidget(self, fromEric=False) 708 self.cw = QRegExpWizardWidget(self, fromEric=False)
669 size = self.cw.size() 709 size = self.cw.size()
670 self.setCentralWidget(self.cw) 710 self.setCentralWidget(self.cw)
671 self.resize(size) 711 self.resize(size)
672 712
673 self.setStyle(Preferences.getUI("Style"), Preferences.getUI("StyleSheet")) 713 self.setStyle(
714 Preferences.getUI("Style"), Preferences.getUI("StyleSheet"))
674 715
675 self.cw.buttonBox.accepted[()].connect(self.close) 716 self.cw.buttonBox.accepted[()].connect(self.close)
676 self.cw.buttonBox.rejected[()].connect(self.close) 717 self.cw.buttonBox.rejected[()].connect(self.close)

eric ide

mercurial