]> SALOME platform Git repositories - modules/adao.git/blob - src/daSalome/daGUI/daGuiImpl/ADAOGUI_impl.py
Salome HOME
90f91416674e3200fd135ed833615252302d31f8
[modules/adao.git] / src / daSalome / daGUI / daGuiImpl / ADAOGUI_impl.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2008-2015 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 PyQt4.QtGui import *
26 from PyQt4.QtCore import *
27
28 import SalomePyQt
29 sgPyQt = SalomePyQt.SalomePyQt()
30
31 ################################################
32 # GUI context class
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)
39
40 from daGuiImpl import adaoGuiHelper
41 from daGuiImpl.adaoGuiManager import AdaoCaseManager
42
43 class GUIcontext:
44     adaoCaseManager = None
45     def __init__(self):
46         self.adaoCaseManager = AdaoCaseManager()
47
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()
54         pass
55     __current_context__ = __study2context__[studyID]
56     return __current_context__
57
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.
60
61 ################################################
62 # Implementation of SALOME GUI interface
63 ################################################
64
65 # called when module is initialized
66 # perform initialization actions
67 def initialize():
68     pass
69
70 # called when module is initialized
71 # return map of popup windows to be used by the module
72 def windows():
73     wm = {}
74     wm[SalomePyQt.WT_ObjectBrowser] = Qt.LeftDockWidgetArea
75     wm[SalomePyQt.WT_PyConsole]     = Qt.BottomDockWidgetArea
76     return wm
77
78 # called when module is initialized
79 # return list of 2d/3d views to be used ny the module
80 def views():
81   print "views"
82   return []
83
84 def createPreferences():
85     """
86     Called when module is initialized. Export module's preferences.
87     """
88     pass
89
90 # called when module is activated
91 # returns True if activating is successfull and False otherwise
92 def activate():
93     ctx = _setContext( sgPyQt.getStudyId() )
94     ctx.adaoCaseManager.activate()
95     return True
96
97 # called when module is deactivated
98 def deactivate():
99     ctx = _setContext( sgPyQt.getStudyId() )
100     ctx.adaoCaseManager.deactivate()
101     pass
102
103 # called when active study is changed
104 # active study ID is passed as parameter
105 def activeStudyChanged( studyID ):
106     ctx = _setContext( sgPyQt.getStudyId() )
107     pass
108
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)
115   if selcount == 1:
116     selectedItem = adaoGuiHelper.getSelectedItem(activeStudyId)
117     popup = ctx.adaoCaseManager.salome_manager.createPopupMenuOnItem(popup, activeStudyId, selectedItem)
118
119 def OnGUIEvent(actionId) :
120     """
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.
123     """
124     pass
125     ctx = _setContext( sgPyQt.getStudyId() )
126     ctx.adaoCaseManager.processGUIEvent(actionId)
127
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 ):
131     pass
132
133 # called when active view is changed
134 # view ID is passed as parameter
135 def activeViewChanged( viewID ):
136   pass
137
138 # called when active view is cloned
139 # cloned view ID is passed as parameter
140 def viewCloned( viewID ):
141     pass
142
143 # called when active view is viewClosed
144 # view ID is passed as parameter
145 def viewClosed( viewID ):
146     pass
147