Skip to content

Commit

Permalink
Added keys binding to view the command history
Browse files Browse the repository at this point in the history
- added new command to clear completely the command history
- fixed copy,cut command in keyPressEvent more minor problems
- update for help
- update for Italian translate
  • Loading branch information
slarosa committed Sep 26, 2012
1 parent f93cdff commit 29aeac7
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 74 deletions.
6 changes: 6 additions & 0 deletions i18n/qgis_it.ts
Expand Up @@ -6281,6 +6281,12 @@ Cambiare questa situazione prima, perché il plugin OSM non quale layer è la de
<source>Run command</source>
<translation>Esegui comando</translation>
</message>
<message>
<source>Are you sure you want to completely
delete the command history ?</source>
<translation>Sei sicuro di voler concellare completamente
la cronologia dei comandi ?</translation>
</message>
<message>
<source>## History saved successfully ##</source>
<translation>## Storia comandi salvata con successo ##</translation>
Expand Down
143 changes: 71 additions & 72 deletions python/console_sci.py
Expand Up @@ -114,7 +114,12 @@ def __init__(self, parent=None):
self.newShortcutCS = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_Space), self)
self.newShortcutCAS = QShortcut(QKeySequence(Qt.CTRL + Qt.ALT + Qt.Key_Space), self)
self.newShortcutCS.activated.connect(self.autoComplete)
self.newShortcutCAS.activated.connect(self.autoComplete)
self.newShortcutCAS.activated.connect(self.showHistory)
self.connect(self, SIGNAL('userListActivated(int, const QString)'),
self.completion_list_selected)

def showHistory(self):
self.showUserList(1, QStringList(self.history))

def autoComplete(self):
self.autoCompleteFromAll()
Expand Down Expand Up @@ -161,8 +166,6 @@ def setLexers(self, lexer):
self.setMarginsFont(font)
self.lexer = QsciLexerPython()
self.lexer.setDefaultFont(font)
#self.lexer.setDefaultFont(QFont('Mono', 10, 0, False))
#self.lexer.setDefaultColor(Qt.darkGray)
self.lexer.setColor(Qt.red, 1)
self.lexer.setColor(Qt.darkGreen, 5)
self.lexer.setColor(Qt.darkBlue, 15)
Expand All @@ -171,44 +174,25 @@ def setLexers(self, lexer):
self.lexer.setFont(font, 4)
self.api = QsciAPIs(self.lexer)
self.api.loadPrepared(QString(os.path.dirname(__file__) + "/api/pyqgis_master.pap"))
# self.api.load(os.path.dirname(__file__) + "/api/PyQGIS_1.8.api")
# self.api.load(os.path.dirname(__file__) + "/api/osgeo_gdal-ogr_1.9.1-1.api")
# self.api.load("qgis.networkanalysis.api")
# self.api.load("qgis.gui.api")
# self.api.load("qgis.core.api")
# self.api.load("qgis.analysis.api")

# self.api.prepare()
# self.lexer.setAPIs(self.api)
self.setLexer(self.lexer)

## TODO: show completion list for file and directory
# def show_completion_list(self, completions, text):
# """Private method to display the possible completions"""
# if len(completions) == 0:
# return
# if len(completions) > 1:
# self.showUserList(1, QStringList(sorted(completions)))
# self.completion_chars = 1
# else:
# txt = completions[0]
# if text != "":
# txt = txt.replace(text, "")
# self.insert(txt)
# self.completion_chars = 0
#
# def show_file_completion(self):
# """Display a completion list for files and directories"""
# cwd = os.getcwdu()
# self.show_completion_list(self.listdir_fullpath('/'), cwd)
#
# def listdir_fullpath(self, d):
# return [os.path.join(d, f) for f in os.listdir(d)]
## TODO: show completion list for file and directory

def completion_list_selected(self, id, txt):
if id == 1:
txt = unicode(txt)
# get current cursor position
line, pos = self.getCurLine()
selCmd= self.text(line).length()
# select typed text
self.setSelection(line, 4, line, selCmd)
self.removeSelectedText()
self.insert(txt)


