Salome HOME
except et print
[tools/eficas.git] / InterfaceQT4 / eficas_go.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # Copyright (C) 2007-2013   EDF R&D
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 #
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #
21
22 # Modules Python
23 import sys,os
24 repIni=os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)),".."))
25 from  determine import monEnvQT5
26 if monEnvQT5 : 
27     ihmQTDir=os.path.join(repIni,"UiQT5")
28     from PyQt5.QtWidgets import QApplication
29 else         : 
30     ihmQTDir=os.path.join(repIni,"UiQT4")
31     from PyQt4.QtGui import QApplication
32 editeurDir=os.path.join(repIni,"Editeur")
33 ihmDir=os.path.join(repIni,"InterfaceQT4")
34 if ihmDir not in sys.path : sys.path.append(ihmDir)
35 if ihmQTDir not in sys.path : sys.path.append(ihmQTDir)
36 if editeurDir not in sys.path :sys.path.append(editeurDir)
37
38
39 def lance_eficas(code=None,fichier=None,ssCode=None,multi=False,langue='en'):
40     """
41         Lance l'appli EFICAS
42     """
43     # Analyse des arguments de la ligne de commande
44     from Editeur  import session
45     options=session.parse(sys.argv)
46     if options.code!= None : code=options.code
47     if options.ssCode!= None : ssCode=options.ssCode
48
49     from qtEficas import Appli
50     app = QApplication(sys.argv)
51     Eficas=Appli(code=code,ssCode=ssCode,multi=multi,langue=langue)
52     Eficas.show()
53
54     res=app.exec_()
55     sys.exit(res)
56
57
58 def lance_eficas_ssIhm(code=None,fichier=None,ssCode=None,version=None):
59     """
60         Lance l'appli EFICAS pour trouver les noms des groupes
61     """
62     # Analyse des arguments de la ligne de commande
63     from Editeur  import session
64     options=session.parse(sys.argv)
65     if version!=None and options.cata==None : options.cata=version
66     if fichier==None : fichier=options.comm[0]
67     if code == None : code=options.code
68
69     from qtEficas import Appli
70     Eficas=Appli(code=code,ssCode=ssCode,ssIhm=True)
71
72     from ssIhm  import QWParentSSIhm
73     parent=QWParentSSIhm(code,Eficas,version)
74
75     import readercata
76     if not hasattr ( Eficas, 'readercata'):
77            monreadercata  = readercata.READERCATA( parent, Eficas )
78            Eficas.readercata=monreadercata
79
80     from editor import JDCEditor
81     monEditeur=JDCEditor(Eficas,fichier)
82     return monEditeur
83
84 def lance_eficas_ssIhm_cherche_Groupes(code=None,fichier=None,ssCode=None,version=None):
85     monEditeur=lance_eficas_ssIhm(code,fichier,ssCode,version)
86     print monEditeur.cherche_Groupes()
87
88 def lance_eficas_ssIhm_cherche_cr(code=None,fichier=None,ssCode=None,version=None):
89     monEditeur=lance_eficas_ssIhm(code,fichier,ssCode,version)
90     print monEditeur.jdc.cr
91
92 def lance_eficas_ssIhm_reecrit(code=None,fichier=None,ssCode=None,version=None,ou=None,cr=False):
93     #print 'lance_eficas_ssIhm_reecrit', fichier
94     monEditeur=lance_eficas_ssIhm(code,fichier,ssCode,version)
95     if ou == None : 
96        fileName=fichier.split(".")[0]+"_reecrit.comm"
97        fn=fichier.split(".")[0]+"_cr.txt"
98     else :
99        f=fichier.split(".")[0]+"_reecrit.comm"
100        f1=os.path.basename(f)
101        fn=fichier.split(".")[0]+"_cr.txt"
102        f2=os.path.basename(fn)
103        fileName=os.path.join(ou,f1)
104        fileCr=os.path.join(ou,f2)
105     monEditeur.saveFileAs(fileName=fileName)
106     if cr:
107        f = open(fileCr, 'wb')
108        f.write(str(monEditeur.jdc.report()))
109        f.close()
110
111 def lance_eficas_param(code='Adao',fichier=None,version='V0',macro='ASSIMILATION_STUDY'):
112     """
113         Lance l'appli EFICAS pour trouver les noms des groupes
114     """
115     # Analyse des arguments de la ligne de commande
116     from Editeur  import session
117     options=session.parse(sys.argv)
118
119     from qtEficas import Appli
120     app = QApplication(sys.argv)
121     Eficas=Appli(code=code,ssCode=None)
122
123     from ssIhm  import QWParentSSIhm
124     parent=QWParentSSIhm(code,Eficas,version)
125
126     import readercata
127     if not hasattr ( Eficas, 'readercata'):
128            monreadercata  = readercata.READERCATA( parent, Eficas )
129            Eficas.readercata=monreadercata
130
131     from editor import JDCEditor
132     monEditeur=JDCEditor(Eficas,fichier)
133     texte=loadJDC(fichier)
134     parameters=getJdcParameters(texte,macro)
135     return parameters
136
137 def getJdcParameters(jdc,macro):
138     """
139     This function converts the data from the specified macro of the
140     specified jdc text to a python dictionnary whose keys are the
141     names of the data of the macro.
142     """
143     context = {}
144     source = "def args_to_dict(**kwargs): return kwargs \n"
145     source+= "%s = _F = args_to_dict          \n"%macro
146     source+= "parameters="+jdc+"                        \n"
147     source+= "context['parameters'] = parameters         \n"
148     code = compile(source, 'file.py', 'exec')
149     eval(code)
150     parameters = context['parameters']
151     return parameters
152
153 def loadJDC(filename):
154     """
155     This function loads the text from the specified JdC file. A JdC
156     file is the persistence file of Eficas (*.comm).
157     """
158     fcomm=open(filename,'r')
159     jdc = ""
160     for line in fcomm.readlines():
161         if not (line[0]=='#'):
162            jdc+="%s"%line
163
164     # Warning, we have to make sure that the jdc comes as a simple
165     # string without any extra spaces/newlines
166     return jdc.strip()
167
168 if __name__ == "__main__":
169     import sys
170     sys.path.insert(0,os.path.abspath(os.path.join(os.getcwd(),'..')))
171     lance_eficas(code=None,fichier=None,ssCode=None,multi=True)
172     
173