Skip to content

Commit

Permalink
Docking of Python console - contributed by Nathan Woodrow - with some…
Browse files Browse the repository at this point in the history
… improvements.

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14998 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Jan 5, 2011
1 parent 50df167 commit 3120590
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions python/console.py
Expand Up @@ -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):
Expand All @@ -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)


Expand Down

0 comments on commit 3120590

Please sign in to comment.