multiline_python_console.diff

Jürgen Fischer, 2009-04-21 01:29 PM

Download (8.2 KB)

View differences:

src/app/qgspythondialog.h (working copy)
37 37

  
38 38
  public slots:
39 39

  
40
    void on_edtCmdLine_returnPressed();
40
    void on_pbnPrev_clicked();
41
    void on_pbnExecute_clicked();
42
    void on_pbnNext_clicked();
41 43

  
42 44
  protected:
43 45

  
44
    void keyPressEvent( QKeyEvent *event );
45 46
    void closeEvent( QCloseEvent *event );
46 47
    void showEvent( QShowEvent *event );
47 48

  
src/app/qgspythondialog.cpp (working copy)
16 16

  
17 17
#include "qgspythondialog.h"
18 18
#include "qgspythonutils.h"
19
#include "qgslogger.h"
19 20

  
20 21
#include <QShowEvent>
21 22
#include <QCloseEvent>
......
43 44
  return text.replace( "<", "&lt;" ).replace( ">", "&gt;" );
44 45
}
45 46

  
46
void QgsPythonDialog::keyPressEvent( QKeyEvent *ev )
47
void QgsPythonDialog::on_pbnPrev_clicked()
47 48
{
48
  switch ( ev->key() )
49
  if ( pos > 0 )
49 50
  {
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] );
76 57
  }
77 58
}
78 59

  
79
void QgsPythonDialog::on_edtCmdLine_returnPressed()
60
void QgsPythonDialog::on_pbnNext_clicked()
80 61
{
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
} 
82 69

  
70
void QgsPythonDialog::on_pbnExecute_clicked()
71
{
72
  QString command = edtCmdLine->toPlainText();
73

  
74
  QgsDebugMsg( QString("command: |%1|").arg( command ) );
75

  
83 76
  if ( !command.isEmpty() )
84 77
  {
85 78
    history << command;
......
90 83

  
91 84
  // when using Py_single_input the return value will be always null
92 85
  // 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 ) )
94 87
  {
95 88
    mPythonUtils->evalString( "sys.stdout.get_and_clean_data()", output );
96 89
    QString result = mPythonUtils->getResult();
src/python/qgspythonutilsimpl.cpp (working copy)
167 167
}
168 168

  
169 169

  
170
bool QgsPythonUtilsImpl::runStringUnsafe( const QString& command )
170
bool QgsPythonUtilsImpl::runStringUnsafe( const QString& command, bool single )
171 171
{
172 172
  // TODO: convert special characters from unicode strings u"..." to \uXXXX
173 173
  // so that they're not mangled to utf-8
174 174
  // (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 );
176 176
  return ( PyErr_Occurred() == 0 );
177 177
}
178 178

  
src/python/qgspythonutils.h (working copy)
52 52

  
53 53
    //! run a statement, error reporting is not done
54 54
    //! @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;
56 56

  
57 57
    virtual bool evalString( const QString& command, QString& result ) = 0;
58 58

  
src/python/qgspythonutilsimpl.h (working copy)
57 57

  
58 58
    //! run a statement, error reporting is not done
59 59
    //! @return true if no error occured
60
    bool runStringUnsafe( const QString& command );
60
    bool runStringUnsafe( const QString& command, bool single = true );
61 61

  
62 62
    bool evalString( const QString& command, QString& result );
63 63

  
src/ui/qgspythondialog.ui (working copy)
5 5
   <rect>
6 6
    <x>0</x>
7 7
    <y>0</y>
8
    <width>541</width>
9
    <height>338</height>
8
    <width>709</width>
9
    <height>265</height>
10 10
   </rect>
11 11
  </property>
12 12
  <property name="windowTitle" >
13 13
   <string>Python console</string>
14 14
  </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" >
23 38
    <widget class="QLabel" name="lblInfo" >
24 39
     <property name="sizePolicy" >
25
      <sizepolicy>
26
       <hsizetype>7</hsizetype>
27
       <vsizetype>5</vsizetype>
40
      <sizepolicy vsizetype="Preferred" hsizetype="Expanding" >
28 41
       <horstretch>0</horstretch>
29 42
       <verstretch>0</verstretch>
30 43
      </sizepolicy>
......
37 50
     </property>
38 51
    </widget>
39 52
   </item>
40
   <item>
53
   <item row="1" column="0" colspan="4" >
41 54
    <widget class="QTextBrowser" name="txtHistory" >
42 55
     <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>
44 61
     </property>
45 62
    </widget>
46 63
   </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>
51 71
     </property>
52
     <property name="spacing" >
53
      <number>6</number>
72
     <property name="text" >
73
      <string>>>></string>
54 74
     </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>
66 76
   </item>
77
   <item rowspan="3" row="2" column="2" >
78
    <widget class="QTextEdit" name="edtCmdLine" />
79
   </item>
67 80
  </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>
68 88
 </widget>
69 89
 <tabstops>
70
  <tabstop>edtCmdLine</tabstop>
71 90
  <tabstop>txtHistory</tabstop>
72 91
 </tabstops>
73 92
 <resources/>