1 // Copyright (C) 2015-2023 OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // File : PyEditor.cxx
20 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
23 #include "PyEditor_Widget.h"
24 #include "PyEditor_Window.h"
25 #include "PyEditor_StdSettings.h"
27 #include <QApplication>
28 #include <QCommandLineParser>
30 #include <QLibraryInfo>
32 #include <QStringList>
33 #include <QTranslator>
37 const char* vars[] = { "QT5_ROOT_DIR", "QT_ROOT_DIR", "QTDIR" };
39 for ( uint i = 0; i < sizeof( vars ) / sizeof( vars[0] ) && qtPath.isEmpty(); i++ )
40 qtPath = qgetenv( vars[i] );
41 if ( !qtPath.isEmpty() )
42 qtPath = QDir( qtPath ).absoluteFilePath( "translations" );
48 // Try standalone application's dir.
49 QDir appDir = QApplication::applicationDirPath();
51 QFileInfo resFile( appDir.filePath( "share/resources/PyEditor_msg_en.qm" ) );
52 if ( resFile.exists() )
53 return resFile.absolutePath();
56 appDir = QApplication::applicationDirPath();
57 appDir.cdUp(); appDir.cdUp();
58 resFile.setFile( appDir.filePath( "share/salome/resources/gui/PyEditor_msg_en.qm" ) );
59 if ( resFile.exists() )
60 return resFile.absolutePath();
65 int main( int argc, char *argv[] )
67 QApplication app( argc, argv );
68 app.setOrganizationName( "salome" );
69 app.setOrganizationDomain( "www.salome-platform.org" );
70 app.setApplicationName( "pyeditor" );
74 PyEditor_StdSettings* settings = new PyEditor_StdSettings();
75 PyEditor_Settings::setSettings( settings );
77 // Load Qt translations.
78 QString qtDirTrSet = QLibraryInfo::location( QLibraryInfo::TranslationsPath );
79 QString qtDirTrEnv = qtTrDir();
81 QStringList qtTrFiles;
82 qtTrFiles << "qt" << "qtbase";
84 qtTrDirs << QLibraryInfo::location( QLibraryInfo::TranslationsPath );
85 qtTrDirs << qtTrDir();
87 foreach( QString qtTrFile, qtTrFiles ) {
88 foreach ( QString qtTrDir, qtTrDirs ) {
89 QTranslator* translator = new QTranslator;
90 if ( translator->load( locale, QString("%1").arg( qtTrFile ), "_", qtTrDir ) ) {
91 app.installTranslator( translator );
94 else if ( translator->load( QString("%1_en").arg( qtTrFile ), qtTrDir ) ) {
95 app.installTranslator( translator );
104 // Load application's translations.
105 QTranslator translator;
106 if ( translator.load( locale, QString( "PyEditor_msg" ), "_", resourceDir() ) )
107 app.installTranslator( &translator );
108 else if ( translator.load( QString( "PyEditor_msg_en" ), resourceDir() ) )
109 app.installTranslator( &translator );
111 QCommandLineParser parser;
112 parser.setApplicationDescription( QApplication::translate( "PyEditor", "PROGRAM_DESCRIPTION" ) );
113 parser.addHelpOption();
114 QCommandLineOption gotoOption( QStringList() << "l" << "line",
115 QApplication::translate( "PyEditor", "Set initial line number." ),
117 parser.addOption( gotoOption );
118 parser.addPositionalArgument( QApplication::translate( "PyEditor", "FILE_PARAM_NAME" ),
119 QApplication::translate( "PyEditor", "FILE_PARAM_DESCRIPTION" ) );
121 parser.process( app );
122 const QStringList args = parser.positionalArguments();
124 PyEditor_Window window;
125 window.setWindowIcon( QIcon( ":/images/py_editor.png" ) );
126 window.resize( 650, 700 );
129 if ( args.count() > 0 ) {
130 window.loadFile( args[0], false );
132 if ( parser.isSet( gotoOption ) ) {
134 int line = parser.value( gotoOption ).toInt( &ok );
136 window.editor()->setCurrentLine( line );