@@ -114,7 +114,12 @@ def __init__(self, parent=None):
114
114
self .newShortcutCS = QShortcut (QKeySequence (Qt .CTRL + Qt .Key_Space ), self )
115
115
self .newShortcutCAS = QShortcut (QKeySequence (Qt .CTRL + Qt .ALT + Qt .Key_Space ), self )
116
116
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 ))
118
123
119
124
def autoComplete (self ):
120
125
self .autoCompleteFromAll ()
@@ -161,8 +166,6 @@ def setLexers(self, lexer):
161
166
self .setMarginsFont (font )
162
167
self .lexer = QsciLexerPython ()
163
168
self .lexer .setDefaultFont (font )
164
- #self.lexer.setDefaultFont(QFont('Mono', 10, 0, False))
165
- #self.lexer.setDefaultColor(Qt.darkGray)
166
169
self .lexer .setColor (Qt .red , 1 )
167
170
self .lexer .setColor (Qt .darkGreen , 5 )
168
171
self .lexer .setColor (Qt .darkBlue , 15 )
@@ -171,44 +174,25 @@ def setLexers(self, lexer):
171
174
self .lexer .setFont (font , 4 )
172
175
self .api = QsciAPIs (self .lexer )
173
176
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)
183
177
self .setLexer (self .lexer )
184
178
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 )
207
191
208
-
209
192
def insertInitText (self ):
210
193
#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 "
212
196
"## use qgis.utils.iface object (instance of QgisInterface class). Read help for more info.\n \n " )
213
197
initText = self .setText (txtInit )
214
198
@@ -379,7 +363,39 @@ def keyPressEvent(self, e):
379
363
self .entered ()
380
364
elif e .modifiers () & Qt .ControlModifier :
381
365
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 )
383
399
elif e .key () == Qt .Key_Backspace :
384
400
curPos , pos = self .getCursorPosition ()
385
401
line = self .lines () - 1
@@ -401,39 +417,7 @@ def keyPressEvent(self, e):
401
417
self .showPrevious ()
402
418
elif e .key () == Qt .Key_Up and not self .isListActive ():
403
419
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 )
432
420
## 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()
437
421
else :
438
422
QsciScintilla .keyPressEvent (self , e )
439
423
@@ -499,13 +483,28 @@ def currentCommand(self):
499
483
def runCommand (self , cmd ):
500
484
self .updateHistory (cmd )
501
485
self .SendScintilla (QsciScintilla .SCI_NEWLINE )
502
- if cmd in ('_save' , '_clear' ):
486
+ if cmd in ('_save' , '_clear' , '_clearAll' ):
503
487
if cmd == '_save' :
504
488
self .writeHistoryFile ()
505
- print QCoreApplication .translate ("PythonConsole" , "## History saved successfully ##" )
489
+ print QCoreApplication .translate ("PythonConsole" ,
490
+ "## History saved successfully ##" )
506
491
elif cmd == '_clear' :
507
492
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 ##" )
509
508
output = sys .stdout .get_and_clean_data ()
510
509
if output :
511
510
self .append (output )
0 commit comments