Skip to content

Commit 1396187

Browse files

File tree

6 files changed

+83
-70
lines changed

6 files changed

+83
-70
lines changed
 

‎src/app/qgspythondialog.cpp

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "qgspythondialog.h"
1818
#include "qgspythonutils.h"
19+
#include "qgslogger.h"
1920

2021
#include <QShowEvent>
2122
#include <QCloseEvent>
@@ -43,42 +44,34 @@ QString QgsPythonDialog::escapeHtml( QString text )
4344
return text.replace( "<", "&lt;" ).replace( ">", "&gt;" );
4445
}
4546

46-
void QgsPythonDialog::keyPressEvent( QKeyEvent *ev )
47+
void QgsPythonDialog::on_pbnPrev_clicked()
4748
{
48-
switch ( ev->key() )
49+
if ( pos > 0 )
4950
{
50-
case Qt::Key_Up:
51-
{
52-
if ( pos > 0 )
53-
{
54-
if ( pos == history.size() )
55-
history << edtCmdLine->text();
56-
else
57-
history[pos] = edtCmdLine->text();
58-
pos--;
59-
edtCmdLine->setText( history[pos] );
60-
}
61-
}
62-
break;
63-
case Qt::Key_Down:
64-
{
65-
if ( pos < history.size() - 1 )
66-
{
67-
history[pos] = edtCmdLine->text();
68-
pos++;
69-
edtCmdLine->setText( history[pos] );
70-
}
71-
}
72-
break;
73-
default:
74-
QWidget::keyPressEvent( ev );
75-
break;
51+
if ( pos == history.size() )
52+
history << edtCmdLine->toPlainText();
53+
else
54+
history[pos] = edtCmdLine->toPlainText();
55+
pos--;
56+
edtCmdLine->setText( history[pos] );
7657
}
7758
}
7859

