[QGIS Commit] r10643 - in trunk/qgis/src: app python ui

svn_qgis at osgeo.org svn_qgis at osgeo.org
Thu Apr 23 18:27:40 EDT 2009


Author: jef
Date: 2009-04-23 18:27:40 -0400 (Thu, 23 Apr 2009)
New Revision: 10643

Modified:
   trunk/qgis/src/app/qgspythondialog.cpp
   trunk/qgis/src/app/qgspythondialog.h
   trunk/qgis/src/python/qgspythonutils.h
   trunk/qgis/src/python/qgspythonutilsimpl.cpp
   trunk/qgis/src/python/qgspythonutilsimpl.h
   trunk/qgis/src/ui/qgspythondialog.ui
Log:
apply #1646

Modified: trunk/qgis/src/app/qgspythondialog.cpp
===================================================================
--- trunk/qgis/src/app/qgspythondialog.cpp	2009-04-23 22:21:54 UTC (rev 10642)
+++ trunk/qgis/src/app/qgspythondialog.cpp	2009-04-23 22:27:40 UTC (rev 10643)
@@ -16,6 +16,7 @@
 
 #include "qgspythondialog.h"
 #include "qgspythonutils.h"
+#include "qgslogger.h"
 
 #include <QShowEvent>
 #include <QCloseEvent>
@@ -43,43 +44,35 @@
   return text.replace( "<", "&lt;" ).replace( ">", "&gt;" );
 }
 
-void QgsPythonDialog::keyPressEvent( QKeyEvent *ev )
+void QgsPythonDialog::on_pbnPrev_clicked()
 {
-  switch ( ev->key() )
+  if ( pos > 0 )
   {
-    case Qt::Key_Up:
-    {
-      if ( pos > 0 )
-      {
-        if ( pos == history.size() )
-          history << edtCmdLine->text();
-        else
-          history[pos] = edtCmdLine->text();
-        pos--;
-        edtCmdLine->setText( history[pos] );
-      }
-    }
-    break;
-    case Qt::Key_Down:
-    {
-      if ( pos < history.size() - 1 )
-      {
-        history[pos] = edtCmdLine->text();
-        pos++;
-        edtCmdLine->setText( history[pos] );
-      }
-    }
-    break;
-    default:
-      QWidget::keyPressEvent( ev );
-      break;
+    if ( pos == history.size() )
+      history << edtCmdLine->toPlainText();
+    else
+      history[pos] = edtCmdLine->toPlainText();
+    pos--;
+    edtCmdLine->setText( history[pos] );
   }
 }
 
-void QgsPythonDialog::on_edtCmdLine_returnPressed()
+void QgsPythonDialog::on_pbnNext_clicked()
 {
-  QString command = edtCmdLine->text();
+  if ( pos < history.size() - 1 )
+  {
+    history[pos] = edtCmdLine->toPlainText();
+    pos++;
+    edtCmdLine->setText( history[pos] );
+  }
+} 
 
