Skip to content
Permalink
Browse files

[pyqgis-console] adds a find text widget to editor

  • Loading branch information
slarosa committed May 2, 2013
1 parent 550825a commit 9ed506384485da521969eb6168333577bf0f5b93
@@ -99,6 +99,9 @@
<file>themes/default/console/iconMethodTreeWidgetConsole.png</file>
<file>themes/default/console/iconFunctionTreeWidgetConsole.png</file>
<file>themes/default/console/iconClassBrowserConsole.png</file>
<file>themes/default/console/iconSearchEditorConsole.png</file>
<file>themes/default/console/iconSearchNextEditorConsole.png</file>
<file>themes/default/console/iconSearchPrevEditorConsole.png</file>
<file>themes/default/extents.png</file>
<file>themes/default/favourites.png</file>
<file>themes/default/geographic.png</file>
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -28,6 +28,7 @@
from console_help import HelpDialog
from console_settings import optionsDialog
from qgis.core import QgsApplication
from qgis.gui import QgsFilterLineEdit

import sys
import os
@@ -242,6 +243,16 @@ def __init__(self, parent=None):
self.objectListButton.setIconVisibleInMenu(True)
self.objectListButton.setToolTip(objList)
self.objectListButton.setText(objList)
## Action for Find text
findText = QCoreApplication.translate("PythonConsole", "Find text")
self.findTextButton = QAction(parent)
self.findTextButton.setCheckable(True)
self.findTextButton.setEnabled(True)
self.findTextButton.setIcon(QgsApplication.getThemeIcon("console/iconSearchEditorConsole.png"))
self.findTextButton.setMenuRole(QAction.PreferencesRole)
self.findTextButton.setIconVisibleInMenu(True)
self.findTextButton.setToolTip(findText)
self.findTextButton.setText(findText)

##----------------Toolbar Console-------------------------------------

@@ -377,6 +388,8 @@ def __init__(self, parent=None):
self.toolBarEditor.addAction(self.saveFileButton)
self.toolBarEditor.addAction(self.saveAsFileButton)
self.toolBarEditor.addSeparator()
self.toolBarEditor.addAction(self.findTextButton)
self.toolBarEditor.addSeparator()
self.toolBarEditor.addAction(self.cutEditorButton)
self.toolBarEditor.addAction(self.copyEditorButton)
self.toolBarEditor.addAction(self.pasteEditorButton)
@@ -388,6 +401,34 @@ def __init__(self, parent=None):
self.toolBarEditor.addSeparator()
self.toolBarEditor.addAction(self.runScriptEditorButton)

## Layout for the find widget
self.widgetFind = QWidget(self)
self.layoutFind = QGridLayout(self.widgetFind)
self.layoutFind.setContentsMargins(0, 0, 0, 0)
self.lineEditFind = QgsFilterLineEdit()
self.lineEditFind.setPlaceholderText('Enter text to find...')
self.findNextButton = QToolButton()
self.findNextButton.setEnabled(False)
toolTipfindNext = QCoreApplication.translate("PythonConsole",
"Find Next")
self.findNextButton.setToolTip(toolTipfindNext)
self.findNextButton.setIcon(QgsApplication.getThemeIcon("console/iconSearchNextEditorConsole.png"))
self.findNextButton.setIconSize(QSize(24, 24))
self.findNextButton.setAutoRaise(True)
self.findPrevButton = QToolButton()
self.findPrevButton.setEnabled(False)
toolTipfindPrev = QCoreApplication.translate("PythonConsole",
"Find Previous")
self.findPrevButton.setToolTip(toolTipfindPrev)
self.findPrevButton.setIcon(QgsApplication.getThemeIcon("console/iconSearchPrevEditorConsole.png"))
self.findPrevButton.setIconSize(QSize(24, 24))
self.findPrevButton.setAutoRaise(True)
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.widgetFind.hide()

## Menu Import Class
self.classMenu = QMenu(self)
self.classMenu.addAction(self.loadSextanteButton)
@@ -431,8 +472,9 @@ def __init__(self, parent=None):
self.layoutEditor = QGridLayout(self.widgetEditor)
self.layoutEditor.setMargin(0)
self.layoutEditor.setSpacing(0)
self.layoutEditor.addWidget(self.widgetButtonEditor, 0, 0, 1, 1)
self.layoutEditor.addWidget(self.tabEditorWidget, 0, 1, 1, 1)
self.layoutEditor.addWidget(self.widgetButtonEditor, 0, 0, 2, 1)
self.layoutEditor.addWidget(self.tabEditorWidget, 1, 1, 1, 1)
self.layoutEditor.addWidget(self.widgetFind, 0, 1, 1, 1)

self.toolBarLayout = QGridLayout(self.widgetButton)
self.toolBarLayout.setMargin(0)
@@ -449,6 +491,7 @@ def __init__(self, parent=None):

##------------ Signal -------------------------------

self.findTextButton.toggled.connect(self.findTextEditor)
self.objectListButton.toggled.connect(self.toggleObjectListWidget)
self.commentEditorButton.triggered.connect(self.commentCode)
self.uncommentEditorButton.triggered.connect(self.uncommentCode)
@@ -471,6 +514,32 @@ def __init__(self, parent=None):
self.prefChanged)
self.connect(self.listClassMethod, SIGNAL('itemClicked(QTreeWidgetItem*, int)'),
self.onClickGoToLine)
self.lineEditFind.returnPressed.connect(self._findText)
self.findNextButton.clicked.connect(self._findNext)
self.findPrevButton.clicked.connect(self._findPrev)
self.lineEditFind.textChanged.connect(self._textFindChanged)

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

