Skip to content
Permalink
Browse files

add eval button to python console that evaluated single line commands…

… and shows the result

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12126 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Nov 15, 2009
1 parent fb889e0 commit 3a0a819ab67105e211159b386d98b4c8aecaf2b7
Showing with 62 additions and 41 deletions.
  1. +13 −3 src/app/qgspythondialog.cpp
  2. +2 −0 src/app/qgspythondialog.h
  3. +47 −38 src/ui/qgspythondialog.ui
@@ -67,11 +67,11 @@ void QgsPythonDialog::on_pbnNext_clicked()
}
}

void QgsPythonDialog::on_pbnExecute_clicked()
void QgsPythonDialog::execute( bool single )
{
QString command = edtCmdLine->toPlainText();

QgsDebugMsg( QString( "command: |%1|" ).arg( command ) );
QgsDebugMsg( QString( "command: |%1| %2" ).arg( command ).arg( single ) );

if ( !command.isEmpty() )
{
@@ -83,7 +83,7 @@ void QgsPythonDialog::on_pbnExecute_clicked()

// 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, false ) )
if ( mPythonUtils->runStringUnsafe( command, single ) )
{
mPythonUtils->evalString( "sys.stdout.get_and_clean_data()", output );
QString result = mPythonUtils->getResult();
@@ -112,6 +112,16 @@ void QgsPythonDialog::on_pbnExecute_clicked()
txtHistory->ensureCursorVisible();
}

void QgsPythonDialog::on_pbnExecute_clicked()
{
execute( false );
}

void QgsPythonDialog::on_pbnEval_clicked()
{
execute( true );
}

void QgsPythonDialog::showEvent( QShowEvent* event )
{
QDialog::showEvent( event );
@@ -39,6 +39,7 @@ class QgsPythonDialog : public QDialog, private Ui::QgsPythonDialog

void on_pbnPrev_clicked();
void on_pbnExecute_clicked();
void on_pbnEval_clicked();
void on_pbnNext_clicked();

protected:
@@ -47,6 +48,7 @@ class QgsPythonDialog : public QDialog, private Ui::QgsPythonDialog
void showEvent( QShowEvent *event );

private:
void execute( bool single );

QgisInterface* mIface;
QgsPythonUtils* mPythonUtils;
@@ -6,56 +6,82 @@
<rect>
<x>0</x>
<y>0</y>
<width>483</width>
<height>305</height>
<width>625</width>
<height>641</height>
</rect>
</property>
<property name="windowTitle">
<string>Python console</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="3">
<widget class="QPushButton" name="pbnExecute">
<item row="0" column="0" colspan="5">
<widget class="QLabel" name="lblInfo">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&amp;Execute</string>
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'DejaVu Sans'; font-size:8pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;To access Quantum GIS environment from this python console use qgis.utils.iface object which is an instance of QgisInterface class.&lt;br /&gt;Usage e.g.: qgis.utils.iface.zoomFull()&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="3">
<item row="2" column="4">
<widget class="QPushButton" name="pbnPrev">
<property name="text">
<string>&amp;Previous</string>
</property>
<property name="shortcut">
<string comment="Ctrl+Up"/>
</property>
</widget>
</item>
<item row="4" column="3">
<item row="3" column="4">
<widget class="QPushButton" name="pbnExecute">
<property name="text">
<string>E&amp;xecute</string>
</property>
</widget>
</item>
<item row="4" column="4">
<widget class="QPushButton" name="pbnEval">
<property name="text">
<string>&amp;Eval</string>
</property>
</widget>
</item>
<item row="5" column="4">
<widget class="QPushButton" name="pbnNext">
<property name="text">
<string>&amp;Next</string>
</property>
<property name="shortcut">
<string/>
</property>
</widget>
</item>
<item row="0" column="0" colspan="4">
<widget class="QLabel" name="lblInfo">
<item row="2" column="1" rowspan="4" colspan="2">
<widget class="QLabel" name="lblPrompt">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'DejaVu Sans'; font-size:8pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;To access Quantum GIS environment from this python console use qgis.utils.iface object which is an instance of QgisInterface class.&lt;br /&gt;Usage e.g.: qgis.utils.iface.zoomFull()&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
<string>&gt;&gt;&gt;</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="4">
<item row="1" column="0" colspan="5">
<widget class="QTextBrowser" name="txtHistory">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
@@ -67,25 +93,12 @@ p, li { white-space: pre-wrap; }
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'DejaVu Sans'; font-size:8pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:9pt;&quot;&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="lblPrompt">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&gt;&gt;&gt;</string>
</property>
</widget>
</item>
<item row="2" column="2" rowspan="3">
<item row="2" column="3" rowspan="4">
<widget class="QTextEdit" name="edtCmdLine">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
@@ -98,10 +111,6 @@ p, li { white-space: pre-wrap; }
</layout>
</widget>
<tabstops>
<tabstop>edtCmdLine</tabstop>
<tabstop>pbnPrev</tabstop>
<tabstop>pbnExecute</tabstop>
<tabstop>pbnNext</tabstop>
<tabstop>txtHistory</tabstop>
</tabstops>
<resources/>

0 comments on commit 3a0a819

Please sign in to comment.