]> SALOME platform Git repositories - modules/gui.git/blob - tools/PyEditor/src/PyEditor.cxx
Salome HOME
Merge branch 'V8_2_BR'
[modules/gui.git] / tools / PyEditor / src / PyEditor.cxx
1 // Copyright (C) 2015-2016  OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // File   : PyEditor.cxx
20 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
21 //
22
23 #include "PyEditor_Window.h"
24 #include "PyEditor_StdSettings.h"
25
26 #include <QApplication>
27 #include <QDir>
28 #include <QLibraryInfo>
29 #include <QLocale>
30 #include <QStringList>
31 #include <QTranslator>
32
33 QString qtTrDir()
34 {
35   const char* vars[] = { "QT5_ROOT_DIR", "QT_ROOT_DIR", "QTDIR" };
36   QString qtPath;
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" );
41   return qtPath;
42 }
43
44 QString resourceDir()
45 {
46   // Try standalone application's dir.
47   QDir appDir = QApplication::applicationDirPath();
48   appDir.cdUp();
49   QFileInfo resFile( appDir.filePath( "share/resources/PyEditor_msg_en.qm" ) );
50   if ( resFile.exists() )
51     return resFile.absolutePath();
52
53   // Try salome dir.
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();
59
60   return QString();
61 }
62
63 int main( int argc, char *argv[] )
64 {
65   QApplication app( argc, argv );
66   app.setOrganizationName( "salome" );
67   app.setOrganizationDomain( "www.salome-platform.org" );
68   app.setApplicationName( "pyeditor" );
69   
70   PyEditor_StdSettings* settings = new PyEditor_StdSettings();
71   PyEditor_Settings::setSettings( settings );
72   
73   QString language = settings->language();
74   
75   // Load Qt translations.
76   QString qtDirTrSet = QLibraryInfo::location( QLibraryInfo::TranslationsPath );
77   QString qtDirTrEnv = qtTrDir();
78   
79   QStringList qtTrFiles;
80   qtTrFiles << "qt" << "qtbase";
81   QStringList qtTrDirs;
82   qtTrDirs << QLibraryInfo::location( QLibraryInfo::TranslationsPath );
83   qtTrDirs << qtTrDir();
84   
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 );
90         break;
91       }
92       else {
93         delete translator;
94       }
95     }
96   }
97   
98   // Load application's translations.
99   QTranslator translator;
100   if ( translator.load( QString( "PyEditor_msg_%1" ).arg( language ), resourceDir() ) )
101     app.installTranslator( &translator );
102   
103   PyEditor_Window window;
104   window.setWindowIcon( QIcon( ":/images/py_editor.png" ) );
105   window.resize( 650, 700 );
106   window.show();
107   
108   return app.exec();
109 }