Salome HOME
627b79ebc330af305682c2894c96eb889a569a36
[modules/eficas.git] / src / EFICASGUI / EFICASGUI.py
1 """
2     Interface PyQt
3 """
4 import qt
5 import libSALOME_Swig
6 import SalomePyQt
7
8 # Variable globale pour stocker le Workspace de Salome
9
10 WORKSPACE=None
11 currentStudyId=None
12 desktop=None
13
14 # -----------------------------------------------------------------------------
15
16 import notifqt
17 #import Tkinter
18 #root.withdraw()
19
20 def g():
21    print "lastWindowClosed()"
22    import Tkinter
23    root=Tkinter.Tk()
24    root.destroy()
25
26 qt.QObject.connect(qt.qApp,qt.SIGNAL("lastWindowClosed()"),g)
27
28 # -----------------------------------------------------------------------------
29
30 import salome
31
32 sg=salome.sg
33 sgPyQt=SalomePyQt.SalomePyQt()
34
35
36 import studyManager
37
38 print "EFicasGUI :: :::::::::::::::::::::::::::::::::::::::::::::::::::::"
39
40
41
42 # -----------------------------------------------------------------------------
43 #Cette méthode est obsolète en V3
44 #En V2, si on n'implémente pas cette méthode, le composant fonctionne
45 #correctement. Un message "Attribute Error" apparait dans la trace.
46 def setWorkSpace(workSpace):
47    print "EficasGUI --- setWorkSpace"
48    global WORKSPACE
49    print workSpace
50    WORKSPACE=workSpace
51    print "WORKSPACE: ",WORKSPACE
52    # le desktop
53    desktop=sgPyQt.getDesktop()
54
55    # creation d'une message box
56    #qt.QMessageBox.information(d,"titre","message")
57
58    # recuperation du workspace
59    ws=sgPyQt.getMainFrame()
60    print ws
61
62 # -----------------------------------------------------------------------------
63
64 def OnGUIEvent(commandID) :
65    print "EficasGUI :: OnGUIEvent :::::::::::::::::::::::::::::::::commandID = ",commandID
66    if dict_command.has_key(commandID):
67       print "OnGUIEvent ::::::::::  commande associée  : ",commandID      
68       dict_command[commandID]()
69    else:
70       print "Pas de commande associée a : ",commandID
71
72 # -----------------------------------------------------------------------------
73
74 def setSettings():
75    """
76    Cette méthode permet les initialisations. On définit en particulier
77    l'identifiant de l'étude courante.
78    """
79    # le desktop
80    desktop=sgPyQt.getDesktop()
81    global currentStudyId
82    currentStudyId = sgPyQt.getStudyId()
83    print "setSettings: currentStudyId = " + str(currentStudyId)
84    # _CS_gbo_ Voir si on peut utiliser directement sgPyQt.getStudyId()
85    # dans salomedsgui?
86    
87    studyManager.palStudy.setCurrentStudyID( currentStudyId ) #CS_pbruno   
88
89 def activate():
90    """
91    Cette méthode permet l'activation du module, s'il a été chargé mais pas encore
92    activé dans une étude précédente.
93    
94    Portage V3.
95    """
96    print "--------EFICASGUI:: activate"
97    setSettings()
98
99
100 # -----------------------------------------------------------------------------
101
102 def activeStudyChanged(ID):
103    # le desktop
104    desktop=sgPyQt.getDesktop()
105    global currentStudyId
106    # ne marche pas car sg est supposé résider dans une etude
107    # studyId=sg.getActiveStudyId()
108    currentStudyId=ID
109    print "_CS_GBO_ : EFICASGUI.activeStudyChanged : currentStudyId = ", currentStudyId
110    print "_CS_GBO_ : EFICASGUI.activeStudyChanged : sgPyQt.getStudyId() = ", sgPyQt.getStudyId()
111    
112    studyManager.palStudy.setCurrentStudyID( currentStudyId ) #CS_pbruno
113    
114
115 def definePopup(theContext, theObject, theParent):    
116    print "EFICASGUI --- definePopup"
117    theContext= ""
118    theObject = "100"
119    theParent = "ObjectBrowser"
120    a=salome.sg.getAllSelected()
121    print a
122     
123    selectedEntry = a[0]
124    aType, aValue = studyManager.palStudy.getTypeAndValue( selectedEntry )
125    
126    if aType == studyManager.FICHIER_EFICAS_ASTER or aType == studyManager.FICHIER_EFICAS_HOMARD:
127         theObject="73"    
128             
129    return (theContext, theObject, theParent)
130
131
132 def customPopup(popup, theContext, theObject, theParent):
133    print "EFICASGUI --- customPopup"
134    popup.removeItem(99000)
135    popup.removeItem(99001)
136    popup.removeItem(99002)
137    popup.removeItem(99003)
138
139
140 # -----------------------------------------------------------------------------
141
142 import eficasSalome
143
144 def runEficas():
145    print "-------------------------EFICASGUI::runEficas-------------------------"
146    print currentStudyId      
147    #eficasSalome.runEficas("ASTER",studyId=currentStudyId)   
148    #ws = sgPyQt.getMainFrame()   
149    #desktop=sgPyQt.getDesktop()   
150    eficasSalome.runEficas( "ASTER" )
151    
152
153 def runEficaspourHomard():
154    print "runEficas"
155    #eficasSalome.runEficas("HOMARD")
156    desktop=sgPyQt.getDesktop()
157    eficasSalome.runEficas( "HOMARD" ) 
158    
159    
160     
161 def runEficasHomard():
162    print "runEficas"
163    #eficasSalome.runEficas("HOMARD")
164    #desktop=sgPyQt.getDesktop()
165    eficasSalome.runEficas( "HOMARD" )
166    
167    
168
169 def runEficasFichier():
170    """
171    Lancement d'eficas pour ASTER
172    si un fichier est sélectionné, il est ouvert dans eficas
173    """
174    print "runEficasFichier"
175    fileName = None
176    code     = None
177    a=salome.sg.getAllSelected()
178    if len(a) == 1:
179       #studyManager.palStudy.setCurrentStudyID( currentStudyId )
180       #boo,attr=aGuiDS.getExternalFileAttribute("FICHIER_EFICAS_ASTER",a[0])      
181       selectedEntry = a[0]
182       
183       aType, aValue = studyManager.palStudy.getTypeAndValue( selectedEntry )
184       if aType == studyManager.FICHIER_EFICAS_ASTER:        
185         fileName = aValue
186         code     = "ASTER"
187       elif aType == studyManager.FICHIER_EFICAS_HOMARD:        
188         fileName = aValue
189         code     = "HOMARD"
190    else:        
191         code = "ASTER"            
192         
193    if code:
194         #eficasSalome.runEficas(code,attr,studyId=currentStudyId)         
195         #desktop=sgPyQt.getDesktop()        
196         eficasSalome.runEficas( code, fileName )
197         
198
199    
200
201 # Partie applicative
202
203 dict_command={
204                 941:runEficasFichier,# runEficas,
205                 946:runEficaspourHomard,
206                 4041:runEficasFichier, #runEficas,
207                 4046:runEficaspourHomard,
208                 9042:runEficasFichier,
209              }
210              
211
212
213