Salome HOME
Résolution du bug roundup n°32 (multi-études)
[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
13 # -----------------------------------------------------------------------------
14
15 import notifqt
16 #import Tkinter
17 #root.withdraw()
18
19 def g():
20    print "lastWindowClosed()"
21    import Tkinter
22    root=Tkinter.Tk()
23    root.destroy()
24
25 qt.QObject.connect(qt.qApp,qt.SIGNAL("lastWindowClosed()"),g)
26
27 # -----------------------------------------------------------------------------
28
29 import salome
30
31 sg=salome.SalomeGUI()
32 sgPyQt=SalomePyQt.SalomePyQt()
33 import salomedsgui
34 aGuiDS=salomedsgui.guiDS()
35 print "EFicasGUI :: :::::::::::::::::::::::::::::::::::::::::::::::::::::"
36
37 # -----------------------------------------------------------------------------
38
39 def setWorkSpace(workSpace):
40    print "EficasGUI --- setWorkSpace"
41    global WORKSPACE
42    print workSpace
43    WORKSPACE=workSpace
44    print "WORKSPACE: ",WORKSPACE
45    # le desktop
46    d=sgPyQt.getDesktop()
47
48    # creation d'une message box
49    #qt.QMessageBox.information(d,"titre","message")
50
51    # recuperation du workspace
52    ws=sgPyQt.getMainFrame()
53    print ws
54
55 # -----------------------------------------------------------------------------
56
57 def OnGUIEvent(commandID) :
58    print "EficasGUI :: OnGUIEvent :::::::::::::::::::::::::::::::::commandID,WORKSPACE = ",commandID,WORKSPACE
59    if dict_command.has_key(commandID):
60       print "OnGUIEvent ::::::::::  commande associée  : ",commandID      
61       dict_command[commandID](WORKSPACE)
62    else:
63       print "Pas de commande associée a : ",commandID
64
65 # -----------------------------------------------------------------------------
66
67 def setSettings():
68    """
69    Cette méthode permet les initialisations. On définit en particulier
70    l'identifiant de l'étude courante.
71    """
72    global currentStudyId
73    currentStudyId = sgPyQt.getStudyId()
74    print "setSettings: currentStudyId = " + str(currentStudyId)
75    # _CS_gbo_ Voir si on peut utiliser directement sgPyQt.getStudyId()
76    # dans salomedsgui?
77
78
79 # -----------------------------------------------------------------------------
80
81 def activeStudyChanged(ID):
82    global currentStudyId
83    # ne marche pas car sg est supposé résider dans une etude
84    # studyId=sg.getActiveStudyId()
85    currentStudyId=ID
86    print "_CS_GBO_ : EFICASGUI.activeStudyChanged : currentStudyId = ", currentStudyId
87    print "_CS_GBO_ : EFICASGUI.activeStudyChanged : sgPyQt.getStudyId() = ", sgPyQt.getStudyId()
88
89 def definePopup(theContext, theObject, theParent):
90    print "EFICASGUI --- definePopup"
91    theContext = ""
92    theParent = "ObjectBrowser"
93    a=salome.sg.getAllSelected()
94    if len(a) >0:
95        theObject="73"
96    return (theContext, theObject, theParent)
97
98
99 def customPopup(popup, theContext, theObject, theParent):
100    print "EFICASGUI --- customPopup"
101    popup.removeItem(99000)
102    popup.removeItem(99001)
103    popup.removeItem(99002)
104    popup.removeItem(99003)
105
106
107 # -----------------------------------------------------------------------------
108
109 import eficasSalome
110
111 def runEficas(ws):
112    eficasSalome.runEficas(ws,"ASTER",studyId=currentStudyId)
113    
114 def runEficaspourHomard(ws):
115    print "runEficas"
116    eficasSalome.runEficas(ws,"HOMARD")
117     
118 def runEficasHomard(ws):
119    print "runEficas"
120    eficasSalome.runEficas(None,"HOMARD")
121
122 def runEficasFichier(ws):
123    """
124    Lancement d'eficas à partir d'un fichier sélectionné dans l'arbre
125    d'étude. 
126    """
127    print "runEficasFichier"
128    attr=None
129    code="ASTER"
130    a=salome.sg.getAllSelected()
131    if len(a) == 1:
132       aGuiDS.setCurrentStudy(currentStudyId)
133       boo,attr=aGuiDS.getExternalFileAttribute("FICHIER_EFICAS_ASTER",a[0])
134       if boo :
135          code = "ASTER" 
136       else :
137          boo,attr=aGuiDS.getExternalFileAttribute("FICHIER_EFICAS_HOMARD",a[0])
138          code = "HOMARD"
139    
140    eficasSalome.runEficas(ws,code,attr,studyId=currentStudyId)
141
142 # Partie applicative
143
144 dict_command={
145                941:runEficas,
146                946:runEficaspourHomard,
147                4041:runEficas,
148                4046:runEficaspourHomard,
149                9042:runEficasFichier,
150              }
151