Skip to content

Commit 29aeac7

Browse files
committed
Added keys binding to view the command 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
1 parent f93cdff commit 29aeac7

File tree

3 files changed

+94
-74
lines changed

3 files changed

+94
-74
lines changed

i18n/qgis_it.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6281,6 +6281,12 @@ Cambiare questa situazione prima, perché il plugin OSM non quale layer è la de
62816281
<source>Run command</source>
62826282
<translation>Esegui comando</translation>
62836283
</message>
6284+
<message>
6285+
<source>Are you sure you want to completely
6286+
delete the command history ?</source>
6287+
<translation>Sei sicuro di voler concellare completamente
6288+
la cronologia dei comandi ?</translation>
6289+
</message>
62846290
<message>
62856291
<source>## History saved successfully ##</source>
62866292
<translation>## Storia comandi salvata con successo ##</translation>

python/console_sci.py

Lines changed: 71 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,12 @@ def __init__(self, parent=None):
114114
self.newShortcutCS = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_Space), self)
115115
self.newShortcutCAS = QShortcut(QKeySequence(Qt.CTRL + Qt.ALT + Qt.Key_Space), self)
116116
self.newShortcutCS.activated.connect(self.autoComplete)
117-
self.newShortcutCAS.activated.connect(self.autoComplete)
117+
self.newShortcutCAS.activated.connect(self.showHistory)
118+
self.connect(self, SIGNAL('userListActivated(int, const QString)'),
119+
self.completion_list_selected)
120+
121+
def showHistory(self):
122+
self.showUserList(1, QStringList(self.history))
118123

119124
def autoComplete(self):
120125
self.autoCompleteFromAll()
@@ -161,8 +166,6 @@ def setLexers(self, lexer):
161166
self.setMarginsFont(font)
162167
self.lexer = QsciLexerPython()
163168
self.lexer.setDefaultFont(font)
164-
#self.lexer.setDefaultFont(QFont('Mono', 10, 0, False))
165-
#self.lexer.setDefaultColor(Qt.darkGray)
166169
self.lexer.setColor(Qt.red, 1)
167170
self.lexer.setColor(Qt.darkGreen, 5)
168171
self.lexer.setColor(Qt.darkBlue, 15)
@@ -171,44 +174,25 @@ def setLexers(self, lexer):
171174
self.lexer.setFont(font, 4)
172175
self.api = QsciAPIs(self.lexer)
173176
self.api.loadPrepared(QString(os.path.dirname(__file__) + "/api/pyqgis_master.pap"))
174-
# self.api.load(os.path.dirname(__file__) + "/api/PyQGIS_1.8.api")
175-
# self.api.load(os.path.dirname(__file__) + "/api/osgeo_gdal-ogr_1.9.1-1.api")
176-
# self.api.load("qgis.networkanalysis.api")
177-
# self.api.load("qgis.gui.api")
178-
# self.api.load("qgis.core.api")
179-
# self.api.load("qgis.analysis.api")
180-
181-
# self.api.prepare()
182-
# self.lexer.setAPIs(self.api)
183177
self.setLexer(self.lexer)
184178

185-
## TODO: show completion list for file and directory
186-
# def show_completion_list(self, completions, text):
187-
# """Private method to display the possible completions"""
188-
# if len(completions) == 0:
189-
# return
190-
# if len(completions) > 1:
191-
# self.showUserList(1, QStringList(sorted(completions)))
192-
# self.completion_chars = 1
193-
# else:
194-
# txt = completions[0]
195-
# if text != "":
196-
# txt = txt.replace(text, "")
197-
# self.insert(txt)
198-
# self.completion_chars = 0
199-
#
200-
# def show_file_completion(self):
201-
# """Display a completion list for files and directories"""
202-
# cwd = os.getcwdu()
203-
# self.show_completion_list(self.listdir_fullpath('/'), cwd)
204-
#
205-
# def listdir_fullpath(self, d):
206-
# return [os.path.join(d, f) for f in os.listdir(d)]
179+
## TODO: show completion list for file and directory
180+
181+
def completion_list_selected(self, id, txt):
182+
if id == 1:
183+
txt = unicode(txt)
184+
# get current cursor position
185+
line, pos = self.getCurLine()
186+
selCmd= self.text(line).length()
187+
# select typed text
188+
self.setSelection(line, 4, line, selCmd)
189+
self.removeSelectedText()
190+
self.insert(txt)
207191

