Skip to content

Commit

Permalink
apply #1646
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@10643 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Apr 23, 2009
1 parent c890666 commit fb0f969
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 70 deletions.
55 changes: 24 additions & 31 deletions src/app/qgspythondialog.cpp
Expand Up @@ -16,6 +16,7 @@

#include "qgspythondialog.h"
#include "qgspythonutils.h"
#include "qgslogger.h"

#include <QShowEvent>
#include <QCloseEvent>
Expand Down Expand Up @@ -43,42 +44,34 @@ QString QgsPythonDialog::escapeHtml( QString text )
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() )
{
Expand All @@ -90,7 +83,7 @@ void QgsPythonDialog::on_edtCmdLine_returnPressed()

// 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();
Expand Down
5 changes: 3 additions & 2 deletions src/app/qgspythondialog.h
Expand Up @@ -37,11 +37,12 @@ class QgsPythonDialog : public QDialog, private Ui::QgsPythonDialog

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 );

Expand Down
2 changes: 1 addition & 1 deletion src/python/qgspythonutils.h
Expand Up @@ -52,7 +52,7 @@ class PYTHON_EXPORT QgsPythonUtils

//! 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;

Expand Down
4 changes: 2 additions & 2 deletions src/python/qgspythonutilsimpl.cpp
Expand Up @@ -167,12 +167,12 @@ void QgsPythonUtilsImpl::uninstallConsoleHooks()
}


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 );
}

Expand Down
2 changes: 1 addition & 1 deletion src/python/qgspythonutilsimpl.h
Expand Up @@ -57,7 +57,7 @@ class QgsPythonUtilsImpl : public QgsPythonUtils

//! 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 );

Expand Down
85 changes: 52 additions & 33 deletions src/ui/qgspythondialog.ui
Expand Up @@ -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>
Expand All @@ -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/>
Expand Down

0 comments on commit fb0f969

Please sign in to comment.