Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

After running several hundred lines of commands (and getting their subsequent error statements...), it is nice to be able to clear out the console window and start clean.

In the Python Console window in QGIS, I would like to clear it out. If I close it and then open it again, the buffer is still retained. If I 'select all' and delete the content, I don't get a prompt and can't do anything to get one back.

Any suggestions on how to clear out the scroll back buffer?

share|improve this question
    
If I may ask: Why? I don't think that's implemented but you can open an enhancement request. (Be prepared to answer the previous question though.) –  underdark Sep 28 '10 at 21:39
    
@underdark: So that you know how far to scroll back after you execute the next command. –  relet Sep 29 '10 at 6:43
    
@underdark I believe that you are right. I guess that I had two things in mind. First to just get a clean window, but that can just be accomplished with a bunch of /n or returns. The second thing I was thinking of was del'ing all of the variables/objects that had been created through the console. I was trying to test some code, but it was affected by an existing value for a shared variable. I guess that this is the difference between running a standalone shell vs opening and closing the console in an application that continues to run. –  DavidF Sep 29 '10 at 14:01
    
I have wondered about this too, you could open console.py file in the Qgis folder which has some python stuff for the console, like font etc and hack some code in to clear the buffer. I was going to do this but just never got around to it. –  Nathan W Oct 3 '10 at 8:19

1 Answer 1

up vote 5 down vote accepted

Ok, so I have been playing around with QGIS console.py to see if you can do this yourself and it turns out to be pretty easier.

Open up console.py which, if you have installed using OSGeo4W, is in C:\OSGeo4W\apps\qgis\python\qgis. Then look for the python method called def entered(self): and replace it with the following:

def entered(self):
    self.cursor.movePosition(QTextCursor.End, QTextCursor.MoveAnchor)
    self.setTextCursor(self.cursor)
    command = unicode(self.currentCommand())
    if command == 'clear':
        self.clearConsole()
    else:
        self.runCommand(command)

also add the following method after the entered method:

def clearConsole(self):
      self.clear()
      self.insertTaggedText("To access Quantum GIS environment from this console\n"
                          "use qgis.utils.iface object (instance of QgisInterface class).\n"
              "\n", ConsoleHighlighter.INIT)
      self.displayPrompt(False)

Save console.py and close, and restart QGIS.

The clearConsole will clear out the console window and return it the way it was when you first open it when the clear command is entered into the window.

However this doesn't clear the history, or restart any variables but I wouldn't want it to if I was using it.

Hope this helps with what you need.

EDIT: As of V1.7 this is a built in feature of the Python console. Just call qgis.console.clearConsole() in the Python console to clear it.

share|improve this answer
2  
Well done Nathan! –  DavidF Oct 5 '10 at 14:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.