~ubuntu-branches/ubuntu/saucy/qgis/saucy

« back to all changes in this revision

Viewing changes to src/app/qgspythondialog.cpp

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2012-04-24 15:12:20 UTC
  • mfrom: (3.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20120424151220-r88g00af5fpn5fc3
Tags: 1.7.4+1.7.5~20120320-1
The "Sometimes they come back" release.

* Branching from Qgis tree and adapting to current Debian Policy and
  standards. The target tree is currently set to release-1.7.
  (closes: #661491, #606304, #615683, #616182, #600308)
* Policy bumped to 3.9.3.
* Moving to debhelper compatibility level 9.
* Source format is now 3.0 with quilt support.
* Merged with 2bf42287 upstream git snapshot.
* Migrated to dh_python2 instead of python-central.
  (closes: #617048)
* Snapshot in qgis.org release-1.7: c936d031
* Added an automagic creation of a lintian override for sqlite embedding.
  This is required for uploading currently.
* Added missing ${misc:Depends} to make lintian happy.
* Copyright notes updated and debian/copyright moved to format 1.0.
* More licenses notices now reported in debian/copyright. Thanks ftpmasters.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
    qgspythondialog.h - dialog with embedded python console
3
 
    ---------------------
4
 
    begin                : October 2006
5
 
    copyright            : (C) 2006 by Martin Dobias
6
 
    email                : wonder.sk at gmail dot com
7
 
 ***************************************************************************
8
 
 *                                                                         *
9
 
 *   This program is free software; you can redistribute it and/or modify  *
10
 
 *   it under the terms of the GNU General Public License as published by  *
11
 
 *   the Free Software Foundation; either version 2 of the License, or     *
12
 
 *   (at your option) any later version.                                   *
13
 
 *                                                                         *
14
 
 ***************************************************************************/
15
 
/* $Id$ */
16
 
 
17
 
#include "qgspythondialog.h"
18
 
#include "qgspythonutils.h"
19
 
#include "qgslogger.h"
20
 
 
21
 
#include <QShowEvent>
22
 
#include <QCloseEvent>
23
 
 
24
 
QgsPythonDialog::QgsPythonDialog( QgisInterface* pIface, QgsPythonUtils* pythonUtils, QWidget *parent )
25
 
    : QDialog( parent )
26
 
{
27
 
  setupUi( this );
28
 
#ifdef Q_WS_MAC
29
 
  // Qt4.3+ bug?: Mac window minimize control isn't enabled
30
 
  setWindowFlags( windowFlags() | Qt::WindowMinimizeButtonHint );
31
 
#endif
32
 
  mIface = pIface;
33
 
  mPythonUtils = pythonUtils;
34
 
 
35
 
  pos = 0;
36
 
}
37
 
 
38
 
QgsPythonDialog::~QgsPythonDialog()
39
 
{
40
 
}
41
 
 
42
 
QString QgsPythonDialog::escapeHtml( QString text )
43
 
{
44
 
  return text.replace( "<", "&lt;" ).replace( ">", "&gt;" );
45
 
}
46
 
 
47
 
void QgsPythonDialog::on_pbnPrev_clicked()
48
 
{
49
 
  if ( pos > 0 )
50
 
  {
51
 
    if ( pos == history.size() )
52
 
      history << edtCmdLine->toPlainText();
53
 
    else
54
 
      history[pos] = edtCmdLine->toPlainText();
55
 
    pos--;
56
 
    edtCmdLine->setText( history[pos] );
57
 
  }
58
 
}
59
 
 
60
 
void QgsPythonDialog::on_pbnNext_clicked()
61
 
{
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::execute( bool single )
71
 
{
72
 
  QString command = edtCmdLine->toPlainText();
73
 
 
74
 
  QgsDebugMsg( QString( "command: |%1| %2" ).arg( command ).arg( single ) );
75
 
 
76
 
  if ( !command.isEmpty() )
77
 
  {
78
 
    history << command;
79
 
    pos = history.size();
80
 
  }
81
 
 
82
 
  QString output;
83
 
 
84
 
  // when using Py_single_input the return value will be always null
85
 
  // we're using custom hooks for output and exceptions to show output in console
86
 
  if ( mPythonUtils->runStringUnsafe( command, single ) )
87
 
  {
88
 
    mPythonUtils->evalString( "sys.stdout.get_and_clean_data()", output );
89
 
    QString result = mPythonUtils->getResult();
90
 
    // escape the result so python objects display properly and
91
 
    // we can still use html output to get nicely formatted display
92
 
    output = escapeHtml( output ) + escapeHtml( result );
93
 
 
94
 
    if ( !output.isEmpty() )
95
 
      output += "<br>";
96
 
  }
97
 
  else
98
 
  {
99
 
    QString className, errorText;
100
 
    mPythonUtils->getError( className, errorText );
101
 
 
102
 
    output = "<font color=\"red\">" + escapeHtml( className ) + ": " + escapeHtml( errorText ) + "</font><br>";
103
 
  }
104
 
 
105
 
  QString str = "<b><font color=\"green\">&gt;&gt;&gt;</font> " + escapeHtml( command ) + "</b><br>" + output;
106
 
 
107
 
  edtCmdLine->setText( "" );
108
 
 
109
 
  txtHistory->moveCursor( QTextCursor::End );
110
 
  txtHistory->insertHtml( str );
111
 
  txtHistory->moveCursor( QTextCursor::End );
112
 
  txtHistory->ensureCursorVisible();
113
 
}
114
 
 
115
 
void QgsPythonDialog::on_pbnExecute_clicked()
116
 
{
117
 
  execute( false );
118
 
}
119
 
 
120
 
void QgsPythonDialog::on_pbnEval_clicked()
121
 
{
122
 
  execute( true );
123
 
}
124
 
 
125
 
void QgsPythonDialog::showEvent( QShowEvent* event )
126
 
{
127
 
  QDialog::showEvent( event );
128
 
 
129
 
  mPythonUtils->installConsoleHooks();
130
 
}
131
 
 
132
 
void QgsPythonDialog::closeEvent( QCloseEvent* event )
133
 
{
134
 
  mPythonUtils->uninstallConsoleHooks();
135
 
 
136
 
  QDialog::closeEvent( event );
137
 
}