1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2008-2015 EDF R&D
4 # This file is part of SALOME ADAO module
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 __author__="aribes/gboulant"
25 from PyQt4.QtGui import *
26 from PyQt4.QtCore import *
29 sgPyQt = SalomePyQt.SalomePyQt()
31 ################################################
33 # Used to store actions, menus, toolbars, etc...
34 ################################################
35 # A gui context instance is created for each study. The dictionnary __study2context__
36 # keeps the mapping in memory. This context contains graphical objects that have
37 # to be created for each study. It contains at least the ui component builder that
38 # creates the menu and toolbar items (must be created for every study)
40 from daGuiImpl import adaoGuiHelper
41 from daGuiImpl.adaoGuiManager import AdaoCaseManager
44 adaoCaseManager = None
46 self.adaoCaseManager = AdaoCaseManager()
48 __study2context__ = {}
49 __current_context__ = None
50 def _setContext( studyID ):
51 global __study2context__, __current_context__
52 if not __study2context__.has_key(studyID):
53 __study2context__[studyID] = GUIcontext()
55 __current_context__ = __study2context__[studyID]
56 return __current_context__
58 # This object does not need to be embedded in a GUI context object. A single
59 # instance for all studies is a priori sufficient.
61 ################################################
62 # Implementation of SALOME GUI interface
63 ################################################
65 # called when module is initialized
66 # perform initialization actions
70 # called when module is initialized
71 # return map of popup windows to be used by the module
74 wm[SalomePyQt.WT_ObjectBrowser] = Qt.LeftDockWidgetArea
75 wm[SalomePyQt.WT_PyConsole] = Qt.BottomDockWidgetArea
78 # called when module is initialized
79 # return list of 2d/3d views to be used ny the module
84 def createPreferences():
86 Called when module is initialized. Export module's preferences.
90 # called when module is activated
91 # returns True if activating is successfull and False otherwise
93 ctx = _setContext( sgPyQt.getStudyId() )
94 ctx.adaoCaseManager.activate()
97 # called when module is deactivated
99 ctx = _setContext( sgPyQt.getStudyId() )
100 ctx.adaoCaseManager.deactivate()
103 # called when active study is changed
104 # active study ID is passed as parameter
105 def activeStudyChanged( studyID ):
106 ctx = _setContext( sgPyQt.getStudyId() )
109 # called when popup menu is invoked
110 # popup menu and menu context are passed as parameters
111 def createPopupMenu( popup, context ):
112 activeStudyId = sgPyQt.getStudyId()
113 ctx = _setContext(sgPyQt.getStudyId())
114 selcount, selected = adaoGuiHelper.getAllSelected(activeStudyId)
116 selectedItem = adaoGuiHelper.getSelectedItem(activeStudyId)
117 popup = ctx.adaoCaseManager.salome_manager.createPopupMenuOnItem(popup, activeStudyId, selectedItem)
119 def OnGUIEvent(actionId) :
121 Called when an event is raised from a graphic item (click on menu item or
122 toolbar button). The actionId value is the ID associated to the item.
125 ctx = _setContext( sgPyQt.getStudyId() )
126 ctx.adaoCaseManager.processGUIEvent(actionId)
128 # called when module's preferences are changed
129 # preference's resources section and setting name are passed as parameters
130 def preferenceChanged( section, setting ):
133 # called when active view is changed
134 # view ID is passed as parameter
135 def activeViewChanged( viewID ):
138 # called when active view is cloned
139 # cloned view ID is passed as parameter
140 def viewCloned( viewID ):
143 # called when active view is viewClosed
144 # view ID is passed as parameter
145 def viewClosed( viewID ):