From c2f3a393f1cdbdfe92e8caa54c33024760ce804c Mon Sep 17 00:00:00 2001 From: Jean-Paul Chaput Date: Thu, 26 Aug 2010 22:01:12 +0000 Subject: [PATCH] * ./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. --- hurricane/src/viewer/CMakeLists.txt | 2 + hurricane/src/viewer/CellViewer.cpp | 17 ++- hurricane/src/viewer/CellViewer.qrc | 1 + hurricane/src/viewer/Script.cpp | 4 +- hurricane/src/viewer/StratusWidget.cpp | 141 ++++++++++++++++++ .../src/viewer/hurricane/viewer/CellViewer.h | 2 + .../src/viewer/hurricane/viewer/Script.h | 4 +- .../viewer/hurricane/viewer/StratusWidget.h | 55 +++++++ hurricane/src/viewer/images/stratus-cloud.png | Bin 0 -> 1961 bytes 9 files changed, 220 insertions(+), 6 deletions(-) create mode 100644 hurricane/src/viewer/StratusWidget.cpp create mode 100644 hurricane/src/viewer/hurricane/viewer/StratusWidget.h create mode 100644 hurricane/src/viewer/images/stratus-cloud.png diff --git a/hurricane/src/viewer/CMakeLists.txt b/hurricane/src/viewer/CMakeLists.txt index 80fb051c..3d86585a 100644 --- a/hurricane/src/viewer/CMakeLists.txt +++ b/hurricane/src/viewer/CMakeLists.txt @@ -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 diff --git a/hurricane/src/viewer/CellViewer.cpp b/hurricane/src/viewer/CellViewer.cpp index c2a8b568..46cde454 100644 --- a/hurricane/src/viewer/CellViewer.cpp +++ b/hurricane/src/viewer/CellViewer.cpp @@ -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. diff --git a/hurricane/src/viewer/CellViewer.qrc b/hurricane/src/viewer/CellViewer.qrc index b9c33291..6955f120 100644 --- a/hurricane/src/viewer/CellViewer.qrc +++ b/hurricane/src/viewer/CellViewer.qrc @@ -10,6 +10,7 @@ images/gtk-go-forward-ltr.png images/swiss-knife.png images/python-logo-v3.png + images/stratus-cloud.png images/gnome-gmush.png images/gnome-core.png images/i-core.png diff --git a/hurricane/src/viewer/Script.cpp b/hurricane/src/viewer/Script.cpp index e6a23f84..a56474d8 100644 --- a/hurricane/src/viewer/Script.cpp +++ b/hurricane/src/viewer/Script.cpp @@ -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; diff --git a/hurricane/src/viewer/StratusWidget.cpp b/hurricane/src/viewer/StratusWidget.cpp new file mode 100644 index 00000000..6754e094 --- /dev/null +++ b/hurricane/src/viewer/StratusWidget.cpp @@ -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 +#include +using namespace std; + +#include +namespace bfs = boost::filesystem; + +#include "hurricane/Warning.h" +#include "hurricane/viewer/Script.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#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 script = Isobar::Script::create(userStratus.leaf()); + script->setEditor ( qobject_cast(parent) ); + + bool returnCode = script->runFunction ( "StratusScript", NULL, Isobar::Script::NoScriptArgs ); + + Isobar::Script::removePath ( userDirectory.string() ); + + return returnCode; + } + + +} // End of Hurricane namespace. diff --git a/hurricane/src/viewer/hurricane/viewer/CellViewer.h b/hurricane/src/viewer/hurricane/viewer/CellViewer.h index 1e9e6d07..6db7a03f 100644 --- a/hurricane/src/viewer/hurricane/viewer/CellViewer.h +++ b/hurricane/src/viewer/hurricane/viewer/CellViewer.h @@ -92,6 +92,7 @@ namespace Hurricane { void raiseToolInterrupt (); void clearToolInterrupt (); void runScript (); + void runStratusScript (); signals: void showSelectionToggled ( bool ); void stateChanged ( shared_ptr& ); @@ -124,6 +125,7 @@ namespace Hurricane { QAction* _clearRulersAction; QAction* _controllerAction; QAction* _scriptAction; + QAction* _stratusAction; QMenu* _fileMenu; QMenu* _viewMenu; QMenu* _toolsMenu; diff --git a/hurricane/src/viewer/hurricane/viewer/Script.h b/hurricane/src/viewer/hurricane/viewer/Script.h index 31edd481..18a8a69e 100644 --- a/hurricane/src/viewer/hurricane/viewer/Script.h +++ b/hurricane/src/viewer/hurricane/viewer/Script.h @@ -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 _pathes; std::string _moduleName; diff --git a/hurricane/src/viewer/hurricane/viewer/StratusWidget.h b/hurricane/src/viewer/hurricane/viewer/StratusWidget.h new file mode 100644 index 00000000..2eb91db1 --- /dev/null +++ b/hurricane/src/viewer/hurricane/viewer/StratusWidget.h @@ -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 + +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__ + diff --git a/hurricane/src/viewer/images/stratus-cloud.png b/hurricane/src/viewer/images/stratus-cloud.png new file mode 100644 index 0000000000000000000000000000000000000000..3b60d8633df4eb1ed61cc9f46c415592f3117842 GIT binary patch literal 1961 zcmV;a2UhrrP)up zSad^gZEa<4bO206K|~-_Wn*Y=Z)|U8X=QUDNp52u zzgj+bdv?CDb8+tI;IQpunin*Nh&CWVNRb#l)>;}8;)U!|kJ9pJ*)o`r4IXUn!mty+cwU%PiG;jY_o!HX|ub)l~5z;8Va_i?Isv zj{fNx{oXmh`PI*VJlLL*__zw|1N#TBON6@~$F zAR#CsnK8H|Bs3so(eZeDlf|lLV`Jk7FT4+jSaAEcD# z0j^(vo*^v2_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