* ./hurricane/src/viewer:

- New: Specific support for Stratus scripts. In a perfect world, this
        should be added in the stratus tool, but it would be much more
        complicated.
This commit is contained in:
Jean-Paul Chaput 2010-08-26 22:01:12 +00:00
parent 88ea3785eb
commit c2f3a393f1
9 changed files with 220 additions and 6 deletions

View File

@ -35,6 +35,7 @@
hurricane/viewer/DisplayFilterWidget.h
hurricane/viewer/ControllerWidget.h
hurricane/viewer/ScriptWidget.h
hurricane/viewer/StratusWidget.h
)
set ( includes hurricane/viewer/ScreenUtilities.h
hurricane/viewer/DisplayStyle.h
@ -94,6 +95,7 @@
DisplayFilterWidget.cpp
ControllerWidget.cpp
ScriptWidget.cpp
StratusWidget.cpp
)
set ( pycpps PyViewer.cpp
PyCellViewer.cpp

View File

@ -45,6 +45,7 @@
#include "hurricane/viewer/MousePositionWidget.h"
#include "hurricane/viewer/ControllerWidget.h"
#include "hurricane/viewer/ScriptWidget.h"
#include "hurricane/viewer/StratusWidget.h"
#include "hurricane/viewer/GotoWidget.h"
@ -71,6 +72,7 @@ namespace Hurricane {
, _clearRulersAction (NULL)
, _controllerAction (NULL)
, _scriptAction (NULL)
, _stratusAction (NULL)
, _fileMenu (NULL)
, _viewMenu (NULL)
, _toolsMenu (NULL)
@ -218,6 +220,11 @@ namespace Hurricane {
_scriptAction->setStatusTip ( tr("Run Python Script") );
_scriptAction->setIcon ( QIcon(":/images/python-logo-v3.png") );
//_scriptAction->setShortcut ( QKeySequence(tr("CTRL+I")) );
_stratusAction = new QAction ( tr("Stratus"), this );
_stratusAction->setObjectName ( "viewer.menuBar.tools.stratusScript" );
_stratusAction->setStatusTip ( tr("Run Stratus Script") );
_stratusAction->setIcon ( QIcon(":/images/stratus-cloud.png") );
}
@ -261,6 +268,7 @@ namespace Hurricane {
_toolsMenu->setObjectName ( "viewer.menuBar.tools" );
_toolsMenu->addAction ( _controllerAction );
_toolsMenu->addAction ( _scriptAction );
_toolsMenu->addAction ( _stratusAction );
}
@ -319,6 +327,7 @@ namespace Hurricane {
connect ( _clearRulersAction , SIGNAL(triggered()) , _cellWidget, SLOT(clearRulers()) );
connect ( _controllerAction , SIGNAL(triggered()) , _controller, SLOT(toggleShow()) );
connect ( _scriptAction , SIGNAL(triggered()) , this , SLOT(runScript()) );
connect ( _stratusAction , SIGNAL(triggered()) , this , SLOT(runStratusScript()) );
connect ( _gotoAction , SIGNAL(triggered()) , this , SLOT(doGoto()) );
connect ( _cellWidget , SIGNAL(dbuModeChanged(unsigned int,DbU::UnitPower))
@ -558,9 +567,11 @@ namespace Hurricane {
void CellViewer::runScript ()
{
ScriptWidget::runScript ( this, getCell() );
}
{ ScriptWidget::runScript ( this, getCell() ); }
void CellViewer::runStratusScript ()
{ StratusWidget::runScript ( this ); }
} // End of Hurricane namespace.

View File

@ -10,6 +10,7 @@
<file>images/gtk-go-forward-ltr.png</file>
<file>images/swiss-knife.png</file>
<file>images/python-logo-v3.png</file>
<file>images/stratus-cloud.png</file>
<file>images/gnome-gmush.png</file>
<file>images/gnome-core.png</file>
<file>images/i-core.png</file>

View File

@ -119,7 +119,7 @@ namespace Isobar {
{ _cellViewer = viewer; }
bool Script::runFunction ( const std::string& function, Cell* cell )
bool Script::runFunction ( const std::string& function, Cell* cell, unsigned int flags )
{
bool returnCode = true;
@ -148,7 +148,7 @@ namespace Isobar {
if ( cell != NULL ) PyTuple_SetItem ( _pyArgs, 0, (PyObject*)PyCell_Link(cell) );
else PyTuple_SetItem ( _pyArgs, 0, Py_None );
_pyResult = PyEval_CallObject ( _pyFunction, _pyArgs );
_pyResult = PyEval_CallObject ( _pyFunction, (flags&NoScriptArgs) ? NULL : _pyArgs );
if ( _pyResult == NULL ) {
cerr << "Something has gone slightly wrong" << endl;

View File

@ -0,0 +1,141 @@
// -*- C++ -*-
//
// This file is part of the Coriolis Software.
// Copyright (c) UPMC/LIP6 2008-2010, All Rights Reserved
//
// ===================================================================
//
// $Id$
//
// x-----------------------------------------------------------------x
// | |
// | C O R I O L I S |
// | V L S I B a c k e n d D a t a - B a s e |
// | |
// | Author : Jean-Paul CHAPUT |
// | E-mail : Jean-Paul.Chaput@asim.lip6.fr |
// | =============================================================== |
// | C++ Module : "./StratusWidget.cpp" |
// | *************************************************************** |
// | U p d a t e s |
// | |
// x-----------------------------------------------------------------x
#include <iostream>
#include <memory>
using namespace std;
#include <boost/filesystem/operations.hpp>
namespace bfs = boost::filesystem;
#include "hurricane/Warning.h"
#include "hurricane/viewer/Script.h"
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QRadioButton>
#include <QButtonGroup>
#include <QCheckBox>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include "hurricane/viewer/Graphics.h"
#include "hurricane/viewer/StratusWidget.h"
#include "hurricane/viewer/CellViewer.h"
namespace Hurricane {
// -------------------------------------------------------------------
// Class : "StratusWidget".
StratusWidget::StratusWidget ( QWidget* parent )
: QDialog (parent)
, _lineEdit(NULL)
{
setWindowTitle ( tr("Execute Stratus Script") );
QLabel* label = new QLabel ();
label->setText ( tr("Stratus script to execute") );
label->setFont ( Graphics::getNormalFont(true) );
_lineEdit = new QLineEdit ();
_lineEdit->setMinimumWidth ( 400 );
QPushButton* okButton = new QPushButton ();
okButton->setText ( "OK" );
okButton->setDefault ( true );
QPushButton* cancelButton = new QPushButton ();
cancelButton->setText ( "Cancel" );
QHBoxLayout* hLayout1 = new QHBoxLayout ();
hLayout1->addStretch ();
hLayout1->addWidget ( okButton );
hLayout1->addStretch ();
hLayout1->addWidget ( cancelButton );
hLayout1->addStretch ();
//QFrame* separator = new QFrame ();
//separator->setFrameShape ( QFrame::HLine );
//separator->setFrameShadow ( QFrame::Sunken );
QVBoxLayout* vLayout = new QVBoxLayout ();
vLayout->setSizeConstraint ( QLayout::SetFixedSize );
vLayout->addWidget ( label );
vLayout->addWidget ( _lineEdit );
vLayout->addLayout ( hLayout1 );
//vLayout->addWidget ( separator );
setLayout ( vLayout );
//setModal ( true );
connect ( okButton, SIGNAL(clicked()) , this, SLOT(accept()) );
connect ( cancelButton, SIGNAL(clicked()) , this, SLOT(reject()) );
}
const QString StratusWidget::getScriptName () const
{
return _lineEdit->text();
}
bool StratusWidget::runScript ( QWidget* parent )
{
StratusWidget* dialog = new StratusWidget ( parent );
bool doRunStratus = (dialog->exec() == Accepted);
QString scriptName = dialog->getScriptName ();
delete dialog;
if ( not doRunStratus ) return false;
if ( scriptName.endsWith(".py",Qt::CaseInsensitive) )
scriptName.truncate ( scriptName.size()-3 );
bfs::path userStratus = scriptName.toStdString();
bfs::path userDirectory = userStratus.branch_path();
if ( not userDirectory.is_complete() )
userDirectory = bfs::current_path() / userDirectory;
userDirectory.normalize();
Isobar::Script::addPath ( userDirectory.string() );
dbo_ptr<Isobar::Script> script = Isobar::Script::create(userStratus.leaf());
script->setEditor ( qobject_cast<CellViewer*>(parent) );
bool returnCode = script->runFunction ( "StratusScript", NULL, Isobar::Script::NoScriptArgs );
Isobar::Script::removePath ( userDirectory.string() );
return returnCode;
}
} // End of Hurricane namespace.

View File

@ -92,6 +92,7 @@ namespace Hurricane {
void raiseToolInterrupt ();
void clearToolInterrupt ();
void runScript ();
void runStratusScript ();
signals:
void showSelectionToggled ( bool );
void stateChanged ( shared_ptr<CellWidget::State>& );
@ -124,6 +125,7 @@ namespace Hurricane {
QAction* _clearRulersAction;
QAction* _controllerAction;
QAction* _scriptAction;
QAction* _stratusAction;
QMenu* _fileMenu;
QMenu* _viewMenu;
QMenu* _toolsMenu;

View File

@ -53,6 +53,8 @@ namespace Isobar {
class Script {
public:
enum Flags { NoScriptArgs=0x1 };
public:
static void addPath ( const std::string& path );
static void removePath ( const std::string& path );
@ -62,7 +64,7 @@ namespace Isobar {
inline PyObject* getHurricaneModule ();
inline PyObject* getUserModule ();
void setEditor ( Hurricane::CellViewer* );
bool runFunction ( const std::string& function, Hurricane::Cell* cell );
bool runFunction ( const std::string& function, Hurricane::Cell* cell, unsigned int flags=0 );
protected:
static std::vector<std::string> _pathes;
std::string _moduleName;

View File

@ -0,0 +1,55 @@
// -*- C++ -*-
//
// This file is part of the Coriolis Software.
// Copyright (c) UPMC/LIP6 2008-2010, All Rights Reserved
//
// ===================================================================
//
// $Id$
//
// x-----------------------------------------------------------------x
// | |
// | C O R I O L I S |
// | V L S I B a c k e n d D a t a - B a s e |
// | |
// | Author : Jean-Paul CHAPUT |
// | E-mail : Jean-Paul.Chaput@asim.lip6.fr |
// | =============================================================== |
// | C++ Header : "./StratusWidget.h" |
// | *************************************************************** |
// | U p d a t e s |
// | |
// x-----------------------------------------------------------------x
#ifndef __HURRICANE_STRATUS_WIDGET__
#define __HURRICANE_STRATUS_WIDGET__
#include <QDialog>
class QLineEdit;
namespace Hurricane {
class Cell;
class StratusWidget : public QDialog {
Q_OBJECT;
public:
static bool runScript ( QWidget* parent );
const QString getScriptName () const;
protected:
StratusWidget ( QWidget* parent=NULL );
protected:
QLineEdit* _lineEdit;
};
} // End of Hurricane namespace.
#endif // __HURRICANE_STRATUS_WIDGET__

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB