1 # Copyright (C) 2015-2016 CEA/DEN, EDF R&D
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 dataManager = medcalc.medcorba.factory.getDataManager()
26 # Initializing the notification system (events from components to GUI)
28 # The MEDEventListener is created in the GUI (WorkspaceController) and
29 # a reference is transmitted to the python context throw its IOR. The
30 # transmission consists in initializing the variable below from the
31 # GUI (who knows the IOR) when importing medcalc in the python console
32 # (see WorkspaceController)
33 __eventListener = None
34 def connectEventListener():
35 global __eventListener
37 eventListenerIOR = dataManager.getEventListenerIOR()
38 __eventListener = salome.orb.string_to_object(eventListenerIOR)
39 except SALOME.SALOME_Exception, e:
40 medcalc.wrn("The event listener is not running yet")
41 msg ="When you'll have loaded the MED GUI, "
42 msg+="call explicitely \"medcalc.medevents.connectEventListener()\" "
43 msg+="to connect the GUI event listener"
45 __eventListener = None
47 medcalc.err("An unknown error occurs. Check if this ior=%s is valid."%eventListenerIOR)
51 def eventListenerIsRunning():
52 global __eventListener
53 if __eventListener is not None:
56 # Try to define the event listener
57 connectEventListener()
58 if __eventListener is None:
59 # it definitly does not work
60 medcalc.wrn("the GUI is not loaded yet and will not be notified of the modification")
66 def processMedEvent(event):
67 __eventListener.processMedEvent(event)
70 # One can try to connect to the eventListener, but it will fail if the
71 # MED GUI is not loaded. That does not matter, because the event
72 # listener is used only to notify the GUI of some event. If the GUI is
73 # not loaded, there is no use of notification.
74 connectEventListener()
78 # ===================================================================
79 # Functions for events notification
80 # ===================================================================
82 # Note that these functions are not part of the class FieldProxy so
83 # that they could be used in another context than the FieldProxy instances
86 def __notifyGui(eventType, dataId=-1, filename="", presentationId=-1):
87 medEvent = MEDCALC.MedEvent(eventType, dataId, filename, presentationId)
88 if not eventListenerIsRunning(): return
90 # Notify the GUI of the update event
91 processMedEvent(medEvent)
94 def notifyGui_updateField(fieldId):
96 This function must be used to notify the GUI that the field
97 meta-data have changed so it could update the gui
98 presentations of this field.
100 __notifyGui(MEDCALC.EVENT_UPDATE_FIELD, dataId=fieldId)
103 def notifyGui_putInWorkspace(fieldId):
104 __notifyGui(MEDCALC.EVENT_PUT_IN_WORKSPACE, dataId=fieldId)
106 def notifyGui_removeFromWorkspace(fieldId):
107 __notifyGui(MEDCALC.EVENT_REMOVE_FROM_WORKSPACE, dataId=fieldId)
109 def notifyGui_cleanWorkspace():
110 __notifyGui(MEDCALC.EVENT_CLEAN_WORKSPACE)
112 def notifyGui_addDatasource(filename):
113 __notifyGui(MEDCALC.EVENT_ADD_DATASOURCE, filename=filename)
115 def notifyGui_addPresentation(fieldId, presId):
116 __notifyGui(MEDCALC.EVENT_ADD_PRESENTATION, dataId=fieldId, presentationId=presId)
118 def notifyGui_playQtTestingScenario(filename):
119 __notifyGui(MEDCALC.EVENT_PLAY_TEST, filename=filename)