1 // Copyright (C) 2015-2016 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_Window.h"
24 #include "PyEditor_StdSettings.h"
26 #include <QApplication>
28 #include <QLibraryInfo>
30 #include <QStringList>
31 #include <QTranslator>
35 const char* vars[] = { "QT5_ROOT_DIR", "QT_ROOT_DIR", "QTDIR" };
37 for ( uint i = 0; i < sizeof( vars ) / sizeof( vars[0] ) && qtPath.isEmpty(); i++ )
38 qtPath = qgetenv( vars[i] );
39 if ( !qtPath.isEmpty() )
40 qtPath = QDir( qtPath ).absoluteFilePath( "translations" );
46 // Try standalone application's dir.
47 QDir appDir = QApplication::applicationDirPath();
49 QFileInfo resFile( appDir.filePath( "share/resources/PyEditor_msg_en.qm" ) );
50 if ( resFile.exists() )
51 return resFile.absolutePath();
54 appDir = QApplication::applicationDirPath();
55 appDir.cdUp(); appDir.cdUp();
56 resFile.setFile( appDir.filePath( "share/salome/resources/gui/PyEditor_msg_en.qm" ) );
57 if ( resFile.exists() )
58 return resFile.absolutePath();
63 int main( int argc, char *argv[] )
65 QApplication app( argc, argv );
66 app.setOrganizationName( "salome" );
67 app.setOrganizationDomain( "www.salome-platform.org" );
68 app.setApplicationName( "pyeditor" );
70 PyEditor_StdSettings* settings = new PyEditor_StdSettings();
71 PyEditor_Settings::setSettings( settings );
73 QString language = settings->language();
75 // Load Qt translations.
76 QString qtDirTrSet = QLibraryInfo::location( QLibraryInfo::TranslationsPath );
77 QString qtDirTrEnv = qtTrDir();
79 QStringList qtTrFiles;
80 qtTrFiles << "qt" << "qtbase";
82 qtTrDirs << QLibraryInfo::location( QLibraryInfo::TranslationsPath );
83 qtTrDirs << qtTrDir();
85 foreach( QString qtTrFile, qtTrFiles ) {
86 foreach ( QString qtTrDir, qtTrDirs ) {
87 QTranslator* translator = new QTranslator;
88 if ( translator->load( QString("%1_%2").arg( qtTrFile ).arg( language ), qtTrDir ) ) {
89 app.installTranslator( translator );
98 // Load application's translations.
99 QTranslator translator;
100 if ( translator.load( QString( "PyEditor_msg_%1" ).arg( language ), resourceDir() ) )
101 app.installTranslator( &translator );
103 PyEditor_Window window;
104 window.setWindowIcon( QIcon( ":/images/py_editor.png" ) );
105 window.resize( 650, 700 );