Salome HOME
Minor source update for OM compatibility
[modules/adao.git] / src / daSalome / daGUI / daGuiImpl / ADAOGUI_impl.py
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2008-2024 EDF R&D
4 #
5 # This file is part of SALOME ADAO module
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License.
11 #
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20 #
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #
23
24 __author__="aribes/gboulant"
25
26 from PyQt5.QtGui import *
27 from PyQt5.QtCore import *
28 from PyQt5.QtWidgets import QApplication
29
30 import SalomePyQt
31 sgPyQt = SalomePyQt.SalomePyQt()
32
33 ################################################
34 # GUI context class
35 # Used to store actions, menus, toolbars, etc...
36 ################################################
37 # A gui context instance is created for each study. The dictionnary __study2context__
38 # keeps the mapping in memory. This context contains graphical objects that have
39 # to be created for each study. It contains at least the ui component builder that
40 # creates the menu and toolbar items (must be created for every study)
41
42 from daGuiImpl import adaoGuiHelper
43 from daGuiImpl.adaoGuiManager import AdaoCaseManager
44
45 class GUIcontext:
46     adaoCaseManager = None
47     def __init__(self):
48         self.adaoCaseManager = AdaoCaseManager()
49
50 #~ __study2context__   = {}
51 #~ __current_context__ = None
52 __current_context__ = GUIcontext()
53 #~ def _setContext( studyID ):
54     #~ global __study2context__, __current_context__
55     #~ QApplication.processEvents()
56     #~ if studyID not in __study2context__:
57         #~ __study2context__[studyID] = GUIcontext()
58         #~ pass
59     #~ __current_context__ = __study2context__[studyID]
60     #~ return __current_context__
61
62 # This object does not need to be embedded in a GUI context object. A single
63 # instance for all studies is a priori sufficient.
64
65 ################################################
66 # Implementation of SALOME GUI interface
67 ################################################
68
69 # called when module is initialized
70 # perform initialization actions
71 def initialize():
72     pass
73
74 # called when module is initialized
75 # return map of popup windows to be used by the module
76 def windows():
77     wm = {}
78     wm[SalomePyQt.WT_ObjectBrowser] = Qt.LeftDockWidgetArea
79     wm[SalomePyQt.WT_PyConsole]     = Qt.BottomDockWidgetArea
80     return wm
81
82 # called when module is initialized
83 # return list of 2d/3d views to be used ny the module
84 def views():
85   return []
86
87 def createPreferences():
88     """
89     Called when module is initialized. Export module's preferences.
90     """
91     pass
92
93 # called when module is activated
94 # returns True if activating is successfull and False otherwise
95 def activate():
96     #~ ctx = _setContext( sgPyQt.getStudyId() )
97     global __current_context__ ; ctx = __current_context__
98     QApplication.processEvents()
99     ctx.adaoCaseManager.activate()
100     return True
101
102 # called when module is deactivated
103 def deactivate():
104     #~ ctx = _setContext( sgPyQt.getStudyId() )
105     global __current_context__ ; ctx = __current_context__
106     QApplication.processEvents()
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     QApplication.processEvents()
114
115 # called when popup menu is invoked
116 # popup menu and menu context are passed as parameters
117 def createPopupMenu( popup, context ):
118   #~ activeStudyId = sgPyQt.getStudyId()
119   #~ ctx = _setContext(sgPyQt.getStudyId())
120   global __current_context__ ; ctx = __current_context__
121   QApplication.processEvents()
122   selcount, selected = adaoGuiHelper.getAllSelected()# activeStudyId)
123   if selcount == 1:
124     selectedItem = adaoGuiHelper.getSelectedItem()# activeStudyId)
125     popup = ctx.adaoCaseManager.salome_manager.createPopupMenuOnItem(popup, selectedItem) # activeStudyId, selectedItem)
126
127 def OnGUIEvent(actionId) :
128     """
129     Called when an event is raised from a graphic item (click on menu item or
130     toolbar button). The actionId value is the ID associated to the item.
131     """
132     #~ ctx = _setContext( sgPyQt.getStudyId() )
133     global __current_context__ ; ctx = __current_context__
134     QApplication.processEvents()
135     ctx.adaoCaseManager.processGUIEvent(actionId)
136
137 # called when module's preferences are changed
138 # preference's resources section and setting name are passed as parameters
139 def preferenceChanged( section, setting ):
140     pass
141
142 # called when active view is changed
143 # view ID is passed as parameter
144 def activeViewChanged( viewID ):
145     pass
146
147 # called when active view is cloned
148 # cloned view ID is passed as parameter
149 def viewCloned( viewID ):
150     pass
151
152 # called when active view is viewClosed
153 # view ID is passed as parameter
154 def viewClosed( viewID ):
155     pass
156