+void QgsPythonDialog::on_pbnExecute_clicked()
+{
+  QString command = edtCmdLine->toPlainText();
+
+  QgsDebugMsg( QString("command: |%1|").arg( command ) );
+
   if ( !command.isEmpty() )
   {
     history << command;
@@ -90,7 +83,7 @@
 
   // when using Py_single_input the return value will be always null
   // we're using custom hooks for output and exceptions to show output in console
-  if ( mPythonUtils->runStringUnsafe( command ) )
+  if ( mPythonUtils->runStringUnsafe( command, false ) )
   {
     mPythonUtils->evalString( "sys.stdout.get_and_clean_data()", output );
     QString result = mPythonUtils->getResult();

Modified: trunk/qgis/src/app/qgspythondialog.h
===================================================================
--- trunk/qgis/src/app/qgspythondialog.h	2009-04-23 22:21:54 UTC (rev 10642)
+++ trunk/qgis/src/app/qgspythondialog.h	2009-04-23 22:27:40 UTC (rev 10643)
@@ -37,11 +37,12 @@
 
   public slots:
 
-    void on_edtCmdLine_returnPressed();
+    void on_pbnPrev_clicked();
+    void on_pbnExecute_clicked();
+    void on_pbnNext_clicked();
 
   protected:
 
-    void keyPressEvent( QKeyEvent *event );
     void closeEvent( QCloseEvent *event );
     void showEvent( QShowEvent *event );
 

Modified: trunk/qgis/src/python/qgspythonutils.h
===================================================================
--- trunk/qgis/src/python/qgspythonutils.h	2009-04-23 22:21:54 UTC (rev 10642)
+++ trunk/qgis/src/python/qgspythonutils.h	2009-04-23 22:27:40 UTC (rev 10643)
@@ -52,7 +52,7 @@
 
     //! run a statement, error reporting is not done
     //! @return true if no error occured
-    virtual bool runStringUnsafe( const QString& command ) = 0;
+    virtual bool runStringUnsafe( const QString& command, bool single = true ) = 0;
 
     virtual bool evalString( const QString& command, QString& result ) = 0;
 

Modified: trunk/qgis/src/python/qgspythonutilsimpl.cpp
===================================================================
--- trunk/qgis/src/python/qgspythonutilsimpl.cpp	2009-04-23 22:21:54 UTC (rev 10642)
+++ trunk/qgis/src/python/qgspythonutilsimpl.cpp	2009-04-23 22:27:40 UTC (rev 10643)
@@ -167,12 +167,12 @@
 }
 
 
-bool QgsPythonUtilsImpl::runStringUnsafe( const QString& command )
+bool QgsPythonUtilsImpl::runStringUnsafe( const QString& command, bool single )
 {
   // TODO: convert special characters from unicode strings u"..." to \uXXXX
   // so that they're not mangled to utf-8
   // (non-unicode strings can be mangled)
-  PyRun_String( command.toUtf8().data(), Py_single_input, mMainDict, mMainDict );
+  PyRun_String( command.toUtf8().data(), single ? Py_single_input : Py_file_input, mMainDict, mMainDict );
   return ( PyErr_Occurred() == 0 );
 }
 

Modified: trunk/qgis/src/python/qgspythonutilsimpl.h
===================================================================
--- trunk/qgis/src/python/qgspythonutilsimpl.h	2009-04-23 22:21:54 UTC (rev 10642)
+++ trunk/qgis/src/python/qgspythonutilsimpl.h	2009-04-23 22:27:40 UTC (rev 10643)
@@ -57,7 +57,7 @@
 
     //! run a statement, error reporting is not done
     //! @return true if no error occured
-    bool runStringUnsafe( const QString& command );
+    bool runStringUnsafe( const QString& command, bool single = true );
 
     bool evalString( const QString& command, QString& result );
 

Modified: trunk/qgis/src/ui/qgspythondialog.ui
===================================================================
--- trunk/qgis/src/ui/qgspythondialog.ui	2009-04-23 22:21:54 UTC (rev 10642)
+++ trunk/qgis/src/ui/qgspythondialog.ui	2009-04-23 22:27:40 UTC (rev 10643)
@@ -5,26 +5,39 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>541</width>
-    <height>338</height>
+    <width>709</width>
+    <height>265</height>
    </rect>
   </property>
   <property name="windowTitle" >
    <string>Python console</string>
   </property>
-  <layout class="QVBoxLayout" >
-   <property name="margin" >
-    <number>9</number>
-   </property>
-   <property name="spacing" >
-    <number>6</number>
-   </property>
-   <item>
+  <layout class="QGridLayout" name="gridLayout" >
+   <item row="3" column="3" >
+    <widget class="QPushButton" name="pbnExecute" >
+     <property name="text" >
+      <string>&amp;Execute</string>
+     </property>
+    </widget>
+   </item>
+   <item row="2" column="3" >
+    <widget class="QPushButton" name="pbnPrev" >
+     <property name="text" >
+      <string>&amp;Previous</string>
+     </property>
+    </widget>
+   </item>
+   <item row="4" column="3" >
+    <widget class="QPushButton" name="pbnNext" >
+     <property name="text" >
+      <string>&amp;Next</string>
+     </property>
+    </widget>
+   </item>
+   <item row="0" column="0" colspan="3" >
     <widget class="QLabel" name="lblInfo" >
      <property name="sizePolicy" >
-      <sizepolicy>
-       <hsizetype>7</hsizetype>
-       <vsizetype>5</vsizetype>
+      <sizepolicy vsizetype="Preferred" hsizetype="Expanding" >
        <horstretch>0</horstretch>
        <verstretch>0</verstretch>
       </sizepolicy>
@@ -37,37 +50,43 @@
      </property>
     </widget>
    </item>
-   <item>
+   <item row="1" column="0" colspan="4" >
     <widget class="QTextBrowser" name="txtHistory" >
      <property name="html" >
-      <string></string>
+      <string>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
+&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
+p, li { white-space: pre-wrap; }
+&lt;/style>&lt;/head>&lt;body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">
+&lt;p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">&lt;/p>&lt;/body>&lt;/html></string>
      </property>
     </widget>
    </item>
-   <item>
-    <layout class="QHBoxLayout" >
-     <property name="margin" >
-      <number>0</number>
+   <item row="3" column="1" >
+    <widget class="QLabel" name="lblPrompt" >
+     <property name="sizePolicy" >
+      <sizepolicy vsizetype="Expanding" hsizetype="Preferred" >
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
      </property>
-     <property name="spacing" >
-      <number>6</number>
+     <property name="text" >
+      <string>>>></string>
      </property>
-     <item>
-      <widget class="QLabel" name="lblPrompt" >
-       <property name="text" >
-        <string>>>></string>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QLineEdit" name="edtCmdLine" />
-     </item>
-    </layout>
+    </widget>
    </item>
+   <item rowspan="3" row="2" column="2" >
+    <widget class="QTextEdit" name="edtCmdLine" />
+   </item>
   </layout>
+  <zorder>pbnExecute</zorder>
+  <zorder>pbnPrev</zorder>
+  <zorder>pbnNext</zorder>
+  <zorder>lblInfo</zorder>
+  <zorder>txtHistory</zorder>
+  <zorder>lblPrompt</zorder>
+  <zorder>edtCmdLine</zorder>
  </widget>
  <tabstops>
-  <tabstop>edtCmdLine</tabstop>
   <tabstop>txtHistory</tabstop>
  </tabstops>
  <resources/>



More information about the QGIS-commit mailing list