#include <qfileinfo.h>
#include <qdir.h>
+#include <qapplication.h>
+#include <qregexp.h>
/*!
Constructor
*/
QString SUIT_ResourceMgr::userFileName( const QString& appName, const bool for_load ) const
{
- QString pathName = QtxResourceMgr::userFileName( appName );
+ QString pathName;
+
+ // Try config file, given in arguments
+ for (int i = 1; i < qApp->argc(); i++) {
+ QRegExp rx ("--resources=(.+)");
+ if ( rx.search( QString(qApp->argv()[i]) ) >= 0 && rx.capturedTexts().count() > 1 ) {
+ QString file = rx.capturedTexts()[1];
+ QFileInfo fi (file);
+ pathName = fi.absFilePath();
+ }
+ }
+
+ if (!pathName.isEmpty())
+ return pathName;
+
+ // QtxResourceMgr::userFileName() + '.' + version()
+ pathName = QtxResourceMgr::userFileName( appName );
if ( !version().isEmpty() )
pathName += QString( "." ) + version();
- if( !QFileInfo( pathName ).exists() && for_load )
+ if ( !QFileInfo( pathName ).exists() && for_load )
{
QString newName = findAppropriateUserFile( pathName );
- if( !newName.isEmpty() )
+ if ( !newName.isEmpty() )
pathName = newName;
}
static bool isFirst = true;
if ( isFirst ) {
isFirst = false;
+
QString hdffile;
QStringList pyfiles;
+
for (int i = 1; i < qApp->argc(); i++) {
- QRegExp rx("--test=(.+)");
- if ( rx.search( QString(qApp->argv()[i]) ) >= 0 && rx.capturedTexts().count() > 0 ) {
- QStringList files = QStringList::split(",",rx.capturedTexts()[1],false);
- for (uint j = 0; j < files.count(); j++ ) {
- QFileInfo fi( files[j] );
- QString extension = fi.extension( false ).lower();
- if ( extension == "hdf" && fi.exists() )
- hdffile = fi.absFilePath();
- else if ( extension == "py" || extension == "" )
- pyfiles.append( fi.baseName( true ) );
- }
+ QRegExp rxs ("--study-hdf=(.+)");
+ if ( rxs.search( QString(qApp->argv()[i]) ) >= 0 && rxs.capturedTexts().count() > 1 ) {
+ QString file = rxs.capturedTexts()[1];
+ QFileInfo fi ( file );
+ QString extension = fi.extension( false ).lower();
+ if ( extension == "hdf" && fi.exists() )
+ hdffile = fi.absFilePath();
+ }
+ else {
+ QRegExp rxp ("--pyscript=(.+)");
+ if ( rxp.search( QString(qApp->argv()[i]) ) >= 0 && rxp.capturedTexts().count() > 1 ) {
+ QStringList files = QStringList::split(",",rxp.capturedTexts()[1],false);
+ pyfiles += files;
+ }
}
}
+
if ( !hdffile.isEmpty() ) // open hdf file given as parameter
onOpenDoc( hdffile );
else if ( pyfiles.count() > 0 ) // create new study
onNewDoc();
- // import python scripts
+
+ // import/execute python scripts
if ( pyfiles.count() > 0 && activeStudy() ) {
SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
if ( appStudy ) {
_PTR(Study) aStudy = appStudy->studyDS();
if ( !aStudy->GetProperties()->IsLocked() ) {
- for ( uint i = 0; i < pyfiles.count(); i++ ) {
- QString command = QString( "import %1" ).arg( pyfiles[i] );
+ for (uint j = 0; j < pyfiles.count(); j++ ) {
+ QFileInfo fi ( pyfiles[j] );
PythonConsole* pyConsole = pythonConsole();
- if ( pyConsole )
- pyConsole->exec( command );
- }
+ if ( pyConsole ) {
+ QString extension = fi.extension( false ).lower();
+ if ( extension == "py" && fi.exists() ) {
+ // execute python script
+ QString command = QString( "execfile(\"%1\")" ).arg( fi.absFilePath() );
+ pyConsole->exec( command );
+ }
+ else {
+ // import python module
+ QString command = QString( "import %1" ).arg( pyfiles[j] );
+ //QString command = QString( "import %1" ).arg( fi.baseName( true ) );
+ pyConsole->exec( command );
+ }
+ }
+ }
}
}
}