208-
209192
def insertInitText(self):
210193
#self.setLexers(False)
211-
txtInit = QCoreApplication.translate("PythonConsole","## To access Quantum GIS environment from this console\n"
194+
txtInit = QCoreApplication.translate("PythonConsole",
195+
"## To access Quantum GIS environment from this console\n"
212196
"## use qgis.utils.iface object (instance of QgisInterface class). Read help for more info.\n\n")
213197
initText = self.setText(txtInit)
214198

@@ -379,7 +363,39 @@ def keyPressEvent(self, e):
379363
self.entered()
380364
elif e.modifiers() & Qt.ControlModifier:
381365
if e.key() == Qt.Key_V:
382-
self.paste()
366+
self.paste()
367+
elif e.key() == Qt.Key_C:
368+
self.copy()
369+
elif e.key() == Qt.Key_X:
370+
self.cut()
371+
elif e.key() == Qt.Key_Left:
372+
e.accept()
373+
if e.modifiers() & Qt.ShiftModifier:
374+
if index > 4:
375+
if e.modifiers() & Qt.ControlModifier:
376+
self.SendScintilla(QsciScintilla.SCI_WORDLEFTEXTEND)
377+
else:
378+
self.SendScintilla(QsciScintilla.SCI_CHARLEFTEXTEND)
379+
else:
380+
if index > 4:
381+
if e.modifiers() & Qt.ControlModifier:
382+
self.SendScintilla(QsciScintilla.SCI_WORDLEFT)
383+
else:
384+
self.SendScintilla(QsciScintilla.SCI_CHARLEFT)
385+
elif e.key() == Qt.Key_Right:
386+
e.accept()
387+
if e.modifiers() & Qt.ShiftModifier:
388+
if index >= 4:
389+
if e.modifiers() & Qt.ControlModifier:
390+
self.SendScintilla(QsciScintilla.SCI_WORDRIGHTEXTEND)
391+
else:
392+
self.SendScintilla(QsciScintilla.SCI_CHARRIGHTEXTEND)
393+
else:
394+
if index >= 4:
395+
if e.modifiers() & Qt.ControlModifier:
396+
self.SendScintilla(QsciScintilla.SCI_WORDRIGHT)
397+
else:
398+
self.SendScintilla(QsciScintilla.SCI_CHARRIGHT)
383399
elif e.key() == Qt.Key_Backspace:
384400
curPos, pos = self.getCursorPosition()
385401
line = self.lines() -1
@@ -401,39 +417,7 @@ def keyPressEvent(self, e):
401417
self.showPrevious()
402418
elif e.key() == Qt.Key_Up and not self.isListActive():
403419
self.showNext()
404-
elif e.key() == Qt.Key_Left:
405-
e.accept()
406-
if e.modifiers() & Qt.ShiftModifier:
407-
if index > 4:
408-
if e.modifiers() & Qt.ControlModifier:
409-
self.SendScintilla(QsciScintilla.SCI_WORDLEFTEXTEND)
410-
else:
411-
self.SendScintilla(QsciScintilla.SCI_CHARLEFTEXTEND)
412-
else:
413-
if index > 4:
414-
if e.modifiers() & Qt.ControlModifier:
415-
self.SendScintilla(QsciScintilla.SCI_WORDLEFT)
416-
else:
417-
self.SendScintilla(QsciScintilla.SCI_CHARLEFT)
418-
elif e.key() == Qt.Key_Right:
419-
e.accept()
420-
if e.modifiers() & Qt.ShiftModifier:
421-
if index >= 4:
422-
if e.modifiers() & Qt.ControlModifier:
423-
self.SendScintilla(QsciScintilla.SCI_WORDRIGHTEXTEND)
424-
else:
425-
self.SendScintilla(QsciScintilla.SCI_CHARRIGHTEXTEND)
426-
else:
427-
if index >= 4:
428-
if e.modifiers() & Qt.ControlModifier:
429-
self.SendScintilla(QsciScintilla.SCI_WORDRIGHT)
430-
else:
431-
self.SendScintilla(QsciScintilla.SCI_CHARRIGHT)
432420
## TODO: press event for auto-completion file directory
433-
#elif e.key() == Qt.Key_Tab:
434-
#self.show_file_completion()
435-
#else:
436-
#self.on_new_line()
437421
else:
438422
QsciScintilla.keyPressEvent(self, e)
439423

@@ -499,13 +483,28 @@ def currentCommand(self):
499483
def runCommand(self, cmd):
500484
self.updateHistory(cmd)
501485
self.SendScintilla(QsciScintilla.SCI_NEWLINE)
502-
if cmd in ('_save', '_clear'):
486+
if cmd in ('_save', '_clear', '_clearAll'):
503487
if cmd == '_save':
504488
self.writeHistoryFile()
505-
print QCoreApplication.translate("PythonConsole", "## History saved successfully ##")
489+
print QCoreApplication.translate("PythonConsole",
490+
"## History saved successfully ##")
506491
elif cmd == '_clear':
507492
self.clearHistoryFile()
508-
print QCoreApplication.translate("PythonConsole", "## History cleared successfully ##")
493+
print QCoreApplication.translate("PythonConsole",
494+
"## History cleared successfully ##")
495+
elif cmd == '_clearAll':
496+
res = QMessageBox.question(self, "Python Console",
497+
QCoreApplication.translate("PythonConsole",
498+
"Are you sure you want to completely\n"
499+
"delete the command history ?"),
500+
QMessageBox.Yes | QMessageBox.No)
501+
if res == QMessageBox.No:
502+
self.SendScintilla(QsciScintilla.SCI_DELETEBACK)
503+
return
504+
self.history = QStringList()
505+
self.clearHistoryFile()
506+
print QCoreApplication.translate("PythonConsole",
507+
"## History cleared successfully ##")
509508
output = sys.stdout.get_and_clean_data()
510509
if output:
511510
self.append(output)

python/helpConsole/help.htm

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ <h4>Features</h4>
4141
</tr>
4242
</table>
4343
<p align="justify">
44+
<ul>
4445
<li>Auto-completion and highlighting syntax for the following APIs:
4546
<ol>
4647
<li>Python</li>
@@ -50,9 +51,23 @@ <h4>Features</h4>
5051
<li>osgeo-gdal-ogr</li>
5152
</ol>
5253
</li>
53-
<li>Saves command history by typing <b>_save</b> or closing the widget.</li>
5454
<br>
55-
<li>Clears command history by typing <b>_clear</b>.</li>
55+
<li>CTRL+SPACE to view the auto-completion list.</li>
56+
<br>
57+
<li>CTRL+ALT+SPACE to view the command history list.</li>
58+
<br>
59+
<li>Saves command history by typing <b>_save</b> or closing the widget.<br>
60+
This command saves the history command in the file ~/.qgis/console_history.txt
61+
</li>
62+
<br>
63+
<li>Clears command history by typing <b>_clear</b>.<br>
64+
This command clears the history command from file ~/.qgis/console_history.txt
65+
</li>
66+
<br>
67+
<li>Clears completely command history by typing <b>_clearAll</b>.<br>
68+
This command clears completely the history command. It has an irreversible effect.
69+
</li>
70+
</ul>
5671
</p>
5772
<table id="header">
5873
<tr>

0 commit comments

Comments
 (0)