[QGIS Commit] r8503 - trunk/qgis/src/app
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Fri May 23 12:58:09 EDT 2008
Author: wonder
Date: 2008-05-23 12:58:09 -0400 (Fri, 23 May 2008)
New Revision: 8503
Modified:
trunk/qgis/src/app/qgspythondialog.cpp
trunk/qgis/src/app/qgspythondialog.h
trunk/qgis/src/app/qgspythonutils.cpp
Log:
One more fix for redirecting output when python console is open
Modified: trunk/qgis/src/app/qgspythondialog.cpp
===================================================================
--- trunk/qgis/src/app/qgspythondialog.cpp 2008-05-23 16:57:28 UTC (rev 8502)
+++ trunk/qgis/src/app/qgspythondialog.cpp 2008-05-23 16:58:09 UTC (rev 8503)
@@ -17,6 +17,7 @@
#include "qgspythondialog.h"
#include "qgspythonutils.h"
+#include <QShowEvent>
#include <QCloseEvent>
QgsPythonDialog::QgsPythonDialog(QgisInterface* pIface, QWidget *parent)
@@ -24,8 +25,6 @@
{
setupUi(this);
mIface = pIface;
-
- QgsPythonUtils::installConsoleHooks();
}
QgsPythonDialog::~QgsPythonDialog()
@@ -46,8 +45,7 @@
// we're using custom hooks for output and exceptions to show output in console
if (QgsPythonUtils::runStringUnsafe(command))
{
- QgsPythonUtils::evalString("sys.stdout.data", output);
- QgsPythonUtils::runString("sys.stdout.data = ''");
+ QgsPythonUtils::evalString("sys.stdout.get_and_clean_data()", output);
QString result = QgsPythonUtils::getResult();
// escape the result so python objects display properly and
// we can still use html output to get nicely formatted display
@@ -74,6 +72,13 @@
txtHistory->ensureCursorVisible();
}
+void QgsPythonDialog::showEvent(QShowEvent* event)
+{
+ QDialog::showEvent(event);
+
+ QgsPythonUtils::installConsoleHooks();
+}
+
void QgsPythonDialog::closeEvent(QCloseEvent* event)
{
QgsPythonUtils::uninstallConsoleHooks();
Modified: trunk/qgis/src/app/qgspythondialog.h
===================================================================
--- trunk/qgis/src/app/qgspythondialog.h 2008-05-23 16:57:28 UTC (rev 8502)
+++ trunk/qgis/src/app/qgspythondialog.h 2008-05-23 16:58:09 UTC (rev 8503)
@@ -21,6 +21,7 @@
class QgisInterface;
class QCloseEvent;
+class QShowEvent;
class QgsPythonDialog : public QDialog, private Ui::QgsPythonDialog
{
@@ -40,7 +41,8 @@
protected:
void closeEvent(QCloseEvent* event);
-
+ void showEvent(QShowEvent* event);
+
private:
QgisInterface* mIface;
Modified: trunk/qgis/src/app/qgspythonutils.cpp
===================================================================
--- trunk/qgis/src/app/qgspythonutils.cpp 2008-05-23 16:57:28 UTC (rev 8502)
+++ trunk/qgis/src/app/qgspythonutils.cpp 2008-05-23 16:58:09 UTC (rev 8503)
@@ -97,6 +97,16 @@
runString(
"def qgis_except_hook(type, value, tb):\n"
" qgis_except_hook_msg(type, value, tb, None)\n");
+ runString(
+ "class QgisOutputCatcher:\n"
+ " def __init__(self):\n"
+ " self.data = ''\n"
+ " def write(self, stuff):\n"
+ " self.data += stuff\n"
+ " def get_and_clean_data(self):\n"
+ " tmp = self.data\n"
+ " self.data = ''\n"
+ " return tmp\n");
// hook for python console so all output will be redirected
// and then shown in console
@@ -135,15 +145,8 @@
{
runString("sys.displayhook = console_display_hook\n");
- runString(
- "class MyOutputCatcher:\n"
- " def __init__(self):\n"
- " self.data = ''\n"
- " def write(self, stuff):\n"
- " self.data += stuff\n");
runString("_old_stdout = sys.stdout\n");
- runString("sys.stdout = MyOutputCatcher()\n");
-
+ runString("sys.stdout = QgisOutputCatcher()\n");
}
void QgsPythonUtils::uninstallConsoleHooks()
More information about the QGIS-commit
mailing list