@@ -97,6 +97,7 @@ def __init__(self, parent=None):
9797
9898 # not too small
9999 #self.setMinimumSize(500, 300)
100+ self .setMinimumHeight (125 )
100101
101102 self .SendScintilla (QsciScintilla .SCI_SETWRAPMODE , 1 )
102103 self .SendScintilla (QsciScintilla .SCI_EMPTYUNDOBUFFER )
@@ -114,7 +115,12 @@ def __init__(self, parent=None):
114115 self .newShortcutCS = QShortcut (QKeySequence (Qt .CTRL + Qt .Key_Space ), self )
115116 self .newShortcutCAS = QShortcut (QKeySequence (Qt .CTRL + Qt .ALT + Qt .Key_Space ), self )
116117 self .newShortcutCS .activated .connect (self .autoComplete )
117- self .newShortcutCAS .activated .connect (self .autoComplete )
118+ self .newShortcutCAS .activated .connect (self .showHistory )
119+ self .connect (self , SIGNAL ('userListActivated(int, const QString)' ),
120+ self .completion_list_selected )
121+
122+ def showHistory (self ):
123+ self .showUserList (1 , QStringList (self .history ))
118124
119125 def autoComplete (self ):
120126 self .autoCompleteFromAll ()
@@ -161,8 +167,6 @@ def setLexers(self, lexer):
161167 self .setMarginsFont (font )
162168 self .lexer = QsciLexerPython ()
163169 self .lexer .setDefaultFont (font )
164- #self.lexer.setDefaultFont(QFont('Mono', 10, 0, False))
165- #self.lexer.setDefaultColor(Qt.darkGray)
166170 self .lexer .setColor (Qt .red , 1 )
167171 self .lexer .setColor (Qt .darkGreen , 5 )
168172 self .lexer .setColor (Qt .darkBlue , 15 )
@@ -171,44 +175,25 @@ def setLexers(self, lexer):
171175 self .lexer .setFont (font , 4 )
172176 self .api = QsciAPIs (self .lexer )
173177 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)
183178 self .setLexer (self .lexer )
184179
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)]
180+ ## TODO: show completion list for file and directory
181+
182+ def completion_list_selected (self , id , txt ):
183+ if id == 1 :
184+ txt = unicode (txt )
185+ # get current cursor position
186+ line , pos = self .getCurLine ()
187+ selCmd = self .text (line ).length ()
188+ # select typed text
189+ self .setSelection (line , 4 , line , selCmd )
190+ self .removeSelectedText ()
191+ self .insert (txt )
207192
208-
209193 def insertInitText (self ):
210194 #self.setLexers(False)
211- txtInit = QCoreApplication .translate ("PythonConsole" ,"## To access Quantum GIS environment from this console\n "
195+ txtInit = QCoreApplication .translate ("PythonConsole" ,
196+ "## To access Quantum GIS environment from this console\n "
212197 "## use qgis.utils.iface object (instance of QgisInterface class). Read help for more info.\n \n " )
213198 initText = self .setText (txtInit )
214199
@@ -379,7 +364,39 @@ def keyPressEvent(self, e):
379364 self .entered ()
380365 elif e .modifiers () & Qt .ControlModifier :
381366 if e .key () == Qt .Key_V :
382- self .paste ()
367+ self .paste ()
368+ elif e .key () == Qt .Key_C :
369+ self .copy ()
370+ elif e .key () == Qt .Key_X :
371+ self .cut ()
372+ elif e .key () == Qt .Key_Left :
373+ e .accept ()
374+ if e .modifiers () & Qt .ShiftModifier :
375+ if index > 4 :
376+ if e .modifiers () & Qt .ControlModifier :
377+ self .SendScintilla (QsciScintilla .SCI_WORDLEFTEXTEND )
378+ else :
379+ self .SendScintilla (QsciScintilla .SCI_CHARLEFTEXTEND )
380+ else :
381+ if index > 4 :
382+ if e .modifiers () & Qt .ControlModifier :
383+ self .SendScintilla (QsciScintilla .SCI_WORDLEFT )
384+ else :
385+ self .SendScintilla (QsciScintilla .SCI_CHARLEFT )
386+ elif e .key () == Qt .Key_Right :
387+ e .accept ()
388+ if e .modifiers () & Qt .ShiftModifier :
389+ if index >= 4 :
390+ if e .modifiers () & Qt .ControlModifier :
391+ self .SendScintilla (QsciScintilla .SCI_WORDRIGHTEXTEND )
392+ else :
393+ self .SendScintilla (QsciScintilla .SCI_CHARRIGHTEXTEND )
394+ else :
395+ if index >= 4 :
396+ if e .modifiers () & Qt .ControlModifier :
397+ self .SendScintilla (QsciScintilla .SCI_WORDRIGHT )
398+ else :
399+ self .SendScintilla (QsciScintilla .SCI_CHARRIGHT )
383400 elif e .key () == Qt .Key_Backspace :
384401 curPos , pos = self .getCursorPosition ()
385402 line = self .lines () - 1
@@ -401,39 +418,7 @@ def keyPressEvent(self, e):
401418 self .showPrevious ()
402419 elif e .key () == Qt .Key_Up and not self .isListActive ():
403420 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 )
432421 ## 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()
437422 else :
438423 QsciScintilla .keyPressEvent (self , e )
439424
@@ -499,13 +484,28 @@ def currentCommand(self):
499484 def runCommand (self , cmd ):
500485 self .updateHistory (cmd )
501486 self .SendScintilla (QsciScintilla .SCI_NEWLINE )
502- if cmd in ('_save' , '_clear' ):
487+ if cmd in ('_save' , '_clear' , '_clearAll' ):
503488 if cmd == '_save' :
504489 self .writeHistoryFile ()
505- print QCoreApplication .translate ("PythonConsole" , "## History saved successfully ##" )
490+ print QCoreApplication .translate ("PythonConsole" ,
491+ "## History saved successfully ##" )
506492 elif cmd == '_clear' :
507493 self .clearHistoryFile ()
508- print QCoreApplication .translate ("PythonConsole" , "## History cleared successfully ##" )
494+ print QCoreApplication .translate ("PythonConsole" ,
495+ "## History cleared successfully ##" )
496+ elif cmd == '_clearAll' :
497+ res = QMessageBox .question (self , "Python Console" ,
498+ QCoreApplication .translate ("PythonConsole" ,
499+ "Are you sure you want to completely\n "
500+ "delete the command history ?" ),
501+ QMessageBox .Yes | QMessageBox .No )
502+ if res == QMessageBox .No :
503+ self .SendScintilla (QsciScintilla .SCI_DELETEBACK )
504+ return
505+ self .history = QStringList ()
506+ self .clearHistoryFile ()
507+ print QCoreApplication .translate ("PythonConsole" ,
508+ "## History cleared successfully ##" )
509509 output = sys .stdout .get_and_clean_data ()
510510 if output :
511511 self .append (output )
0 commit comments