def insertInitText(self):
#self.setLexers(False)
txtInit = QCoreApplication.translate("PythonConsole","## To access Quantum GIS environment from this console\n"
txtInit = QCoreApplication.translate("PythonConsole",
"## To access Quantum GIS environment from this console\n"
"## use qgis.utils.iface object (instance of QgisInterface class). Read help for more info.\n\n")
initText = self.setText(txtInit)

Expand Down Expand Up @@ -379,7 +363,39 @@ def keyPressEvent(self, e):
self.entered()
elif e.modifiers() & Qt.ControlModifier:
if e.key() == Qt.Key_V:
self.paste()
self.paste()
elif e.key() == Qt.Key_C:
self.copy()
elif e.key() == Qt.Key_X:
self.cut()
elif e.key() == Qt.Key_Left:
e.accept()
if e.modifiers() & Qt.ShiftModifier:
if index > 4:
if e.modifiers() & Qt.ControlModifier:
self.SendScintilla(QsciScintilla.SCI_WORDLEFTEXTEND)
else:
self.SendScintilla(QsciScintilla.SCI_CHARLEFTEXTEND)
else:
if index > 4:
if e.modifiers() & Qt.ControlModifier:
self.SendScintilla(QsciScintilla.SCI_WORDLEFT)
else:
self.SendScintilla(QsciScintilla.SCI_CHARLEFT)
elif e.key() == Qt.Key_Right:
e.accept()
if e.modifiers() & Qt.ShiftModifier:
if index >= 4:
if e.modifiers() & Qt.ControlModifier:
self.SendScintilla(QsciScintilla.SCI_WORDRIGHTEXTEND)
else:
self.SendScintilla(QsciScintilla.SCI_CHARRIGHTEXTEND)
else:
if index >= 4:
if e.modifiers() & Qt.ControlModifier:
self.SendScintilla(QsciScintilla.SCI_WORDRIGHT)
else:
self.SendScintilla(QsciScintilla.SCI_CHARRIGHT)
elif e.key() == Qt.Key_Backspace:
curPos, pos = self.getCursorPosition()
line = self.lines() -1
Expand All @@ -401,39 +417,7 @@ def keyPressEvent(self, e):
self.showPrevious()
elif e.key() == Qt.Key_Up and not self.isListActive():
self.showNext()
elif e.key() == Qt.Key_Left:
e.accept()
if e.modifiers() & Qt.ShiftModifier:
if index > 4:
if e.modifiers() & Qt.ControlModifier:
self.SendScintilla(QsciScintilla.SCI_WORDLEFTEXTEND)
else:
self.SendScintilla(QsciScintilla.SCI_CHARLEFTEXTEND)
else:
if index > 4:
if e.modifiers() & Qt.ControlModifier:
self.SendScintilla(QsciScintilla.SCI_WORDLEFT)
else:
self.SendScintilla(QsciScintilla.SCI_CHARLEFT)
elif e.key() == Qt.Key_Right:
e.accept()
if e.modifiers() & Qt.ShiftModifier:
if index >= 4:
if e.modifiers() & Qt.ControlModifier:
self.SendScintilla(QsciScintilla.SCI_WORDRIGHTEXTEND)
else:
self.SendScintilla(QsciScintilla.SCI_CHARRIGHTEXTEND)
else:
if index >= 4:
if e.modifiers() & Qt.ControlModifier:
self.SendScintilla(QsciScintilla.SCI_WORDRIGHT)
else:
self.SendScintilla(QsciScintilla.SCI_CHARRIGHT)
## TODO: press event for auto-completion file directory
#elif e.key() == Qt.Key_Tab:
#self.show_file_completion()
#else:
#self.on_new_line()
else:
QsciScintilla.keyPressEvent(self, e)

Expand Down Expand Up @@ -499,13 +483,28 @@ def currentCommand(self):
def runCommand(self, cmd):
self.updateHistory(cmd)
self.SendScintilla(QsciScintilla.SCI_NEWLINE)
if cmd in ('_save', '_clear'):
if cmd in ('_save', '_clear', '_clearAll'):
if cmd == '_save':
self.writeHistoryFile()
print QCoreApplication.translate("PythonConsole", "## History saved successfully ##")
print QCoreApplication.translate("PythonConsole",
"## History saved successfully ##")
elif cmd == '_clear':
self.clearHistoryFile()
print QCoreApplication.translate("PythonConsole", "## History cleared successfully ##")
print QCoreApplication.translate("PythonConsole",
"## History cleared successfully ##")
elif cmd == '_clearAll':
res = QMessageBox.question(self, "Python Console",
QCoreApplication.translate("PythonConsole",
"Are you sure you want to completely\n"
"delete the command history ?"),
QMessageBox.Yes | QMessageBox.No)
if res == QMessageBox.No:
self.SendScintilla(QsciScintilla.SCI_DELETEBACK)
return
self.history = QStringList()
self.clearHistoryFile()
print QCoreApplication.translate("PythonConsole",
"## History cleared successfully ##")
output = sys.stdout.get_and_clean_data()
if output:
self.append(output)
Expand Down
19 changes: 17 additions & 2 deletions python/helpConsole/help.htm
Expand Up @@ -41,6 +41,7 @@ <h4>Features</h4>
</tr>
</table>
<p align="justify">
<ul>
<li>Auto-completion and highlighting syntax for the following APIs:
<ol>
<li>Python</li>
Expand All @@ -50,9 +51,23 @@ <h4>Features</h4>
<li>osgeo-gdal-ogr</li>
</ol>
</li>
<li>Saves command history by typing <b>_save</b> or closing the widget.</li>
<br>
<li>Clears command history by typing <b>_clear</b>.</li>
<li>CTRL+SPACE to view the auto-completion list.</li>
<br>
<li>CTRL+ALT+SPACE to view the command history list.</li>
<br>
<li>Saves command history by typing <b>_save</b> or closing the widget.<br>
This command saves the history command in the file ~/.qgis/console_history.txt
</li>
<br>
<li>Clears command history by typing <b>_clear</b>.<br>
This command clears the history command from file ~/.qgis/console_history.txt
</li>
<br>
<li>Clears completely command history by typing <b>_clearAll</b>.<br>
This command clears completely the history command. It has an irreversible effect.
</li>
</ul>
</p>
<table id="header">
<tr>
Expand Down

0 comments on commit 29aeac7

Please sign in to comment.