1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2008-2017 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 daUtils.qtversion import useQT5
27 from PyQt5.QtGui import *
28 from PyQt5.QtCore import *
29 from PyQt5.QtWidgets import QApplication
31 from PyQt4.QtGui import *
32 from PyQt4.QtCore import *
35 sgPyQt = SalomePyQt.SalomePyQt()
37 ################################################
39 # Used to store actions, menus, toolbars, etc...
40 ################################################
41 # A gui context instance is created for each study. The dictionnary __study2context__
42 # keeps the mapping in memory. This context contains graphical objects that have
43 # to be created for each study. It contains at least the ui component builder that
44 # creates the menu and toolbar items (must be created for every study)
46 from daGuiImpl import adaoGuiHelper
47 from daGuiImpl.adaoGuiManager import AdaoCaseManager
50 adaoCaseManager = None
52 self.adaoCaseManager = AdaoCaseManager()
54 __study2context__ = {}
55 __current_context__ = None
56 def _setContext( studyID ):
57 global __study2context__, __current_context__
58 QApplication.processEvents()
59 if not __study2context__.has_key(studyID):
60 __study2context__[studyID] = GUIcontext()
62 __current_context__ = __study2context__[studyID]
63 return __current_context__
65 # This object does not need to be embedded in a GUI context object. A single
66 # instance for all studies is a priori sufficient.
68 ################################################
69 # Implementation of SALOME GUI interface
70 ################################################
72 # called when module is initialized
73 # perform initialization actions
77 # called when module is initialized
78 # return map of popup windows to be used by the module
81 wm[SalomePyQt.WT_ObjectBrowser] = Qt.LeftDockWidgetArea
82 wm[SalomePyQt.WT_PyConsole] = Qt.BottomDockWidgetArea
85 # called when module is initialized
86 # return list of 2d/3d views to be used ny the module
91 def createPreferences():
93 Called when module is initialized. Export module's preferences.
97 # called when module is activated
98 # returns True if activating is successfull and False otherwise
100 ctx = _setContext( sgPyQt.getStudyId() )
101 ctx.adaoCaseManager.activate()
104 # called when module is deactivated
106 ctx = _setContext( sgPyQt.getStudyId() )
107 ctx.adaoCaseManager.deactivate()
109 # called when active study is changed
110 # active study ID is passed as parameter
111 def activeStudyChanged( studyID ):
112 ctx = _setContext( sgPyQt.getStudyId() )
114 # called when popup menu is invoked
115 # popup menu and menu context are passed as parameters
116 def createPopupMenu( popup, context ):
117 activeStudyId = sgPyQt.getStudyId()
118 ctx = _setContext(sgPyQt.getStudyId())
119 selcount, selected = adaoGuiHelper.getAllSelected(activeStudyId)
121 selectedItem = adaoGuiHelper.getSelectedItem(activeStudyId)
122 popup = ctx.adaoCaseManager.salome_manager.createPopupMenuOnItem(popup, activeStudyId, selectedItem)
124 def OnGUIEvent(actionId) :
126 Called when an event is raised from a graphic item (click on menu item or
127 toolbar button). The actionId value is the ID associated to the item.
129 ctx = _setContext( sgPyQt.getStudyId() )
130 ctx.adaoCaseManager.processGUIEvent(actionId)
132 # called when module's preferences are changed
133 # preference's resources section and setting name are passed as parameters
134 def preferenceChanged( section, setting ):
137 # called when active view is changed
138 # view ID is passed as parameter
139 def activeViewChanged( viewID ):
142 # called when active view is cloned
143 # cloned view ID is passed as parameter
144 def viewCloned( viewID ):
147 # called when active view is viewClosed
148 # view ID is passed as parameter
149 def viewClosed( viewID ):