Salome HOME
nettoyage du code
[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 import salomedsgui
35 aGuiDS=salomedsgui.guiDS()
36 print "EFicasGUI :: :::::::::::::::::::::::::::::::::::::::::::::::::::::"
37
38
39
40 # -----------------------------------------------------------------------------
41 #Cette méthode est obsolète en V3
42 #En V2, si on n'implémente pas cette méthode, le composant fonctionne
43 #correctement. Un message "Attribute Error" apparait dans la trace.
44 def setWorkSpace(workSpace):
45    print "EficasGUI --- setWorkSpace"
46    global WORKSPACE
47    print workSpace
48    WORKSPACE=workSpace
49    print "WORKSPACE: ",WORKSPACE
50    # le desktop
51    desktop=sgPyQt.getDesktop()
52
53    # creation d'une message box
54    #qt.QMessageBox.information(d,"titre","message")
55
56    # recuperation du workspace
57    ws=sgPyQt.getMainFrame()
58    print ws
59
60 # -----------------------------------------------------------------------------
61
62 def OnGUIEvent(commandID) :
63    print "EficasGUI :: OnGUIEvent :::::::::::::::::::::::::::::::::commandID = ",commandID
64    if dict_command.has_key(commandID):
65       print "OnGUIEvent ::::::::::  commande associée  : ",commandID      
66       dict_command[commandID]()
67    else:
68       print "Pas de commande associée a : ",commandID
69
70 # -----------------------------------------------------------------------------
71
72 def setSettings():
73    """
74    Cette méthode permet les initialisations. On définit en particulier
75    l'identifiant de l'étude courante.
76    """
77    # le desktop
78    desktop=sgPyQt.getDesktop()
79    global currentStudyId
80    currentStudyId = sgPyQt.getStudyId()
81    print "setSettings: currentStudyId = " + str(currentStudyId)
82    # _CS_gbo_ Voir si on peut utiliser directement sgPyQt.getStudyId()
83    # dans salomedsgui?
84    
85    palStudyManager.setCurrentStudyID( currentStudyId ) #CS_pbruno   
86
87 def activate():
88    """
89    Cette méthode permet l'activation du module, s'il a été chargé mais pas encore
90    activé dans une étude précédente.
91    
92    Portage V3.
93    """
94    print "--------EFICASGUI:: activate"
95    setSettings()
96
97
98 # -----------------------------------------------------------------------------
99
100 def activeStudyChanged(ID):
101    # le desktop
102    desktop=sgPyQt.getDesktop()
103    global currentStudyId
104    # ne marche pas car sg est supposé résider dans une etude
105    # studyId=sg.getActiveStudyId()
106    currentStudyId=ID
107    print "_CS_GBO_ : EFICASGUI.activeStudyChanged : currentStudyId = ", currentStudyId
108    print "_CS_GBO_ : EFICASGUI.activeStudyChanged : sgPyQt.getStudyId() = ", sgPyQt.getStudyId()
109    
110    palStudyManager.setCurrentStudyID( currentStudyId ) #CS_pbruno
111    
112
113 def definePopup(theContext, theObject, theParent):
114    print "EFICASGUI --- definePopup"
115    theContext = ""
116    theParent = "ObjectBrowser"
117    a=salome.sg.getAllSelected()
118    if len(a) >0:
119        theObject="73"
120    return (theContext, theObject, theParent)
121
122
123 def customPopup(popup, theContext, theObject, theParent):
124    print "EFICASGUI --- customPopup"
125    popup.removeItem(99000)
126    popup.removeItem(99001)
127    popup.removeItem(99002)
128    popup.removeItem(99003)
129
130
131 # -----------------------------------------------------------------------------
132
133 import eficasSalome
134
135 def runEficas():
136    print "-------------------------EFICASGUI::runEficas-------------------------"
137    print currentStudyId      
138    #eficasSalome.runEficas("ASTER",studyId=currentStudyId)   
139    #ws = sgPyQt.getMainFrame()   
140    desktop=sgPyQt.getDesktop()   
141    eficasSalome.runEficas( desktop, palStudyManager, "ASTER" )
142    
143
144 def runEficaspourHomard():
145    print "runEficas"
146    #eficasSalome.runEficas("HOMARD")
147    desktop=sgPyQt.getDesktop()
148    eficasSalome.runEficas( desktop, palStudyManager, "HOMARD" ) 
149    
150    
151     
152 def runEficasHomard():
153    print "runEficas"
154    #eficasSalome.runEficas("HOMARD")
155    desktop=sgPyQt.getDesktop()
156    eficasSalome.runEficas( desktop, palStudyManager, "HOMARD" )
157    
158    
159
160 def runEficasFichier():
161    """
162    Lancement d'eficas à partir d'un fichier sélectionné dans l'arbre
163    d'étude. 
164    """
165    print "runEficasFichier"
166    attr=None
167    code=None
168    a=salome.sg.getAllSelected()
169    if len(a) == 1:
170       aGuiDS.setCurrentStudy(currentStudyId)
171       boo,attr=aGuiDS.getExternalFileAttribute("FICHIER_EFICAS_ASTER",a[0])
172       if boo :
173          code = "ASTER" 
174       else :
175          boo,attr=aGuiDS.getExternalFileAttribute("FICHIER_EFICAS_HOMARD",a[0])         
176          if boo:
177             code = "HOMARD"
178    if code:
179         #eficasSalome.runEficas(code,attr,studyId=currentStudyId)         
180         desktop=sgPyQt.getDesktop()   
181         eficasSalome.runEficas( desktop, palStudyManager, code, attr )
182    
183
184 # Partie applicative
185
186 dict_command={
187                 941:runEficas,                
188                 946:runEficaspourHomard,
189                 4041:runEficas,                
190                 4046:runEficaspourHomard,
191                 9042:runEficasFichier,
192              }
193              
194 #CS_pbruno temporaire
195 import studyManager #from PAL
196 palStudyManager = studyManager.SalomeStudy()