79-
void QgsPythonDialog::on_edtCmdLine_returnPressed()
60+
void QgsPythonDialog::on_pbnNext_clicked()
8061
{
81-
QString command = edtCmdLine->text();
62+
if ( pos < history.size() - 1 )
63+
{
64+
history[pos] = edtCmdLine->toPlainText();
65+
pos++;
66+
edtCmdLine->setText( history[pos] );
67+
}
68+
}
69+
70+
void QgsPythonDialog::on_pbnExecute_clicked()
71+
{
72+
QString command = edtCmdLine->toPlainText();
73+
74+
QgsDebugMsg( QString("command: |%1|").arg( command ) );
8275

8376
if ( !command.isEmpty() )
8477
{
@@ -90,7 +83,7 @@ void QgsPythonDialog::on_edtCmdLine_returnPressed()
9083

9184
// when using Py_single_input the return value will be always null
9285
// we're using custom hooks for output and exceptions to show output in console
93-
if ( mPythonUtils->runStringUnsafe( command ) )
86+
if ( mPythonUtils->runStringUnsafe( command, false ) )
9487
{
9588
mPythonUtils->evalString( "sys.stdout.get_and_clean_data()", output );
9689
QString result = mPythonUtils->getResult();

‎src/app/qgspythondialog.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ class QgsPythonDialog : public QDialog, private Ui::QgsPythonDialog
3737

3838
public slots:
3939

40-
void on_edtCmdLine_returnPressed();
40+
void on_pbnPrev_clicked();
41+
void on_pbnExecute_clicked();
42+
void on_pbnNext_clicked();
4143

4244
protected:
4345

44-
void keyPressEvent( QKeyEvent *event );
4546
void closeEvent( QCloseEvent *event );
4647
void showEvent( QShowEvent *event );
4748

‎src/python/qgspythonutils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class PYTHON_EXPORT QgsPythonUtils
5252

5353
//! run a statement, error reporting is not done
5454
//! @return true if no error occured
55-
virtual bool runStringUnsafe( const QString& command ) = 0;
55+
virtual bool runStringUnsafe( const QString& command, bool single = true ) = 0;
5656

5757
virtual bool evalString( const QString& command, QString& result ) = 0;
5858

‎src/python/qgspythonutilsimpl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,12 @@ void QgsPythonUtilsImpl::uninstallConsoleHooks()
167167
}
168168

169169

170-
bool QgsPythonUtilsImpl::runStringUnsafe( const QString& command )
170+
bool QgsPythonUtilsImpl::runStringUnsafe( const QString& command, bool single )
171171
{
172172
// TODO: convert special characters from unicode strings u"..." to \uXXXX
173173
// so that they're not mangled to utf-8
174174
// (non-unicode strings can be mangled)
175-
PyRun_String( command.toUtf8().data(), Py_single_input, mMainDict, mMainDict );
175+
PyRun_String( command.toUtf8().data(), single ? Py_single_input : Py_file_input, mMainDict, mMainDict );
176176
return ( PyErr_Occurred() == 0 );
177177
}
178178

‎src/python/qgspythonutilsimpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class QgsPythonUtilsImpl : public QgsPythonUtils
5757

5858
//! run a statement, error reporting is not done
5959
//! @return true if no error occured
60-
bool runStringUnsafe( const QString& command );
60+
bool runStringUnsafe( const QString& command, bool single = true );
6161

6262
bool evalString( const QString& command, QString& result );
6363

‎src/ui/qgspythondialog.ui

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,39 @@
55
<rect>
66
<x>0</x>
77
<y>0</y>
8-
<width>541</width>
9-
<height>338</height>
8+
<width>709</width>
9+
<height>265</height>
1010
</rect>
1111
</property>
1212
<property name="windowTitle" >
1313
<string>Python console</string>
1414
</property>
15-
<layout class="QVBoxLayout" >
16-
<property name="margin" >
17-
<number>9</number>
18-
</property>
19-
<property name="spacing" >
20-
<number>6</number>
21-
</property>
22-
<item>
15+
<layout class="QGridLayout" name="gridLayout" >
16+
<item row="3" column="3" >
17+
<widget class="QPushButton" name="pbnExecute" >
18+
<property name="text" >
19+
<string>&amp;Execute</string>
20+
</property>
21+
</widget>
22+
</item>
23+
<item row="2" column="3" >
24+
<widget class="QPushButton" name="pbnPrev" >
25+
<property name="text" >
26+
<string>&amp;Previous</string>
27+
</property>
28+
</widget>
29+
</item>
30+
<item row="4" column="3" >
31+
<widget class="QPushButton" name="pbnNext" >
32+
<property name="text" >
33+
<string>&amp;Next</string>
34+
</property>
35+
</widget>
36+
</item>
37+
<item row="0" column="0" colspan="3" >
2338
<widget class="QLabel" name="lblInfo" >
2439
<property name="sizePolicy" >
25-
<sizepolicy>
26-
<hsizetype>7</hsizetype>
27-
<vsizetype>5</vsizetype>
40+
<sizepolicy vsizetype="Preferred" hsizetype="Expanding" >
2841
<horstretch>0</horstretch>
2942
<verstretch>0</verstretch>
3043
</sizepolicy>
@@ -37,37 +50,43 @@
3750
</property>
3851
</widget>
3952
</item>
40-
<item>
53+
<item row="1" column="0" colspan="4" >
4154
<widget class="QTextBrowser" name="txtHistory" >
4255
<property name="html" >
43-
<string></string>
56+
<string>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
57+
&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
58+
p, li { white-space: pre-wrap; }
59+
&lt;/style>&lt;/head>&lt;body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">
60+
&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>
4461
</property>
4562
</widget>
4663
</item>
47-
<item>
48-
<layout class="QHBoxLayout" >
49-
<property name="margin" >
50-
<number>0</number>
64+
<item row="3" column="1" >
65+
<widget class="QLabel" name="lblPrompt" >
66+
<property name="sizePolicy" >
67+
<sizepolicy vsizetype="Expanding" hsizetype="Preferred" >
68+
<horstretch>0</horstretch>
69+
<verstretch>0</verstretch>
70+
</sizepolicy>
5171
</property>
52-
<property name="spacing" >
53-
<number>6</number>
72+
<property name="text" >
73+
<string>>>></string>
5474
</property>
55-
<item>
56-
<widget class="QLabel" name="lblPrompt" >
57-
<property name="text" >
58-
<string>>>></string>
59-
</property>
60-
</widget>
61-
</item>
62-
<item>
63-
<widget class="QLineEdit" name="edtCmdLine" />
64-
</item>
65-
</layout>
75+
</widget>
76+
</item>
77+
<item rowspan="3" row="2" column="2" >
78+
<widget class="QTextEdit" name="edtCmdLine" />
6679
</item>
6780
</layout>
81+
<zorder>pbnExecute</zorder>
82+
<zorder>pbnPrev</zorder>
83+
<zorder>pbnNext</zorder>
84+
<zorder>lblInfo</zorder>
85+
<zorder>txtHistory</zorder>
86+
<zorder>lblPrompt</zorder>
87+
<zorder>edtCmdLine</zorder>
6888
</widget>
6989
<tabstops>
70-
<tabstop>edtCmdLine</tabstop>
7190
<tabstop>txtHistory</tabstop>
7291
</tabstops>
7392
<resources/>

0 commit comments

Comments
 (0)
Please sign in to comment.