1 //=============================================================================
2 // File : SalomePyQt.cxx
4 // Author : Vadim SANDLER
6 // Copyright : 2003-2005 CEA/DEN, EDF R&D
8 //=============================================================================
10 #include "SALOME_PYQT_Module.h" // this include must be first!!!
11 #include "SalomePyQt.h"
13 #include <qapplication.h>
16 #include <qpopupmenu.h>
18 #include <qstringlist.h>
20 #include "SALOME_Event.hxx"
22 #include "SUIT_Session.h"
23 #include "SUIT_Desktop.h"
24 #include "SUIT_ResourceMgr.h"
25 #include "SUIT_Tools.h"
26 #include "STD_MDIDesktop.h"
27 #include "SalomeApp_Application.h"
28 #include "SalomeApp_Study.h"
29 #include "SalomeApp_SelectionMgr.h"
30 #include "OB_Browser.h"
34 //====================================================================================
36 //====================================================================================
39 Returns active application object [ static ]
41 static SalomeApp_Application* getApplication() {
42 if ( SUIT_Session::session() )
43 return dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
49 Gets active study or 0 if there is no study opened [ static ]
51 static SalomeApp_Study* getActiveStudy()
53 if ( getApplication() )
54 return dynamic_cast<SalomeApp_Study*>( getApplication()->activeStudy() );
58 //====================================================================================
59 // SALOME_Selection class.
60 //====================================================================================
62 SALOME_Selection::SALOME_Selection
63 Selection constructor. Gets an instance of selection manager.
65 SALOME_Selection::SALOME_Selection() : mySelMgr( 0 )
67 if ( SalomeApp_Application* anApp = getApplication() ) {
68 mySelMgr = anApp->selectionMgr();
69 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SIGNAL( currentSelectionChanged() ) );
70 connect( mySelMgr, SIGNAL( destroyed() ), this, SLOT ( onSelMgrDestroyed() ) );
75 SALOME_Selection::onSelMgrDestroyed
76 Watches for the selection manager destroying when study is closed.
78 void SALOME_Selection::onSelMgrDestroyed()
84 SALOME_Selection::Clear
87 void SALOME_Selection::Clear()
89 class TEvent: public SALOME_Event {
90 SalomeApp_SelectionMgr* mySelMgr;
92 TEvent( SalomeApp_SelectionMgr* selMgr )
93 : mySelMgr( selMgr ) {}
94 virtual void Execute() {
96 mySelMgr->clearSelected();
99 ProcessVoidEvent( new TEvent( mySelMgr ) );
103 SALOME_Selection::ClearIObjects
104 Clears the selection.
106 void SALOME_Selection::ClearIObjects()
112 SALOME_Selection::ClearFilters
113 Removes all selection filters.
115 void SALOME_Selection::ClearFilters()
117 class TEvent: public SALOME_Event {
118 SalomeApp_SelectionMgr* mySelMgr;
120 TEvent( SalomeApp_SelectionMgr* selMgr )
121 : mySelMgr( selMgr ) {}
122 virtual void Execute() {
124 mySelMgr->clearFilters();
129 //====================================================================================
131 //====================================================================================
134 SalomePyQt::getDesktop
135 Gets desktop. Returns 0 in error.
137 class TGetDesktopEvent: public SALOME_Event {
139 typedef QWidget* TResult;
141 TGetDesktopEvent() : myResult( 0 ) {}
142 virtual void Execute() {
143 if ( getApplication() )
144 myResult = (QWidget*)( getApplication()->desktop() );
147 QWidget* SalomePyQt::getDesktop()
149 return ProcessEvent( new TGetDesktopEvent() );
153 SalomePyQt::getMainFrame
154 Gets workspace widget. Returns 0 in error.
156 class TGetMainFrameEvent: public SALOME_Event {
158 typedef QWidget* TResult;
160 TGetMainFrameEvent() : myResult( 0 ) {}
161 virtual void Execute() {
162 if ( getApplication() ) {
163 SUIT_Desktop* aDesktop = getApplication()->desktop();
164 myResult = (QWidget*)( aDesktop->centralWidget() );
168 QWidget* SalomePyQt::getMainFrame()
170 return ProcessEvent( new TGetMainFrameEvent() );
174 SalomePyQt::getMainMenuBar
175 Gets main menu. Returns 0 in error.
177 class TGetMainMenuBarEvent: public SALOME_Event {
179 typedef QMenuBar* TResult;
181 TGetMainMenuBarEvent() : myResult( 0 ) {}
182 virtual void Execute() {
183 if ( SalomeApp_Application* anApp = getApplication() ) {
184 myResult = anApp->desktop()->menuBar();
188 QMenuBar* SalomePyQt::getMainMenuBar()
190 return ProcessEvent( new TGetMainMenuBarEvent() );
194 SalomePyQt::getPopupMenu
195 Gets an main menu's child popup menu by its id
197 class TGetPopupMenuEvent: public SALOME_Event {
199 typedef QPopupMenu* TResult;
202 TGetPopupMenuEvent( const MenuName menu ) : myResult( 0 ), myMenuName( menu ) {}
203 virtual void Execute() {
204 if ( SalomeApp_Application* anApp = getApplication() ) {
205 QMenuBar* menuBar = anApp->desktop()->menuBar();
208 switch( myMenuName) {
210 menu = QObject::tr( "MEN_DESK_FILE" ); break;
212 menu = QObject::tr( "MEN_DESK_VIEW" ); break;
214 menu = QObject::tr( "MEN_DESK_EDIT" ); break;
216 menu = QObject::tr( "MEN_DESK_PREFERENCES" ); break;
218 menu = QObject::tr( "MEN_DESK_TOOLS" ); break;
220 menu = QObject::tr( "MEN_DESK_WINDOW" ); break;
222 menu = QObject::tr( "MEN_DESK_HELP" ); break;
224 for ( int i = 0; i < menuBar->count() && !myResult; i++ ) {
225 QMenuItem* item = menuBar->findItem( menuBar->idAt( i ) );
226 if ( item && item->text() == menu && item->popup() )
227 myResult = item->popup();
233 QPopupMenu* SalomePyQt::getPopupMenu( const MenuName menu )
235 return ProcessEvent( new TGetPopupMenuEvent( menu ) );
239 SalomePyQt::getStudyId
240 Returns active study's ID or 0 if there is no active study.
242 class TGetStudyIdEvent: public SALOME_Event {
246 TGetStudyIdEvent() : myResult( 0 ) {}
247 virtual void Execute() {
248 if ( SalomeApp_Study* aStudy = getActiveStudy() ) {
249 myResult = aStudy->studyDS()->StudyId();
253 int SalomePyQt::getStudyId()
255 return ProcessEvent( new TGetStudyIdEvent() );
259 SalomePyQt::getSelection
260 Creates a Selection object (to provide a compatibility with previous SALOME GUI).
262 class TGetSelectionEvent: public SALOME_Event {
264 typedef SALOME_Selection* TResult;
266 TGetSelectionEvent() : myResult( 0 ) {}
267 virtual void Execute() {
268 myResult = new SALOME_Selection();
271 SALOME_Selection* SalomePyQt::getSelection()
273 return ProcessEvent( new TGetSelectionEvent() );
278 Puts an information message to the desktop's status bar
279 (with optional delay parameter given in seconds)
281 class TPutInfoEvent: public SALOME_Event {
285 TPutInfoEvent( const QString& msg, const int sec = 0 ) : myMsg( msg ), mySecs( sec ) {}
286 virtual void Execute() {
287 if ( SalomeApp_Application* anApp = getApplication() ) {
288 anApp->putInfo( myMsg, mySecs * 1000 );
292 void SalomePyQt::putInfo( const QString& msg, const int sec )
294 ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
298 SalomePyQt::getActiveComponent
299 Returns an active component name or empty string if there is no active component
301 class TGetActiveComponentEvent: public SALOME_Event {
303 typedef QString TResult;
305 TGetActiveComponentEvent() {}
306 virtual void Execute() {
307 if ( SalomeApp_Application* anApp = getApplication() ) {
308 if ( CAM_Module* mod = anApp->activeModule() ) {
309 myResult = mod->name("");
314 const QString SalomePyQt::getActiveComponent()
316 return ProcessEvent( new TGetActiveComponentEvent() );
320 SalomePyQt::updateObjBrowser
321 Updates an Object Browser of a given study.
322 If <studyId> <= 0 the active study's object browser is updated.
323 <updateSelection> parameter is obsolete parameter and currently not used. To be removed lately.
325 void SalomePyQt::updateObjBrowser( const int studyId, bool updateSelection )
327 class TEvent: public SALOME_Event {
329 bool myUpdateSelection;
331 TEvent( const int studyId, bool updateSelection )
332 : myStudyId( studyId ), myUpdateSelection( updateSelection ) {}
333 virtual void Execute() {
334 if ( SUIT_Session::session() ) {
335 if ( getActiveStudy() && myStudyId <= 0 )
336 myStudyId = getActiveStudy()->id();
337 if ( myStudyId > 0 ) {
338 QPtrList<SUIT_Application> apps = SUIT_Session::session()->applications();
339 QPtrListIterator<SUIT_Application> it( apps );
340 for( ; it.current(); ++it ) {
341 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( it.current() );
342 if ( anApp && anApp->activeStudy() && anApp->activeStudy()->id() == myStudyId )
343 anApp->updateObjectBrowser();
349 ProcessVoidEvent( new TEvent( studyId, updateSelection ) );
352 const char* DEFAULT_SECTION = "SalomePyQt";
355 SalomePyQt::addStringSetting
356 Adds a string setting to the application preferences
357 <autoValue> parameter is obsolete parameter and currently not used. To be removed lately.
358 This function is obsolete. Use addSetting() instead.
360 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
362 class TEvent: public SALOME_Event {
367 TEvent( const QString& name, const QString& value, bool autoValue )
368 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
369 virtual void Execute() {
370 if ( SUIT_Session::session() ) {
371 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
372 QStringList sl = QStringList::split( ":", myName );
373 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
374 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
375 if ( !_sec.isEmpty() && !_nam.isEmpty() )
376 resMgr->setValue( _sec, _nam, myValue );
380 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
384 SalomePyQt::addIntSetting
385 Adds an integer setting to the application preferences
386 <autoValue> parameter is obsolete parameter and currently not used. To be removed lately.
387 This function is obsolete. Use addSetting() instead.
389 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
391 class TEvent: public SALOME_Event {
396 TEvent( const QString& name, const int value, bool autoValue )
397 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
398 virtual void Execute() {
399 if ( SUIT_Session::session() ) {
400 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
401 QStringList sl = QStringList::split( ":", myName );
402 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
403 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
404 if ( !_sec.isEmpty() && !_nam.isEmpty() )
405 resMgr->setValue( _sec, _nam, myValue );
409 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
413 SalomePyQt::addDoubleSetting
414 Adds an double setting to the application preferences
415 <autoValue> parameter is obsolete parameter and currently not used. To be removed lately.
416 This function is obsolete. Use addSetting() instead.
418 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
420 class TEvent: public SALOME_Event {
425 TEvent( const QString& name, const double value, bool autoValue )
426 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
427 virtual void Execute() {
428 if ( SUIT_Session::session() ) {
429 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
430 QStringList sl = QStringList::split( ":", myName );
431 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
432 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
433 if ( !_sec.isEmpty() && !_nam.isEmpty() )
434 resMgr->setValue( _sec, _nam, myValue );
438 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
442 SalomePyQt::removeSettings
443 Removes a setting from the application preferences
444 This function is obsolete. Use removeSetting() instead.
446 void SalomePyQt::removeSettings( const QString& name )
448 class TEvent: public SALOME_Event {
451 TEvent( const QString& name ) : myName( name ) {}
452 virtual void Execute() {
453 if ( SUIT_Session::session() ) {
454 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
455 QStringList sl = QStringList::split( ":", myName );
456 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
457 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
458 if ( !_sec.isEmpty() && !_nam.isEmpty() )
459 resMgr->remove( _sec, _nam );
463 ProcessVoidEvent( new TEvent( name ) );
467 SalomePyQt::getSetting
468 Gets a setting value (as string)
469 This function is obsolete. Use stringSetting(), integerSetting(),
470 boolSetting(), stringSetting() or colorSetting() instead.
472 class TGetSettingEvent: public SALOME_Event {
474 typedef QString TResult;
477 TGetSettingEvent( const QString& name ) : myName( name ) {}
478 virtual void Execute() {
479 if ( SUIT_Session::session() ) {
480 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
481 QStringList sl = QStringList::split( ":", myName );
482 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
483 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
484 myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" );
488 QString SalomePyQt::getSetting( const QString& name )
490 return ProcessEvent( new TGetSettingEvent( name ) );
494 SalomePyQt::addSetting
495 Adds a double setting to the application preferences
497 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
499 class TEvent: public SALOME_Event {
504 TEvent( const QString& section, const QString& name, double value )
505 : mySection( section ), myName( name ), myValue( value ) {}
506 virtual void Execute() {
507 if ( SUIT_Session::session() ) {
508 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
509 if ( !mySection.isEmpty() && !myName.isEmpty() )
510 resMgr->setValue( mySection, myName, myValue );
514 ProcessVoidEvent( new TEvent( section, name, value ) );
518 SalomePyQt::addSetting
519 Adds an integer setting to the application preferences
521 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
523 class TEvent: public SALOME_Event {
528 TEvent( const QString& section, const QString& name, int value )
529 : mySection( section ), myName( name ), myValue( value ) {}
530 virtual void Execute() {
531 if ( SUIT_Session::session() ) {
532 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
533 if ( !mySection.isEmpty() && !myName.isEmpty() )
534 resMgr->setValue( mySection, myName, myValue );
538 ProcessVoidEvent( new TEvent( section, name, value ) );
542 SalomePyQt::addSetting
543 Adds a string setting to the application preferences
545 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
547 class TEvent: public SALOME_Event {
552 TEvent( const QString& section, const QString& name, const QString& value )
553 : mySection( section ), myName( name ), myValue( value ) {}
554 virtual void Execute() {
555 if ( SUIT_Session::session() ) {
556 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
557 if ( !mySection.isEmpty() && !myName.isEmpty() )
558 resMgr->setValue( mySection, myName, myValue );
562 ProcessVoidEvent( new TEvent( section, name, value ) );
566 SalomePyQt::addSetting
567 Adds a color setting to the application preferences
569 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
571 class TEvent: public SALOME_Event {
576 TEvent( const QString& section, const QString& name, const QColor& value )
577 : mySection( section ), myName( name ), myValue( value ) {}
578 virtual void Execute() {
579 if ( SUIT_Session::session() ) {
580 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
581 if ( !mySection.isEmpty() && !myName.isEmpty() )
582 resMgr->setValue( mySection, myName, myValue );
586 ProcessVoidEvent( new TEvent( section, name, value ) );
590 SalomePyQt::integerSetting
591 Gets an integer setting from the application preferences
593 class TGetIntSettingEvent: public SALOME_Event {
600 TGetIntSettingEvent( const QString& section, const QString& name, const int def )
601 : mySection( section ), myName( name ), myDefault( def ) {}
602 virtual void Execute() {
603 if ( SUIT_Session::session() ) {
604 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
605 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
609 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
611 return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
615 SalomePyQt::doubleSetting
616 Gets a double setting from the application preferences
618 class TGetDblSettingEvent: public SALOME_Event {
620 typedef double TResult;
625 TGetDblSettingEvent( const QString& section, const QString& name, const double def )
626 : mySection( section ), myName( name ), myDefault( def ) {}
627 virtual void Execute() {
628 if ( SUIT_Session::session() ) {
629 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
630 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
634 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const int def )
636 return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
640 SalomePyQt::boolSetting
641 Gets a boolean setting from the application preferences
643 class TGetBoolSettingEvent: public SALOME_Event {
645 typedef bool TResult;
650 TGetBoolSettingEvent( const QString& section, const QString& name, const bool def )
651 : mySection( section ), myName( name ), myDefault( def ) {}
652 virtual void Execute() {
653 if ( SUIT_Session::session() ) {
654 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
655 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
659 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
661 return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
665 SalomePyQt::stringSetting
666 Gets a string setting from the application preferences
668 class TGetStrSettingEvent: public SALOME_Event {
670 typedef QString TResult;
675 TGetStrSettingEvent( const QString& section, const QString& name, const QString& def )
676 : mySection( section ), myName( name ), myDefault( def ) {}
677 virtual void Execute() {
678 if ( SUIT_Session::session() ) {
679 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
680 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault ) : myDefault;
684 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def )
686 return ProcessEvent( new TGetStrSettingEvent( section, name, def ) );
690 SalomePyQt::colorSetting
691 Gets a color setting from the application preferences
693 class TGetColorSettingEvent: public SALOME_Event {
695 typedef QColor TResult;
700 TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def )
701 : mySection( section ), myName( name ), myDefault( def ) {}
702 virtual void Execute() {
703 if ( SUIT_Session::session() ) {
704 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
705 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
709 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
711 return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
715 SalomePyQt::removeSetting
716 Removes a setting from the application preferences
718 void SalomePyQt::removeSetting( const QString& section, const QString& name )
720 class TEvent: public SALOME_Event {
724 TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
725 virtual void Execute() {
726 if ( SUIT_Session::session() ) {
727 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
728 if ( !mySection.isEmpty() && !myName.isEmpty() )
729 resMgr->remove( mySection, myName );
733 ProcessVoidEvent( new TEvent( section, name ) );
737 SalomePyQt::getFileName
738 Displays 'Open/Save file' dialog box and returns a user's choice (file name)
740 class TGetFileNameEvent: public SALOME_Event {
742 typedef QString TResult;
746 QStringList myFilters;
749 TGetFileNameEvent( QWidget* parent,
750 const QString& initial,
751 const QStringList& filters,
752 const QString& caption,
754 : myParent ( parent ),
755 myInitial( initial ),
756 myFilters( filters ),
757 myCaption( caption ),
759 virtual void Execute() {
760 if ( SalomeApp_Application* anApp = getApplication() ) {
761 myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"), myCaption, myParent );
765 QString SalomePyQt::getFileName( QWidget* parent,
766 const QString& initial,
767 const QStringList& filters,
768 const QString& caption,
771 return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
775 SalomePyQt::getOpenFileNames
776 Displays 'Open files' dialog box and returns a user's choice (a list of file names)
778 class TGetOpenFileNamesEvent: public SALOME_Event {
780 typedef QStringList TResult;
784 QStringList myFilters;
786 TGetOpenFileNamesEvent( QWidget* parent,
787 const QString& initial,
788 const QStringList& filters,
789 const QString& caption )
790 : myParent ( parent ),
791 myInitial( initial ),
792 myFilters( filters ),
793 myCaption( caption ) {}
794 virtual void Execute() {
795 if ( SalomeApp_Application* anApp = getApplication() ) {
796 myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
800 QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
801 const QString& initial,
802 const QStringList& filters,
803 const QString& caption )
805 return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
809 SalomePyQt::getExistingDirectory
810 Displays 'Get Directory' dialog box and returns a user's choice (a directory name)
812 class TGetExistingDirectoryEvent: public SALOME_Event {
814 typedef QString TResult;
819 TGetExistingDirectoryEvent( QWidget* parent,
820 const QString& initial,
821 const QString& caption )
822 : myParent ( parent ),
823 myInitial( initial ),
824 myCaption( caption ) {}
825 virtual void Execute() {
826 if ( SalomeApp_Application* anApp = getApplication() ) {
827 myResult = anApp->getDirectory( myInitial, myCaption, myParent );
831 QString SalomePyQt::getExistingDirectory( QWidget* parent,
832 const QString& initial,
833 const QString& caption )
835 return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
839 SalomePyQt::helpContext
840 Opens external browser to display 'context help' information
841 current implementation does nothing.
843 void SalomePyQt::helpContext( const QString& source, const QString& context ) {
844 class TEvent: public SALOME_Event {
848 TEvent( const QString& source, const QString& context )
849 : mySource( source ), myContext( context ) {}
850 virtual void Execute() {
851 if ( /*SalomeApp_Application* anApp =*/ getApplication() ) {
853 // anApp->helpContext( mySource, myContext );
857 ProcessVoidEvent( new TEvent( source, context ) );
862 Dumps the contents of the currently active view to the image file
863 in the given format (JPEG, PNG, BMP are supported)
865 class TDumpViewEvent: public SALOME_Event {
867 typedef bool TResult;
870 TDumpViewEvent( const QString& filename )
871 : myResult ( false ), myFileName( filename ) {}
872 virtual void Execute() {
873 if ( SalomeApp_Application* anApp = getApplication() ) {
874 SUIT_ViewManager* vm = anApp->activeViewManager();
876 SUIT_ViewWindow* vw = vm->getActiveView();
878 QImage im = vw->dumpView();
879 if ( !im.isNull() && !myFileName.isEmpty() ) {
880 QString fmt = SUIT_Tools::extension( myFileName ).upper();
881 if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
882 if ( fmt == "JPG" ) fmt = "JPEG";
883 myResult = im.save( myFileName, fmt.latin1() );
890 bool SalomePyQt::dumpView( const QString& filename )
892 return ProcessEvent( new TDumpViewEvent( filename ) );
896 SalomePyQt::createTool
897 These methods allow operating with the toolbars:
898 - create a new toolbar or get the existing one (the toolbar name is passed as parameter);
899 this method returns an id of the toolbar;
900 - add action with given id (must be created previously) and optional index to the existing toolbar
901 (toobar is identified either by its id or by its name)
902 these methods return an id of the action.
903 If error occurs, the -1 value is returned.
908 CrTool( const QString& tBar )
909 : myCase( 0 ), myTbName( tBar ) {}
910 CrTool( const int id, const int tBar, const int idx )
911 : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
912 CrTool( const int id, const QString& tBar, const int idx )
913 : myCase( 2 ), myId( id ), myTbName( tBar ), myIndex( idx ) {}
914 CrTool( QAction* action, const int tbId, const int id, const int idx )
915 : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
916 CrTool( QAction* action, const QString& tBar, const int id, const int idx )
917 : myCase( 4 ), myAction( action ), myTbName( tBar ), myId( id ), myIndex( idx ) {}
919 int execute( SALOME_PYQT_Module* module ) const
924 return module->createTool( myTbName );
926 return module->createTool( myId, myTbId, myIndex );
928 return module->createTool( myId, myTbName, myIndex );
930 return module->createTool( myAction, myTbId, myId, myIndex );
932 return module->createTool( myAction, myTbName, myId, myIndex );
945 class TCreateToolEvent: public SALOME_Event {
949 const CrTool& myCrTool;
950 TCreateToolEvent( const CrTool& crTool )
951 : myResult( -1 ), myCrTool( crTool ) {}
952 virtual void Execute() {
953 if ( SalomeApp_Application* anApp = getApplication() ) {
954 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
956 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
957 myResult = myCrTool.execute( module );
961 // create new toolbar or get existing by name
962 int SalomePyQt::createTool( const QString& tBar )
964 return ProcessEvent( new TCreateToolEvent( CrTool( tBar ) ) );
966 // add action with id and index to the existing tollbar
967 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
969 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
971 // add action with id and index to the existing tollbar
972 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
974 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
976 // add action with id and index to the existing tollbar
977 int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int idx )
979 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
981 // add action with id and index to the existing tollbar
982 int SalomePyQt::createTool( QAction* a, const QString& tBar, const int id, const int idx )
984 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
988 SalomePyQt::createMenu
989 These methods allow operating with the main menu:
990 - create a new menu or submenu or get the existing one (the parent menu name or id is passed as parameter,
991 if it is empty or -1, it means that main menu is created, otherwise submenu is created);
992 this method returns an id of the menu/submenu;
993 - add action with given id (must be created previously) and optional index and group number to the existing menu
994 or submenu (menu name or id us passed as parameter)
995 these methods return an id of the action.
996 If error occurs, the -1 value is returned.
1001 CrMenu( const QString& subMenu, const int menu, const int group, const int idx )
1002 : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
1003 CrMenu( const QString& subMenu, const QString& menu, const int group, const int idx )
1004 : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
1005 CrMenu( const int id, const int menu, const int group, const int idx )
1006 : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
1007 CrMenu( const int id, const QString& menu, const int group, const int idx )
1008 : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
1009 CrMenu( QAction* action, const int menu, const int id, const int group, const int idx )
1010 : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1011 CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx )
1012 : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1014 int execute( SALOME_PYQT_Module* module ) const
1019 return module->createMenu( mySubMenuName, myMenuId, -1, myGroup, myIndex );
1021 return module->createMenu( mySubMenuName, myMenuName, -1, myGroup, myIndex );
1023 return module->createMenu( myId, myMenuId, myGroup, myIndex );
1025 return module->createMenu( myId, myMenuName, myGroup, myIndex );
1027 return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
1029 return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
1038 QString mySubMenuName;
1044 class TCreateMenuEvent: public SALOME_Event {
1046 typedef int TResult;
1048 const CrMenu& myCrMenu;
1049 TCreateMenuEvent( const CrMenu& crMenu )
1050 : myResult( -1 ), myCrMenu( crMenu ) {}
1051 virtual void Execute() {
1052 if ( SalomeApp_Application* anApp = getApplication() ) {
1053 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1055 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1056 myResult = myCrMenu.execute( module );
1060 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int group, const int idx )
1062 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, group, idx ) ) );
1065 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int group, const int idx )
1067 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, group, idx ) ) );
1070 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
1072 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1075 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
1077 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1080 int SalomePyQt::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
1082 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1085 int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
1087 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1091 SalomePyQt::createSeparator
1092 Create a separator action which can be then used in the menu or toolbar.
1094 class TCreateSepEvent: public SALOME_Event {
1096 typedef QAction* TResult;
1100 virtual void Execute() {
1101 if ( SalomeApp_Application* anApp = getApplication() ) {
1102 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1104 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1106 myResult = module->createSeparator();
1110 QAction* SalomePyQt::createSeparator()
1112 return ProcessEvent( new TCreateSepEvent() );
1116 SalomePyQt::createAction
1117 Create an action which can be then used in the menu or toolbar:
1118 - id : the unique id action to be registered to;
1119 - menuText : action text which should appear in menu;
1120 - tipText : text which should appear in the tooltip;
1121 - statusText : text which should appear in the status bar when action is activated;
1122 - icon : the name of the icon file (the actual icon file name can be coded in the translation files);
1123 - key : the key accelrator for the action
1124 - toggle : if true the action is checkable
1126 class TCreateActionEvent: public SALOME_Event {
1128 typedef QAction* TResult;
1133 QString myStatusText;
1137 TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
1138 const QString& statusText, const QString& icon, const int key, const bool toggle )
1139 : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
1140 myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
1141 virtual void Execute() {
1142 if ( SalomeApp_Application* anApp = getApplication() ) {
1143 printf("TCreateActionEvent::Execute() - 1\n");
1144 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1145 printf("TCreateActionEvent::Execute() - 2: module = %d\n",module);
1147 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1148 printf("TCreateActionEvent::Execute() - 3: module = %d\n",module);
1150 myResult = module->createAction( myId, myTipText, myIcon, myMenuText, myStatusText, myKey, myToggle );
1151 printf("TCreateActionEvent::Execute() - 4: myResult = %d\n",myResult);
1155 QAction* SalomePyQt::createAction( const int id, const QString& menuText,
1156 const QString& tipText, const QString& statusText,
1157 const QString& icon, const int key, const bool toggle )
1159 return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
1164 Get an action by its id. Returns 0 if the action with such id was not registered.
1166 class TActionEvent: public SALOME_Event {
1168 typedef QAction* TResult;
1171 TActionEvent( const int id )
1172 : myResult( 0 ), myId( id ) {}
1173 virtual void Execute() {
1174 if ( SalomeApp_Application* anApp = getApplication() ) {
1175 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1177 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1179 myResult = module->action( myId );
1183 QAction* SalomePyQt::action( const int id )
1185 return ProcessEvent( new TActionEvent( id ) );
1189 SalomePyQt::actionId
1190 Get an action id. Returns -1 if the action was not registered.
1192 class TActionIdEvent: public SALOME_Event {
1194 typedef int TResult;
1196 const QAction* myAction;
1197 TActionIdEvent( const QAction* action )
1198 : myResult( -1 ), myAction( action ) {}
1199 virtual void Execute() {
1200 if ( SalomeApp_Application* anApp = getApplication() ) {
1201 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1203 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1205 myResult = module->actionId( myAction );
1209 int SalomePyQt::actionId( const QAction* a )
1211 return ProcessEvent( new TActionIdEvent( a ) );