1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2010 EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 __author__="aribes/gboulant"
23 from PyQt4.QtGui import *
24 from PyQt4.QtCore import *
27 sgPyQt = SalomePyQt.SalomePyQt()
29 ################################################
31 # Used to store actions, menus, toolbars, etc...
32 ################################################
33 # A gui context instance is created for each study. The dictionnary __study2context__
34 # keeps the mapping in memory. This context contains graphical objects that have
35 # to be created for each study. It contains at least the ui component builder that
36 # creates the menu and toolbar items (must be created for every study)
38 from daGuiImpl import adaoGuiHelper
39 from daGuiImpl.adaoGuiManager import AdaoCaseManager
42 adaoCaseManager = None
44 self.adaoCaseManager = AdaoCaseManager()
46 __study2context__ = {}
47 __current_context__ = None
48 def _setContext( studyID ):
49 global __study2context__, __current_context__
50 if not __study2context__.has_key(studyID):
51 __study2context__[studyID] = GUIcontext()
53 __current_context__ = __study2context__[studyID]
54 return __current_context__
56 # This object does not need to be embedded in a GUI context object. A single
57 # instance for all studies is a priori sufficient.
59 ################################################
60 # Implementation of SALOME GUI interface
61 ################################################
63 # called when module is initialized
64 # perform initialization actions
68 # called when module is initialized
69 # return map of popup windows to be used by the module
72 wm[SalomePyQt.WT_ObjectBrowser] = Qt.LeftDockWidgetArea
73 wm[SalomePyQt.WT_PyConsole] = Qt.BottomDockWidgetArea
76 # called when module is initialized
77 # return list of 2d/3d views to be used ny the module
82 def createPreferences():
84 Called when module is initialized. Export module's preferences.
88 # called when module is activated
89 # returns True if activating is successfull and False otherwise
91 ctx = _setContext( sgPyQt.getStudyId() )
92 ctx.adaoCaseManager.activate()
95 # called when module is deactivated
97 ctx = _setContext( sgPyQt.getStudyId() )
98 ctx.adaoCaseManager.deactivate()
101 # called when active study is changed
102 # active study ID is passed as parameter
103 def activeStudyChanged( studyID ):
104 ctx = _setContext( sgPyQt.getStudyId() )
107 # called when popup menu is invoked
108 # popup menu and menu context are passed as parameters
109 def createPopupMenu( popup, context ):
110 activeStudyId = sgPyQt.getStudyId()
111 ctx = _setContext(sgPyQt.getStudyId())
112 selcount, selected = adaoGuiHelper.getAllSelected(activeStudyId)
114 selectedItem = adaoGuiHelper.getSelectedItem(activeStudyId)
115 popup = ctx.adaoCaseManager.salome_manager.createPopupMenuOnItem(popup, activeStudyId, selectedItem)
117 def OnGUIEvent(actionId) :
119 Called when an event is raised from a graphic item (click on menu item or
120 toolbar button). The actionId value is the ID associated to the item.
123 ctx = _setContext( sgPyQt.getStudyId() )
124 ctx.adaoCaseManager.processGUIEvent(actionId)
126 # called when module's preferences are changed
127 # preference's resources section and setting name are passed as parameters
128 def preferenceChanged( section, setting ):
131 # called when active view is changed
132 # view ID is passed as parameter
133 def activeViewChanged( viewID ):
134 print "activeViewChanged", viewID
137 # called when active view is cloned
138 # cloned view ID is passed as parameter
139 def viewCloned( viewID ):
142 # called when active view is viewClosed
143 # view ID is passed as parameter
144 def viewClosed( viewID ):