Skip to content
Browse files
Docking of Python console - contributed by Nathan Woodrow - with some…
… improvements.

git-svn-id: c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Jan 5, 2011
1 parent 50df167 commit 3120590533197c1343563559adc6a3b0e642fbb3
Showing with 22 additions and 18 deletions.
  1. +22 −18 python/
@@ -24,31 +24,35 @@

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.utils import iface
import sys
import traceback
import code

_init_commands = ["from qgis.core import *", "import qgis.utils"]

_console = None

def show_console():
""" called from QGIS to open the console """
global _console
if _console is None:
_console = PythonConsole()
_console.setWindowState( _console.windowState() & ~Qt.WindowMinimized )

_console = PythonConsole(iface.mainWindow()) # force show even if it was restored as hidden
_console.setVisible(not _console.isVisible())
# set focus to the edit box so the user can start typing
if _console.isVisible():

_old_stdout = sys.stdout
_console_output = None

# hook for python console so all output will be redirected
# and then shown in console
def console_displayhook(obj):
@@ -69,26 +73,26 @@ def flush(self):

sys.stdout = QgisOutputCatcher()

class PythonConsole(QWidget):
class PythonConsole(QDockWidget):
def __init__(self, parent=None):
QWidget.__init__(self, parent)

QDockWidget.__init__(self, parent)
self.setObjectName("Python Console")
self.widget = QWidget()
self.l = QVBoxLayout(self.widget)
self.edit = PythonEdit()
self.l = QVBoxLayout()
self.setWindowTitle(QCoreApplication.translate("PythonConsole", "Python Console"))

s = QSettings()
# try to restore position from stored main window state
if not iface.mainWindow().restoreDockWidget(self):
iface.mainWindow().addDockWidget(Qt.BottomDockWidgetArea, self)

def sizeHint(self):
return QSize(500,300)

def closeEvent(self, event):
s = QSettings()
s.setValue("/python/console/geometry", QVariant(self.saveGeometry()))
QWidget.closeEvent(self, event)

0 comments on commit 3120590

Please sign in to comment.