4 from omniORB import CORBA
5 from SALOME_NamingServicePy import *
6 from LifeCycleCORBA import *
8 import SALOMEDS_Attributes_idl
10 ################################################
12 __MODULE_NAME__ = "PYHELLO"
15 ################################################
17 # Get SALOME PyQt interface
19 sgPyQt=SalomePyQt.SalomePyQt()
21 # Get SALOME Swig interface
23 sg = libSALOME_Swig.SALOMEGUI_Swig()
25 ################################################
28 orb = CORBA.ORB_init( [''], CORBA.ORB_ID )
30 # create naming service instance
31 naming_service = SALOME_NamingServicePy_i( orb )
33 # create life cycle CORBA instance
34 lcc = LifeCycleCORBA( orb )
37 obj = naming_service.Resolve( '/myStudyManager' )
38 studyManager = obj._narrow( SALOMEDS.StudyManager )
40 ################################################
43 # --- get PYHELLO engine ---
46 engine = lcc.FindOrLoadComponent( "FactoryServerPy", __MODULE_NAME__ )
49 # --- get active study ---
51 studyId = sgPyQt.getStudyId()
52 study = studyManager.GetStudyByID( studyId )
55 # --- returns 1 if object has children ---
56 def _hasChildren( sobj ):
59 iter = study.NewChildIterator( sobj )
61 name = iter.Value().GetName()
67 # --- finds or creates component object ---
68 def _findOrCreateComponent():
70 father = study.FindComponent( __MODULE_NAME__ )
72 builder = study.NewBuilder()
73 father = builder.NewComponent( __MODULE_NAME__ )
74 attr = builder.FindOrCreateAttribute( father, "AttributeName" )
75 attr.SetValue( __MODULE_NAME__ )
76 attr = builder.FindOrCreateAttribute( father, "AttributeLocalID" )
77 attr.SetValue( __MODULE_ID__ )
79 ### The following line is commented because it causes crashes ! ###
80 ### builder.DefineComponentInstance( father, _getEngine() )
86 ################################################
89 # set workspace (obsolete method, not used)
90 def setWorkSpace( pyws ):
91 print "PYHELLOGUI::setWorkSpace : ", pyws
94 # called when module is activated
96 print "PYHELLOGUI::setSettings"
99 # called when active study is changed
100 def activeStudyChanged( studyID ):
101 print "PYHELLOGUI::activeStudyChanged: study ID =", studyID
105 def definePopup( context, object, parent ):
110 if sg.SelectedCount() == 1:
111 entry = sg.getSelected( 0 )
113 sobj = study.FindObjectID( entry )
115 test, anAttr = sobj.FindAttribute( "AttributeLocalID" )
117 id = anAttr._narrow( SALOMEDS.AttributeLocalID ).Value()
120 print "PYHELLOGUI::definePopup :", context, object, parent
121 return context, object, parent
123 # customize popup menu
124 def customPopup( popup, context, object, parent ):
125 print "PYHELLOGUI::customPopup :", context, object, parent
127 if id == __MODULE_ID__:
129 if sg.SelectedCount() == 1:
130 entry = sg.getSelected( 0 )
132 sobj = study.FindObjectID( entry )
133 if sobj and not _hasChildren( sobj ):
134 popup.removeItem( 951 ) # remove 'Delete All' command
138 def OnGUIEvent(commandID) :
139 print "PYHELLOGUI::OnGUIEvent : commandID =",commandID
140 if dict_command.has_key( commandID ):
142 dict_command[commandID]()
144 traceback.print_exc()
146 print "The command is not implemented: ",commandID
148 ################################################
149 # GUI actions implementation
151 # ----------------------- #
153 # ----------------------- #
154 class MyDialog( QDialog ):
156 def __init__( self, parent = None, modal = 0):
157 QDialog.__init__( self, parent, "MyDialog", modal )
158 self.setCaption( "HELLO!" )
159 vb = QVBoxLayout( self, 8 )
162 label = QLabel( "Prenom: ", hb0 )
163 self.entry = QLineEdit( hb0 )
164 self.entry.setMinimumWidth( 200 )
167 bOk = QPushButton( "&OK", hb1 )
168 self.connect( bOk, SIGNAL( 'clicked()' ), self, SLOT( 'accept()' ) )
169 dummy = QWidget( hb1 )
170 bCancel = QPushButton( "&Cancel", hb1 )
171 self.connect( bCancel, SIGNAL( 'clicked()' ), self, SLOT( 'close()' ) )
172 hb1.setStretchFactor( dummy, 10 )
177 name = str( self.entry.text() )
179 banner = _getEngine().makeBanner( name )
180 QMessageBox.information( self, 'Info', banner )
183 QMessageBox.warning( self, 'Error!', 'Please, enter the name!' )
186 # ----------------------- #
189 d = MyDialog( sgPyQt.getDesktop(), 1 )
195 # ----------------------- #
199 builder = study.NewBuilder()
200 father = _findOrCreateComponent()
201 object = builder.NewObject( father )
202 attr = builder.FindOrCreateAttribute( object, "AttributeName" )
204 attr.SetValue( "Object " + str( __id__ ) )
205 attr = builder.FindOrCreateAttribute( object, "AttributeLocalID" )
206 attr.SetValue( __OBJECT_ID__ )
207 sgPyQt.updateObjBrowser()
210 # ----------------------- #
213 father = study.FindComponent( __MODULE_NAME__ )
215 iter = study.NewChildIterator( father )
216 builder = study.NewBuilder()
220 builder.RemoveObjectWithChildren( sobj )
221 sgPyQt.updateObjBrowser()
224 # ----------------------- #
227 entry = sg.getSelected( 0 )
229 sobj = study.FindObjectID( entry )
231 test, attr = sobj.FindAttribute( "AttributeName" )
233 QMessageBox.information( sgPyQt.getDesktop(), 'Info', "My name is '%s'" % attr.Value() )
237 # ----------------------- #
240 entry = sg.getSelected( 0 )
242 sobj = study.FindObjectID( entry )
244 builder = study.NewBuilder()
245 builder.RemoveObject( sobj )
246 sgPyQt.updateObjBrowser()
249 # ----------------------- #