Skip to content

Commit 3a0a819

Browse files
author
jef
committed
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
1 parent fb889e0 commit 3a0a819

File tree

3 files changed

+62
-41
lines changed

3 files changed

+62
-41
lines changed

src/app/qgspythondialog.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ void QgsPythonDialog::on_pbnNext_clicked()
6767
}
6868
}
6969

70-
void QgsPythonDialog::on_pbnExecute_clicked()
70+
void QgsPythonDialog::execute( bool single )
7171
{
7272
QString command = edtCmdLine->toPlainText();
7373

74-
QgsDebugMsg( QString( "command: |%1|" ).arg( command ) );
74+
QgsDebugMsg( QString( "command: |%1| %2" ).arg( command ).arg( single ) );
7575

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

8484
// when using Py_single_input the return value will be always null
8585
// we're using custom hooks for output and exceptions to show output in console
86-
if ( mPythonUtils->runStringUnsafe( command, false ) )
86+
if ( mPythonUtils->runStringUnsafe( command, single ) )
8787
{
8888
mPythonUtils->evalString( "sys.stdout.get_and_clean_data()", output );
8989
QString result = mPythonUtils->getResult();
@@ -112,6 +112,16 @@ void QgsPythonDialog::on_pbnExecute_clicked()
112112
txtHistory->ensureCursorVisible();
113113
}
114114

115+
void QgsPythonDialog::on_pbnExecute_clicked()
116+
{
117+
execute( false );
118+
}
119+
120+
void QgsPythonDialog::on_pbnEval_clicked()
121+
{
122+
execute( true );
123+
}
124+
115125
void QgsPythonDialog::showEvent( QShowEvent* event )
116126
{
117127
QDialog::showEvent( event );

src/app/qgspythondialog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class QgsPythonDialog : public QDialog, private Ui::QgsPythonDialog
3939

4040
void on_pbnPrev_clicked();
4141
void on_pbnExecute_clicked();
42+
void on_pbnEval_clicked();
4243
void on_pbnNext_clicked();
4344

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

4950
private:
51+
void execute( bool single );
5052

5153
QgisInterface* mIface;
5254
QgsPythonUtils* mPythonUtils;

src/ui/qgspythondialog.ui

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,82 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>483</width>
10-
<height>305</height>
9+
<width>625</width>
10+
<height>641</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>Python console</string>
1515
</property>
1616
<layout class="QGridLayout" name="gridLayout">
17-
<item row="3" column="3">
18-
<widget class="QPushButton" name="pbnExecute">
17+
<item row="0" column="0" colspan="5">
18+
<widget class="QLabel" name="lblInfo">
19+
<property name="sizePolicy">
20+
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
21+
<horstretch>0</horstretch>
22+
<verstretch>0</verstretch>
23+
</sizepolicy>
24+
</property>
1925
<property name="text">
20-
<string>&amp;Execute</string>
26+
<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;
27+
&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;
28+
p, li { white-space: pre-wrap; }
29+
&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;
30+
&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>
31+
</property>
32+
<property name="wordWrap">
33+
<bool>true</bool>
2134
</property>
2235
</widget>
2336
</item>
24-
<item row="2" column="3">
37+
<item row="2" column="4">
2538
<widget class="QPushButton" name="pbnPrev">
2639
<property name="text">
2740
<string>&amp;Previous</string>
2841
</property>
42+
<property name="shortcut">
43+
<string comment="Ctrl+Up"/>
44+
</property>
2945
</widget>
3046
</item>
31-
<item row="4" column="3">
47+
<item row="3" column="4">
48+
<widget class="QPushButton" name="pbnExecute">
49+
<property name="text">
50+
<string>E&amp;xecute</string>
51+
</property>
52+
</widget>
53+
</item>
54+
<item row="4" column="4">
55+
<widget class="QPushButton" name="pbnEval">
56+
<property name="text">
57+
<string>&amp;Eval</string>
58+
</property>
59+
</widget>
60+
</item>
61+
<item row="5" column="4">
3262
<widget class="QPushButton" name="pbnNext">
3363
<property name="text">
3464
<string>&amp;Next</string>
3565
</property>
66+
<property name="shortcut">
67+
<string/>
68+
</property>
3669
</widget>
3770
</item>
38-
<item row="0" column="0" colspan="4">
39-
<widget class="QLabel" name="lblInfo">
71+
<item row="2" column="1" rowspan="4" colspan="2">
72+
<widget class="QLabel" name="lblPrompt">
4073
<property name="sizePolicy">
41-
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
74+
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
4275
<horstretch>0</horstretch>
4376
<verstretch>0</verstretch>
4477
</sizepolicy>
4578
</property>
4679
<property name="text">
47-
<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;
48-
&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;
49-
p, li { white-space: pre-wrap; }
50-
&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;
51-
&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>
52-
</property>
53-
<property name="wordWrap">
54-
<bool>true</bool>
80+
<string>&gt;&gt;&gt;</string>
5581
</property>
5682
</widget>
5783
</item>
58-
<item row="1" column="0" colspan="4">
84+
<item row="1" column="0" colspan="5">
5985
<widget class="QTextBrowser" name="txtHistory">
6086
<property name="sizePolicy">
6187
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
@@ -67,25 +93,12 @@ p, li { white-space: pre-wrap; }
6793
<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;
6894
&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;
6995
p, li { white-space: pre-wrap; }
70-
&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;
96+
&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;
7197
&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>
7298
</property>
7399
</widget>
74100
</item>
75-
<item row="3" column="1">
76-
<widget class="QLabel" name="lblPrompt">
77-
<property name="sizePolicy">
78-
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
79-
<horstretch>0</horstretch>
80-
<verstretch>0</verstretch>
81-
</sizepolicy>
82-
</property>
83-
<property name="text">
84-
<string>&gt;&gt;&gt;</string>
85-
</property>
86-
</widget>
87-
</item>
88-
<item row="2" column="2" rowspan="3">
101+
<item row="2" column="3" rowspan="4">
89102
<widget class="QTextEdit" name="edtCmdLine">
90103
<property name="sizePolicy">
91104
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
@@ -98,10 +111,6 @@ p, li { white-space: pre-wrap; }
98111
</layout>
99112
</widget>
100113
<tabstops>
101-
<tabstop>edtCmdLine</tabstop>
102-
<tabstop>pbnPrev</tabstop>
103-
<tabstop>pbnExecute</tabstop>
104-
<tabstop>pbnNext</tabstop>
105114
<tabstop>txtHistory</tabstop>
106115
</tabstops>
107116
<resources/>

0 commit comments

Comments
 (0)