Skip to content

Commit

Permalink
[pyqgis-console] adds more options to find text in the editor
Browse files Browse the repository at this point in the history
  • Loading branch information
slarosa committed May 18, 2013
1 parent 2df1a20 commit acacf84
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
23 changes: 18 additions & 5 deletions python/console/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,22 @@ def __init__(self, parent=None):
self.findPrevButton.setIcon(QgsApplication.getThemeIcon("console/iconSearchPrevEditorConsole.png"))
self.findPrevButton.setIconSize(QSize(24, 24))
self.findPrevButton.setAutoRaise(True)
self.caseSensitive = QCheckBox()
caseSensTr = QCoreApplication.translate("PythonConsole", "Case Sensitive")
self.caseSensitive.setText(caseSensTr)
self.wholeWord = QCheckBox()
wholeWordTr = QCoreApplication.translate("PythonConsole", "Whole Word")
self.wholeWord.setText(wholeWordTr)
self.wrapAround = QCheckBox()
self.wrapAround.setChecked(True)
wrapAroundTr = QCoreApplication.translate("PythonConsole", "Wrap Around")
self.wrapAround.setText(wrapAroundTr)
self.layoutFind.addWidget(self.lineEditFind, 0, 1, 1, 1)
self.layoutFind.addWidget(self.findNextButton, 0, 3, 1, 1)
self.layoutFind.addWidget(self.findPrevButton, 0, 2, 1, 1)
self.layoutFind.addWidget(self.findNextButton, 0, 3, 1, 1)
self.layoutFind.addWidget(self.caseSensitive, 0, 4, 1, 1)
self.layoutFind.addWidget(self.wholeWord, 0, 5, 1, 1)
self.layoutFind.addWidget(self.wrapAround, 0, 6, 1, 1)

##------------ Add first Tab in Editor -------------------------------

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

def _findText(self):
self.tabEditorWidget.currentWidget().newEditor.findText()
self.tabEditorWidget.currentWidget().newEditor.findText(True)

def _findNext(self):
self.tabEditorWidget.currentWidget().newEditor.findText()
self.tabEditorWidget.currentWidget().newEditor.findText(True)

def _findPrev(self):
self.tabEditorWidget.currentWidget().newEditor.findText(True)
self.tabEditorWidget.currentWidget().newEditor.findNext()
self.tabEditorWidget.currentWidget().newEditor.findText(False)

def _textFindChanged(self):
if not self.lineEditFind.text().isEmpty():
self.findNextButton.setEnabled(True)
self.findPrevButton.setEnabled(True)
else:
self.lineEditFind.setStyleSheet('')
self.findNextButton.setEnabled(False)
self.findPrevButton.setEnabled(False)

Expand Down
29 changes: 20 additions & 9 deletions python/console/console_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,21 +344,32 @@ def contextMenuEvent(self, e):
pasteAction.setEnabled(True)
action = menu.exec_(self.mapToGlobal(e.pos()))

def findText(self, direction=False):
def findText(self, forward):
lineFrom, indexFrom, lineTo, indexTo = self.getSelection()
line, index = self.getCursorPosition()
text = self.parent.pc.lineEditFind.text()
msgText = False
re = False
wrap = self.parent.pc.wrapAround.isChecked()
cs = self.parent.pc.caseSensitive.isChecked()
wo = self.parent.pc.wholeWord.isChecked()
notFound = False
if not text.isEmpty():
if direction:
if not self.findFirst(text, 1, 0, line, index, forward=False):
msgText = True
else:
if not self.findFirst(text, 1, 0, line, index):
msgText = True
if msgText:
if not forward:
line = lineFrom
index = indexFrom
## findFirst(QString(), re bool, cs bool, wo bool, wrap, bool, forward=True)
## re = Regular Expression, cs = Case Sensitive, wo = Whole Word, wrap = Wrap Around
if not self.findFirst(text, re, cs, wo, wrap, forward, line, index):
notFound = True
if notFound:
styleError = 'QLineEdit {background-color: #d65253; \
color: #ffffff;}'
msgText = QCoreApplication.translate('PythonConsole',
'<b>"%1"</b> was not found.').arg(text)
self.parent.pc.callWidgetMessageBarEditor(msgText, 0, True)
else:
styleError = ''
self.parent.pc.lineEditFind.setStyleSheet(styleError)

def objectListEditor(self):
listObj = self.parent.pc.listClassMethod
Expand Down

0 comments on commit acacf84

Please sign in to comment.