Salome HOME
Correction for Qt5/Eficas/Adao/Salome embedded frames compatibility
[modules/adao.git] / src / daSalome / daGUI / daGuiImpl / ADAOGUI_impl.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2008-2016 EDF R&D
3 #
4 # This file is part of SALOME ADAO module
5 #
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.
10 #
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.
15 #
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
19 #
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22
23 __author__="aribes/gboulant"
24
25 from daUtils.qtversion import useQT5
26 if useQT5:
27     from PyQt5.QtGui import *
28     from PyQt5.QtCore import *
29     from PyQt5.QtWidgets import QApplication
30 else:
31     from PyQt4.QtGui import *
32     from PyQt4.QtCore import *
33
34 import SalomePyQt
35 sgPyQt = SalomePyQt.SalomePyQt()
36
37 ################################################
38 # GUI context class
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)
45
46 from daGuiImpl import adaoGuiHelper
47 from daGuiImpl.adaoGuiManager import AdaoCaseManager
48
49 class GUIcontext:
50     adaoCaseManager = None
51     def __init__(self):
52         self.adaoCaseManager = AdaoCaseManager()
53
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()
61         pass
62     __current_context__ = __study2context__[studyID]
63     return __current_context__
64
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.
67
68 ################################################
69 # Implementation of SALOME GUI interface
70 ################################################
71
72 # called when module is initialized
73 # perform initialization actions
74 def initialize():
75     pass
76
77 # called when module is initialized
78 # return map of popup windows to be used by the module
79 def windows():
80     wm = {}
81     wm[SalomePyQt.WT_ObjectBrowser] = Qt.LeftDockWidgetArea
82     wm[SalomePyQt.WT_PyConsole]     = Qt.BottomDockWidgetArea
83     return wm
84
85 # called when module is initialized
86 # return list of 2d/3d views to be used ny the module
87 def views():
88   print "views"
89   return []
90
91 def createPreferences():
92     """
93     Called when module is initialized. Export module's preferences.
94     """
95     pass
96
97 # called when module is activated
98 # returns True if activating is successfull and False otherwise
99 def activate():
100     ctx = _setContext( sgPyQt.getStudyId() )
101     ctx.adaoCaseManager.activate()
102     return True
103
104 # called when module is deactivated
105 def deactivate():
106     ctx = _setContext( sgPyQt.getStudyId() )
107     ctx.adaoCaseManager.deactivate()
108
109 # called when active study is changed
110 # active study ID is passed as parameter
111 def activeStudyChanged( studyID ):
112     ctx = _setContext( sgPyQt.getStudyId() )
113
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)
120   if selcount == 1:
121     selectedItem = adaoGuiHelper.getSelectedItem(activeStudyId)
122     popup = ctx.adaoCaseManager.salome_manager.createPopupMenuOnItem(popup, activeStudyId, selectedItem)
123
124 def OnGUIEvent(actionId) :
125     """
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.
128     """
129     ctx = _setContext( sgPyQt.getStudyId() )
130     ctx.adaoCaseManager.processGUIEvent(actionId)
131
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 ):
135     pass
136
137 # called when active view is changed
138 # view ID is passed as parameter
139 def activeViewChanged( viewID ):
140     pass
141
142 # called when active view is cloned
143 # cloned view ID is passed as parameter
144 def viewCloned( viewID ):
145     pass
146
147 # called when active view is viewClosed
148 # view ID is passed as parameter
149 def viewClosed( viewID ):
150     pass
151