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

git-svn-id: http://svn.osgeo.org/qgis/trunk@14998 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Jan 5, 2011
1 parent c4743a0 commit 1fa7abb75e0a9b3469a671474da385d2605c0a89
Showing with 22 additions and 18 deletions.
  1. +22 −18 python/console.py
@@ -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.show()
_console.raise_()
_console.setWindowState( _console.windowState() & ~Qt.WindowMinimized )
_console.activateWindow()

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



_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.setAllowedAreas(Qt.BottomDockWidgetArea)
self.widget = QWidget()
self.l = QVBoxLayout(self.widget)
self.edit = PythonEdit()
self.l = QVBoxLayout()
self.l.addWidget(self.edit)
self.setLayout(self.l)
self.setWidget(self.widget)
self.setWindowTitle(QCoreApplication.translate("PythonConsole", "Python Console"))

s = QSettings()
self.restoreGeometry(s.value("/python/console/geometry").toByteArray())
# 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 1fa7abb

Please sign in to comment.