Skip to content

Commit acacf84

Browse files
committedMay 18, 2013
[pyqgis-console] adds more options to find text in the editor
1 parent 2df1a20 commit acacf84

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed
 

‎python/console/console.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,22 @@ def __init__(self, parent=None):
489489
self.findPrevButton.setIcon(QgsApplication.getThemeIcon("console/iconSearchPrevEditorConsole.png"))
490490
self.findPrevButton.setIconSize(QSize(24, 24))
491491
self.findPrevButton.setAutoRaise(True)
492+
self.caseSensitive = QCheckBox()
493+
caseSensTr = QCoreApplication.translate("PythonConsole", "Case Sensitive")
494+
self.caseSensitive.setText(caseSensTr)
495+
self.wholeWord = QCheckBox()
496+
wholeWordTr = QCoreApplication.translate("PythonConsole", "Whole Word")
497+
self.wholeWord.setText(wholeWordTr)
498+
self.wrapAround = QCheckBox()
499+
self.wrapAround.setChecked(True)
500+
wrapAroundTr = QCoreApplication.translate("PythonConsole", "Wrap Around")
501+
self.wrapAround.setText(wrapAroundTr)
492502
self.layoutFind.addWidget(self.lineEditFind, 0, 1, 1, 1)
493-
self.layoutFind.addWidget(self.findNextButton, 0, 3, 1, 1)
494503
self.layoutFind.addWidget(self.findPrevButton, 0, 2, 1, 1)
504+
self.layoutFind.addWidget(self.findNextButton, 0, 3, 1, 1)
505+
self.layoutFind.addWidget(self.caseSensitive, 0, 4, 1, 1)
506+
self.layoutFind.addWidget(self.wholeWord, 0, 5, 1, 1)
507+
self.layoutFind.addWidget(self.wrapAround, 0, 6, 1, 1)
495508

496509
##------------ Add first Tab in Editor -------------------------------
497510

@@ -528,20 +541,20 @@ def __init__(self, parent=None):
528541
self.lineEditFind.textChanged.connect(self._textFindChanged)
529542

530543
def _findText(self):
531-
self.tabEditorWidget.currentWidget().newEditor.findText()
544+
self.tabEditorWidget.currentWidget().newEditor.findText(True)
532545

533546
def _findNext(self):
534-
self.tabEditorWidget.currentWidget().newEditor.findText()
547+
self.tabEditorWidget.currentWidget().newEditor.findText(True)
535548

536549
def _findPrev(self):
537-
self.tabEditorWidget.currentWidget().newEditor.findText(True)
538-
self.tabEditorWidget.currentWidget().newEditor.findNext()
550+
self.tabEditorWidget.currentWidget().newEditor.findText(False)
539551

540552
def _textFindChanged(self):
541553
if not self.lineEditFind.text().isEmpty():
542554
self.findNextButton.setEnabled(True)
543555
self.findPrevButton.setEnabled(True)
544556
else:
557+
self.lineEditFind.setStyleSheet('')
545558
self.findNextButton.setEnabled(False)
546559
self.findPrevButton.setEnabled(False)
547560

‎python/console/console_editor.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -344,21 +344,32 @@ def contextMenuEvent(self, e):
344344
pasteAction.setEnabled(True)
345345
action = menu.exec_(self.mapToGlobal(e.pos()))
346346

347-
def findText(self, direction=False):
347+
def findText(self, forward):
348+
lineFrom, indexFrom, lineTo, indexTo = self.getSelection()
348349
line, index = self.getCursorPosition()
349350
text = self.parent.pc.lineEditFind.text()
350-
msgText = False
351+
re = False
352+
wrap = self.parent.pc.wrapAround.isChecked()
353+
cs = self.parent.pc.caseSensitive.isChecked()
354+
wo = self.parent.pc.wholeWord.isChecked()
355+
notFound = False
351356
if not text.isEmpty():
352-
if direction:
353-
if not self.findFirst(text, 1, 0, line, index, forward=False):
354-
msgText = True
355-
else:
356-
if not self.findFirst(text, 1, 0, line, index):
357-
msgText = True
358-
if msgText:
357+
if not forward:
358+
line = lineFrom
359+
index = indexFrom
360+
## findFirst(QString(), re bool, cs bool, wo bool, wrap, bool, forward=True)
361+
## re = Regular Expression, cs = Case Sensitive, wo = Whole Word, wrap = Wrap Around
362+
if not self.findFirst(text, re, cs, wo, wrap, forward, line, index):
363+
notFound = True
364+
if notFound:
365+
styleError = 'QLineEdit {background-color: #d65253; \
366+
color: #ffffff;}'
359367
msgText = QCoreApplication.translate('PythonConsole',
360368
'<b>"%1"</b> was not found.').arg(text)
361369
self.parent.pc.callWidgetMessageBarEditor(msgText, 0, True)
370+
else:
371+
styleError = ''
372+
self.parent.pc.lineEditFind.setStyleSheet(styleError)
362373

363374
def objectListEditor(self):
364375
listObj = self.parent.pc.listClassMethod

0 commit comments

Comments
 (0)
Please sign in to comment.