]> SALOME platform Git repositories - modules/eficas.git/blob - src/EFICASGUI/EFICASGUI.py
Salome HOME
utilisation studyManager
[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    theParent = "ObjectBrowser"
119    a=salome.sg.getAllSelected()
120    if len(a) >0:
121        theObject="73"
122    return (theContext, theObject, theParent)
123
124
125 def customPopup(popup, theContext, theObject, theParent):
126    print "EFICASGUI --- customPopup"
127    popup.removeItem(99000)
128    popup.removeItem(99001)
129    popup.removeItem(99002)
130    popup.removeItem(99003)
131
132
133 # -----------------------------------------------------------------------------
134
135 import eficasSalome
136
137 def runEficas():
138    print "-------------------------EFICASGUI::runEficas-------------------------"
139    print currentStudyId      
140    #eficasSalome.runEficas("ASTER",studyId=currentStudyId)   
141    #ws = sgPyQt.getMainFrame()   
142    desktop=sgPyQt.getDesktop()   
143    eficasSalome.runEficas( desktop, studyManager.palStudy, "ASTER" )
144    
145
146 def runEficaspourHomard():
147    print "runEficas"
148    #eficasSalome.runEficas("HOMARD")
149    desktop=sgPyQt.getDesktop()
150    eficasSalome.runEficas( desktop, studyManager.palStudy, "HOMARD" ) 
151    
152    
153     
154 def runEficasHomard():
155    print "runEficas"
156    #eficasSalome.runEficas("HOMARD")
157    desktop=sgPyQt.getDesktop()
158    eficasSalome.runEficas( desktop, studyManager.palStudy, "HOMARD" )
159    
160    
161
162 def runEficasFichier():
163    """
164    Lancement d'eficas à partir d'un fichier sélectionné dans l'arbre
165    d'étude par clique droit de la souris. 
166    """
167    print "runEficasFichier"
168    fileName = None
169    code     = None
170    a=salome.sg.getAllSelected()
171    if len(a) == 1:
172       #studyManager.palStudy.setCurrentStudyID( currentStudyId )
173       #boo,attr=aGuiDS.getExternalFileAttribute("FICHIER_EFICAS_ASTER",a[0])
174       selectedEntry = a[0]
175       
176       aType, aValue = studyManager.palStudy.getTypeAndValue( selectedEntry )
177       if aType == studyManager.FICHIER_EFICAS_ASTER:
178         fileName = aValue
179         code     = "ASTER"
180       elif aType == studyManager.FICHIER_EFICAS_HOMARD:
181         fileName = aValue
182         code     = "HOMARD"        
183    if code:
184         #eficasSalome.runEficas(code,attr,studyId=currentStudyId)         
185         desktop=sgPyQt.getDesktop()
186         eficasSalome.runEficas( desktop, studyManager.palStudy, code, fileName )
187         
188    
189
190 # Partie applicative
191
192 dict_command={
193                 941:runEficas,                
194                 946:runEficaspourHomard,
195                 4041:runEficas,                
196                 4046:runEficaspourHomard,
197                 9042:runEficasFichier,
198              }
199              
200
201
202