mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
[pyqgis-console] adds more options to find text in the editor
This commit is contained in:
parent
2df1a20ccb
commit
acacf84845
@ -489,9 +489,22 @@ class PythonConsoleWidget(QWidget):
|
||||
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 -------------------------------
|
||||
|
||||
@ -528,20 +541,20 @@ class PythonConsoleWidget(QWidget):
|
||||
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)
|
||||
|
||||
|
@ -344,21 +344,32 @@ class Editor(QsciScintilla):
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user