1 // SUPERV SUPERVGUI : GUI for Supervisor component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SUPERVGUI_Python.cxx
25 // Author : Francis KLOSS
29 #include "SUPERVGUI_Def.h"
30 #include "QAD_PyEditor.h"
31 #include "QAD_PyInterp.h"
32 #include "QAD_Application.h"
33 #include "SUPERVGUI_Python.h"
34 #include <qgroupbox.h>
36 #include <qapplication.h>
38 #define MARGIN_SIZE 11
39 #define SPACING_SIZE 6
40 #define MIN_PYTHON_WIDTH 300
41 #define MIN_PYTHON_HEIGHT 200
46 SUPERVGUI_Python::SUPERVGUI_Python(QAD_PyInterp* pi, bool isReadOnly)
47 : QDialog( 0, "", TRUE, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
50 Trace("SUPERVGUI_Python::SUPERVGUI_Python");
51 setCaption("Python Control Code");
52 setSizeGripEnabled( TRUE );
54 QVBoxLayout* topLayout = new QVBoxLayout( this );
55 topLayout->setMargin( MARGIN_SIZE ); topLayout->setSpacing( SPACING_SIZE );
57 edit = new QMultiLineEdit( this );
58 edit->setPalette( QAD_Application::getPalette( true ) );
59 edit->setReadOnly( isReadOnly );
60 edit->setMinimumSize( MIN_PYTHON_WIDTH, MIN_PYTHON_HEIGHT );
62 QGroupBox* GroupButtons = new QGroupBox( this );
63 GroupButtons->setColumnLayout(0, Qt::Vertical );
64 GroupButtons->layout()->setSpacing( 0 ); GroupButtons->layout()->setMargin( 0 );
65 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons->layout() );
66 GroupButtonsLayout->setAlignment( Qt::AlignTop );
67 GroupButtonsLayout->setSpacing( SPACING_SIZE );
68 GroupButtonsLayout->setMargin( MARGIN_SIZE );
71 ok = new QPushButton( tr( "BUT_OK" ), GroupButtons, "buttonOk" );
72 ok->setAutoDefault( TRUE ); ok->setDefault( TRUE );
73 GroupButtonsLayout->addWidget( ok );
74 connect( ok, SIGNAL( clicked() ), this, SLOT( accept() ) );
76 GroupButtonsLayout->addStretch();
77 ko = new QPushButton( isReadOnly ? tr( "BUT_CLOSE" ) : tr( "BUT_CANCEL" ), GroupButtons, "buttonCancel" );
78 ko->setAutoDefault( TRUE );
79 GroupButtonsLayout->addWidget( ko );
80 connect( ko, SIGNAL( clicked() ), this, SLOT( reject() ) );
82 GroupButtonsLayout->addStretch();
84 topLayout->addWidget( edit );
85 topLayout->addWidget( GroupButtons );
91 SUPERVGUI_Python::~SUPERVGUI_Python() {
92 Trace("SUPERVGUI_Python::~SUPERVGUI_Python")
98 void SUPERVGUI_Python::accept() {
99 Trace("SUPERVGUI_Python::okButton");
101 qApp->processEvents();
102 int n = edit->numLines();
103 for ( int li = 0; li < n; li++ ) {
104 QString ligne = edit->textLine( li );
105 if ( !ligne.isEmpty() ) {
106 if ( py_int->run( ligne.latin1() ) ) {
107 QMessageBox::warning(0, "Supervision Error", "Can't Reload Python Code");
116 void SUPERVGUI_Python::reject() {
117 Trace("SUPERVGUI_Python::koButton");