def _findNext(self, fromPrev=False):
if not fromPrev:
self._findText()
self.tabEditorWidget.currentWidget().newEditor.findNext()
else:
self.tabEditorWidget.currentWidget().newEditor.findNext()

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

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

def onClickGoToLine(self, item, column):
linenr = int(item.text(1))
@@ -498,6 +567,9 @@ def toggleEditor(self, checked):
def toggleObjectListWidget(self, checked):
self.listClassMethod.show() if checked else self.listClassMethod.hide()

def findTextEditor(self, checked):
self.widgetFind.show() if checked else self.widgetFind.hide()

def pasteEditor(self):
self.tabEditorWidget.currentWidget().newEditor.paste()

@@ -147,13 +147,14 @@ def __init__(self, parent=None):
self.SendScintilla(QsciScintilla.SCI_CLEARCMDKEY, ord('L')+ ctrl)
self.SendScintilla(QsciScintilla.SCI_CLEARCMDKEY, ord('T')+ ctrl)
self.SendScintilla(QsciScintilla.SCI_CLEARCMDKEY, ord('D')+ ctrl)
#self.SendScintilla(QsciScintilla.SCI_CLEARCMDKEY, ord('Z')+ ctrl)
self.SendScintilla(QsciScintilla.SCI_CLEARCMDKEY, ord('Y')+ ctrl)
self.SendScintilla(QsciScintilla.SCI_CLEARCMDKEY, ord('L')+ ctrl+shift)

## New QShortcut = ctrl+space/ctrl+alt+space for Autocomplete
self.newShortcutCS = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_Space), self)
self.newShortcutCS.setContext(Qt.WidgetShortcut)
self.redoScut = QShortcut(QKeySequence(Qt.CTRL + Qt.SHIFT + Qt.Key_Z), self)
self.redoScut.setContext(Qt.WidgetShortcut)
self.redoScut.activated.connect(self.redo)
self.newShortcutCS.activated.connect(self.autoCompleteKeyBinding)
self.runScut = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_E), self)
self.runScut.setContext(Qt.WidgetShortcut)
@@ -266,6 +267,7 @@ def contextMenuEvent(self, e):
iconCommentEditor = QgsApplication.getThemeIcon("console/iconCommentEditorConsole.png")
iconUncommentEditor = QgsApplication.getThemeIcon("console/iconUncommentEditorConsole.png")
iconSettings = QgsApplication.getThemeIcon("console/iconSettingsConsole.png")
iconFind = QgsApplication.getThemeIcon("console/iconSearchEditorConsole.png")
hideEditorAction = menu.addAction("Hide Editor",
self.hideEditor)
menu.addSeparator()
@@ -283,7 +285,11 @@ def contextMenuEvent(self, e):
self.runScriptCode, 'Shift+Ctrl+E')
menu.addSeparator()
undoAction = menu.addAction("Undo", self.undo, QKeySequence.Undo)
redoAction = menu.addAction("Redo", self.redo, QKeySequence.Redo)
redoAction = menu.addAction("Redo", self.redo, 'Ctrl+Shift+Z')
menu.addSeparator()
findAction = menu.addAction(iconFind,
"Find Text",
self.showFindWidget)
menu.addSeparator()
cutAction = menu.addAction("Cut",
self.cut,
@@ -338,6 +344,18 @@ def contextMenuEvent(self, e):
if QApplication.clipboard().text() != "":
pasteAction.setEnabled(True)
action = menu.exec_(self.mapToGlobal(e.pos()))

def findText(self, direction=False):
line, index = self.getCursorPosition()
text = self.parent.pc.lineEditFind.text()
if text:
if direction:
self.findFirst(text, 1, 0, line, index, forward=False)
else:
if not self.findFirst(text, 1, 0, line, index):
msgText = QCoreApplication.translate('PythonConsole',
'<b>"%1"</b> was not found.').arg(text)
self.parent.pc.callWidgetMessageBarEditor(msgText, 0, True)

def objectListEditor(self):
listObj = self.parent.pc.listClassMethod
@@ -381,6 +399,15 @@ def hideEditor(self):
self.parent.pc.splitterObj.hide()
self.parent.pc.showEditorButton.setChecked(False)

def showFindWidget(self):
wF = self.parent.pc.widgetFind
if wF.isVisible():
wF.hide()
self.parent.pc.findTextButton.setChecked(False)
else:
wF.show()
self.parent.pc.findTextButton.setChecked(True)

def commentEditorCode(self, commentCheck):
self.beginUndoAction()
if self.hasSelectedText():
@@ -553,7 +580,7 @@ def __init__(self, parent, parentConsole, filename, *args):
self.newEditor = Editor(self)
if filename:
self.path = filename
if os.path.exists(filename)
if os.path.exists(filename):
self.loadFile(filename, False)

# Creates layout for message bar

0 comments on commit 9ed5063

Please sign in to comment.
You can’t perform that action at this time.