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();
127 ProcessVoidEvent( new TEvent( mySelMgr ) );
130 //====================================================================================
132 //====================================================================================
135 SalomePyQt::getDesktop
136 Gets desktop. Returns 0 in error.
138 class TGetDesktopEvent: public SALOME_Event {
140 typedef QWidget* TResult;
142 TGetDesktopEvent() : myResult( 0 ) {}
143 virtual void Execute() {
144 if ( getApplication() )
145 myResult = (QWidget*)( getApplication()->desktop() );
148 QWidget* SalomePyQt::getDesktop()
150 return ProcessEvent( new TGetDesktopEvent() );
154 SalomePyQt::getMainFrame
155 Gets workspace widget. Returns 0 in error.
157 class TGetMainFrameEvent: public SALOME_Event {
159 typedef QWidget* TResult;
161 TGetMainFrameEvent() : myResult( 0 ) {}
162 virtual void Execute() {
163 if ( getApplication() ) {
164 SUIT_Desktop* aDesktop = getApplication()->desktop();
165 myResult = (QWidget*)( aDesktop->centralWidget() );
169 QWidget* SalomePyQt::getMainFrame()
171 return ProcessEvent( new TGetMainFrameEvent() );
175 SalomePyQt::getMainMenuBar
176 Gets main menu. Returns 0 in error.
178 class TGetMainMenuBarEvent: public SALOME_Event {
180 typedef QMenuBar* TResult;
182 TGetMainMenuBarEvent() : myResult( 0 ) {}
183 virtual void Execute() {
184 if ( SalomeApp_Application* anApp = getApplication() ) {
185 myResult = anApp->desktop()->menuBar();
189 QMenuBar* SalomePyQt::getMainMenuBar()
191 return ProcessEvent( new TGetMainMenuBarEvent() );
195 SalomePyQt::getPopupMenu
196 Gets an main menu's child popup menu by its id
198 class TGetPopupMenuEvent: public SALOME_Event {
200 typedef QPopupMenu* TResult;
203 TGetPopupMenuEvent( const MenuName menu ) : myResult( 0 ), myMenuName( menu ) {}
204 virtual void Execute() {
205 if ( SalomeApp_Application* anApp = getApplication() ) {
206 QMenuBar* menuBar = anApp->desktop()->menuBar();
209 switch( myMenuName) {
211 menu = QObject::tr( "MEN_DESK_FILE" ); break;
213 menu = QObject::tr( "MEN_DESK_VIEW" ); break;
215 menu = QObject::tr( "MEN_DESK_EDIT" ); break;
217 menu = QObject::tr( "MEN_DESK_PREFERENCES" ); break;
219 menu = QObject::tr( "MEN_DESK_TOOLS" ); break;
221 menu = QObject::tr( "MEN_DESK_WINDOW" ); break;
223 menu = QObject::tr( "MEN_DESK_HELP" ); break;
225 for ( int i = 0; i < menuBar->count() && !myResult; i++ ) {
226 QMenuItem* item = menuBar->findItem( menuBar->idAt( i ) );
227 if ( item && item->text() == menu && item->popup() )
228 myResult = item->popup();
234 QPopupMenu* SalomePyQt::getPopupMenu( const MenuName menu )
236 return ProcessEvent( new TGetPopupMenuEvent( menu ) );
240 SalomePyQt::getStudyId
241 Returns active study's ID or 0 if there is no active study.
243 class TGetStudyIdEvent: public SALOME_Event {
247 TGetStudyIdEvent() : myResult( 0 ) {}
248 virtual void Execute() {
249 if ( SalomeApp_Study* aStudy = getActiveStudy() ) {
250 myResult = aStudy->studyDS()->StudyId();
254 int SalomePyQt::getStudyId()
256 return ProcessEvent( new TGetStudyIdEvent() );
260 SalomePyQt::getSelection
261 Creates a Selection object (to provide a compatibility with previous SALOME GUI).
263 class TGetSelectionEvent: public SALOME_Event {
265 typedef SALOME_Selection* TResult;
267 TGetSelectionEvent() : myResult( 0 ) {}
268 virtual void Execute() {
269 myResult = new SALOME_Selection();
272 SALOME_Selection* SalomePyQt::getSelection()
274 return ProcessEvent( new TGetSelectionEvent() );
279 Puts an information message to the desktop's status bar
280 (with optional delay parameter given in seconds)
282 class TPutInfoEvent: public SALOME_Event {
286 TPutInfoEvent( const QString& msg, const int sec = 0 ) : myMsg( msg ), mySecs( sec ) {}
287 virtual void Execute() {
288 if ( SalomeApp_Application* anApp = getApplication() ) {
289 anApp->putInfo( myMsg, mySecs * 1000 );
293 void SalomePyQt::putInfo( const QString& msg, const int sec )
295 ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
299 SalomePyQt::getActiveComponent
300 Returns an active component name or empty string if there is no active component
302 class TGetActiveComponentEvent: public SALOME_Event {
304 typedef QString TResult;
306 TGetActiveComponentEvent() {}
307 virtual void Execute() {
308 if ( SalomeApp_Application* anApp = getApplication() ) {
309 if ( CAM_Module* mod = anApp->activeModule() ) {
310 myResult = mod->name("");
315 const QString SalomePyQt::getActiveComponent()
317 return ProcessEvent( new TGetActiveComponentEvent() );
321 SalomePyQt::updateObjBrowser
322 Updates an Object Browser of a given study.
323 If <studyId> <= 0 the active study's object browser is updated.
324 <updateSelection> parameter is obsolete parameter and currently not used. To be removed lately.
326 void SalomePyQt::updateObjBrowser( const int studyId, bool updateSelection )
328 class TEvent: public SALOME_Event {
330 bool myUpdateSelection;
332 TEvent( const int studyId, bool updateSelection )
333 : myStudyId( studyId ), myUpdateSelection( updateSelection ) {}
334 virtual void Execute() {
335 if ( SUIT_Session::session() ) {
336 if ( getActiveStudy() && myStudyId <= 0 )
337 myStudyId = getActiveStudy()->id();
338 if ( myStudyId > 0 ) {
339 QPtrList<SUIT_Application> apps = SUIT_Session::session()->applications();
340 QPtrListIterator<SUIT_Application> it( apps );
341 for( ; it.current(); ++it ) {
342 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( it.current() );
343 if ( anApp && anApp->activeStudy() && anApp->activeStudy()->id() == myStudyId )
344 anApp->updateObjectBrowser();
350 ProcessVoidEvent( new TEvent( studyId, updateSelection ) );
353 const char* DEFAULT_SECTION = "SalomePyQt";
356 SalomePyQt::addStringSetting
357 Adds a string setting to the application preferences
358 <autoValue> parameter is obsolete parameter and currently not used. To be removed lately.
359 This function is obsolete. Use addSetting() instead.
361 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
363 class TEvent: public SALOME_Event {
368 TEvent( const QString& name, const QString& value, bool autoValue )
369 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
370 virtual void Execute() {
371 if ( SUIT_Session::session() ) {
372 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
373 QStringList sl = QStringList::split( ":", myName );
374 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
375 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
376 if ( !_sec.isEmpty() && !_nam.isEmpty() )
377 resMgr->setValue( _sec, _nam, myValue );
381 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
385 SalomePyQt::addIntSetting
386 Adds an integer setting to the application preferences
387 <autoValue> parameter is obsolete parameter and currently not used. To be removed lately.
388 This function is obsolete. Use addSetting() instead.
390 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
392 class TEvent: public SALOME_Event {
397 TEvent( const QString& name, const int value, bool autoValue )
398 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
399 virtual void Execute() {
400 if ( SUIT_Session::session() ) {
401 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
402 QStringList sl = QStringList::split( ":", myName );
403 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
404 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
405 if ( !_sec.isEmpty() && !_nam.isEmpty() )
406 resMgr->setValue( _sec, _nam, myValue );
410 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
414 SalomePyQt::addDoubleSetting
415 Adds an double setting to the application preferences
416 <autoValue> parameter is obsolete parameter and currently not used. To be removed lately.
417 This function is obsolete. Use addSetting() instead.
419 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
421 class TEvent: public SALOME_Event {
426 TEvent( const QString& name, const double value, bool autoValue )
427 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
428 virtual void Execute() {
429 if ( SUIT_Session::session() ) {
430 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
431 QStringList sl = QStringList::split( ":", myName );
432 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
433 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
434 if ( !_sec.isEmpty() && !_nam.isEmpty() )
435 resMgr->setValue( _sec, _nam, myValue );
439 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
443 SalomePyQt::removeSettings
444 Removes a setting from the application preferences
445 This function is obsolete. Use removeSetting() instead.
447 void SalomePyQt::removeSettings( const QString& name )
449 class TEvent: public SALOME_Event {
452 TEvent( const QString& name ) : myName( name ) {}
453 virtual void Execute() {
454 if ( SUIT_Session::session() ) {
455 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
456 QStringList sl = QStringList::split( ":", myName );
457 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
458 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
459 if ( !_sec.isEmpty() && !_nam.isEmpty() )
460 resMgr->remove( _sec, _nam );
464 ProcessVoidEvent( new TEvent( name ) );
468 SalomePyQt::getSetting
469 Gets a setting value (as string)
470 This function is obsolete. Use stringSetting(), integerSetting(),
471 boolSetting(), stringSetting() or colorSetting() instead.
473 class TGetSettingEvent: public SALOME_Event {
475 typedef QString TResult;
478 TGetSettingEvent( const QString& name ) : myName( name ) {}
479 virtual void Execute() {
480 if ( SUIT_Session::session() ) {
481 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
482 QStringList sl = QStringList::split( ":", myName );
483 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
484 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
485 myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" );
489 QString SalomePyQt::getSetting( const QString& name )
491 return ProcessEvent( new TGetSettingEvent( name ) );
495 SalomePyQt::addSetting
496 Adds a double setting to the application preferences
498 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
500 class TEvent: public SALOME_Event {
505 TEvent( const QString& section, const QString& name, double value )
506 : mySection( section ), myName( name ), myValue( value ) {}
507 virtual void Execute() {
508 if ( SUIT_Session::session() ) {
509 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
510 if ( !mySection.isEmpty() && !myName.isEmpty() )
511 resMgr->setValue( mySection, myName, myValue );
515 ProcessVoidEvent( new TEvent( section, name, value ) );
519 SalomePyQt::addSetting
520 Adds an integer setting to the application preferences
522 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
524 class TEvent: public SALOME_Event {
529 TEvent( const QString& section, const QString& name, int value )
530 : mySection( section ), myName( name ), myValue( value ) {}
531 virtual void Execute() {
532 if ( SUIT_Session::session() ) {
533 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
534 if ( !mySection.isEmpty() && !myName.isEmpty() )
535 resMgr->setValue( mySection, myName, myValue );
539 ProcessVoidEvent( new TEvent( section, name, value ) );
543 SalomePyQt::addSetting
544 Adds a string setting to the application preferences
546 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
548 class TEvent: public SALOME_Event {
553 TEvent( const QString& section, const QString& name, const QString& value )
554 : mySection( section ), myName( name ), myValue( value ) {}
555 virtual void Execute() {
556 if ( SUIT_Session::session() ) {
557 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
558 if ( !mySection.isEmpty() && !myName.isEmpty() )
559 resMgr->setValue( mySection, myName, myValue );
563 ProcessVoidEvent( new TEvent( section, name, value ) );
567 SalomePyQt::addSetting
568 Adds a color setting to the application preferences
570 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
572 class TEvent: public SALOME_Event {
577 TEvent( const QString& section, const QString& name, const QColor& value )
578 : mySection( section ), myName( name ), myValue( value ) {}
579 virtual void Execute() {
580 if ( SUIT_Session::session() ) {
581 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
582 if ( !mySection.isEmpty() && !myName.isEmpty() )
583 resMgr->setValue( mySection, myName, myValue );
587 ProcessVoidEvent( new TEvent( section, name, value ) );
591 SalomePyQt::integerSetting
592 Gets an integer setting from the application preferences
594 class TGetIntSettingEvent: public SALOME_Event {
601 TGetIntSettingEvent( const QString& section, const QString& name, const int def )
602 : mySection( section ), myName( name ), myDefault( def ) {}
603 virtual void Execute() {
604 if ( SUIT_Session::session() ) {
605 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
606 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
610 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
612 return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
616 SalomePyQt::doubleSetting
617 Gets a double setting from the application preferences
619 class TGetDblSettingEvent: public SALOME_Event {
621 typedef double TResult;
626 TGetDblSettingEvent( const QString& section, const QString& name, const double def )
627 : mySection( section ), myName( name ), myDefault( def ) {}
628 virtual void Execute() {
629 if ( SUIT_Session::session() ) {
630 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
631 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
635 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const int def )
637 return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
641 SalomePyQt::boolSetting
642 Gets a boolean setting from the application preferences
644 class TGetBoolSettingEvent: public SALOME_Event {
646 typedef bool TResult;
651 TGetBoolSettingEvent( const QString& section, const QString& name, const bool def )
652 : mySection( section ), myName( name ), myDefault( def ) {}
653 virtual void Execute() {
654 if ( SUIT_Session::session() ) {
655 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
656 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
660 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
662 return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
666 SalomePyQt::stringSetting
667 Gets a string setting from the application preferences
669 class TGetStrSettingEvent: public SALOME_Event {
671 typedef QString TResult;
676 TGetStrSettingEvent( const QString& section, const QString& name, const QString& def )
677 : mySection( section ), myName( name ), myDefault( def ) {}
678 virtual void Execute() {
679 if ( SUIT_Session::session() ) {
680 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
681 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault ) : myDefault;
685 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def )
687 return ProcessEvent( new TGetStrSettingEvent( section, name, def ) );
691 SalomePyQt::colorSetting
692 Gets a color setting from the application preferences
694 class TGetColorSettingEvent: public SALOME_Event {
696 typedef QColor TResult;
701 TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def )
702 : mySection( section ), myName( name ), myDefault( def ) {}
703 virtual void Execute() {
704 if ( SUIT_Session::session() ) {
705 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
706 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
710 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
712 return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
716 SalomePyQt::removeSetting
717 Removes a setting from the application preferences
719 void SalomePyQt::removeSetting( const QString& section, const QString& name )
721 class TEvent: public SALOME_Event {
725 TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
726 virtual void Execute() {
727 if ( SUIT_Session::session() ) {
728 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
729 if ( !mySection.isEmpty() && !myName.isEmpty() )
730 resMgr->remove( mySection, myName );
734 ProcessVoidEvent( new TEvent( section, name ) );
738 SalomePyQt::getFileName
739 Displays 'Open/Save file' dialog box and returns a user's choice (file name)
741 class TGetFileNameEvent: public SALOME_Event {
743 typedef QString TResult;
747 QStringList myFilters;
750 TGetFileNameEvent( QWidget* parent,
751 const QString& initial,
752 const QStringList& filters,
753 const QString& caption,
755 : myParent ( parent ),
756 myInitial( initial ),
757 myFilters( filters ),
758 myCaption( caption ),
760 virtual void Execute() {
761 if ( SalomeApp_Application* anApp = getApplication() ) {
762 myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"), myCaption, myParent );
766 QString SalomePyQt::getFileName( QWidget* parent,
767 const QString& initial,
768 const QStringList& filters,
769 const QString& caption,
772 return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
776 SalomePyQt::getOpenFileNames
777 Displays 'Open files' dialog box and returns a user's choice (a list of file names)
779 class TGetOpenFileNamesEvent: public SALOME_Event {
781 typedef QStringList TResult;
785 QStringList myFilters;
787 TGetOpenFileNamesEvent( QWidget* parent,
788 const QString& initial,
789 const QStringList& filters,
790 const QString& caption )
791 : myParent ( parent ),
792 myInitial( initial ),
793 myFilters( filters ),
794 myCaption( caption ) {}
795 virtual void Execute() {
796 if ( SalomeApp_Application* anApp = getApplication() ) {
797 myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
801 QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
802 const QString& initial,
803 const QStringList& filters,
804 const QString& caption )
806 return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
810 SalomePyQt::getExistingDirectory
811 Displays 'Get Directory' dialog box and returns a user's choice (a directory name)
813 class TGetExistingDirectoryEvent: public SALOME_Event {
815 typedef QString TResult;
820 TGetExistingDirectoryEvent( QWidget* parent,
821 const QString& initial,
822 const QString& caption )
823 : myParent ( parent ),
824 myInitial( initial ),
825 myCaption( caption ) {}
826 virtual void Execute() {
827 if ( SalomeApp_Application* anApp = getApplication() ) {
828 myResult = anApp->getDirectory( myInitial, myCaption, myParent );
832 QString SalomePyQt::getExistingDirectory( QWidget* parent,
833 const QString& initial,
834 const QString& caption )
836 return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
840 SalomePyQt::helpContext
841 Opens external browser to display 'context help' information
842 current implementation does nothing.
844 void SalomePyQt::helpContext( const QString& source, const QString& context ) {
845 class TEvent: public SALOME_Event {
849 TEvent( const QString& source, const QString& context )
850 : mySource( source ), myContext( context ) {}
851 virtual void Execute() {
852 if ( /*SalomeApp_Application* anApp =*/ getApplication() ) {
854 // anApp->helpContext( mySource, myContext );
858 ProcessVoidEvent( new TEvent( source, context ) );
863 Dumps the contents of the currently active view to the image file
864 in the given format (JPEG, PNG, BMP are supported)
866 class TDumpViewEvent: public SALOME_Event {
868 typedef bool TResult;
871 TDumpViewEvent( const QString& filename )
872 : myResult ( false ), myFileName( filename ) {}
873 virtual void Execute() {
874 if ( SalomeApp_Application* anApp = getApplication() ) {
875 SUIT_ViewManager* vm = anApp->activeViewManager();
877 SUIT_ViewWindow* vw = vm->getActiveView();
879 QImage im = vw->dumpView();
880 if ( !im.isNull() && !myFileName.isEmpty() ) {
881 QString fmt = SUIT_Tools::extension( myFileName ).upper();
882 if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
883 if ( fmt == "JPG" ) fmt = "JPEG";
884 myResult = im.save( myFileName, fmt.latin1() );
891 bool SalomePyQt::dumpView( const QString& filename )
893 return ProcessEvent( new TDumpViewEvent( filename ) );
897 SalomePyQt::createTool
898 These methods allow operating with the toolbars:
899 - create a new toolbar or get the existing one (the toolbar name is passed as parameter);
900 this method returns an id of the toolbar;
901 - add action with given id (must be created previously) and optional index to the existing toolbar
902 (toobar is identified either by its id or by its name)
903 these methods return an id of the action.
904 If error occurs, the -1 value is returned.
909 CrTool( const QString& tBar )
910 : myCase( 0 ), myTbName( tBar ) {}
911 CrTool( const int id, const int tBar, const int idx )
912 : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
913 CrTool( const int id, const QString& tBar, const int idx )
914 : myCase( 2 ), myId( id ), myTbName( tBar ), myIndex( idx ) {}
915 CrTool( QAction* action, const int tbId, const int id, const int idx )
916 : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
917 CrTool( QAction* action, const QString& tBar, const int id, const int idx )
918 : myCase( 4 ), myAction( action ), myTbName( tBar ), myId( id ), myIndex( idx ) {}
920 int execute( SALOME_PYQT_Module* module ) const
925 return module->createTool( myTbName );
927 return module->createTool( myId, myTbId, myIndex );
929 return module->createTool( myId, myTbName, myIndex );
931 return module->createTool( myAction, myTbId, myId, myIndex );
933 return module->createTool( myAction, myTbName, myId, myIndex );
946 class TCreateToolEvent: public SALOME_Event {
950 const CrTool& myCrTool;
951 TCreateToolEvent( const CrTool& crTool )
952 : myResult( -1 ), myCrTool( crTool ) {}
953 virtual void Execute() {
954 if ( SalomeApp_Application* anApp = getApplication() ) {
955 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
957 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
958 myResult = myCrTool.execute( module );
962 // create new toolbar or get existing by name
963 int SalomePyQt::createTool( const QString& tBar )
965 return ProcessEvent( new TCreateToolEvent( CrTool( tBar ) ) );
967 // add action with id and index to the existing tollbar
968 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
970 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
972 // add action with id and index to the existing tollbar
973 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
975 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
977 // add action with id and index to the existing tollbar
978 int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int idx )
980 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
982 // add action with id and index to the existing tollbar
983 int SalomePyQt::createTool( QAction* a, const QString& tBar, const int id, const int idx )
985 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
989 SalomePyQt::createMenu
990 These methods allow operating with the main menu:
991 - create a new menu or submenu or get the existing one (the parent menu name or id is passed as parameter,
992 if it is empty or -1, it means that main menu is created, otherwise submenu is created);
993 this method returns an id of the menu/submenu;
994 - add action with given id (must be created previously) and optional index and group number to the existing menu
995 or submenu (menu name or id us passed as parameter)
996 these methods return an id of the action.
997 If error occurs, the -1 value is returned.
1002 CrMenu( const QString& subMenu, const int menu, const int group, const int idx )
1003 : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
1004 CrMenu( const QString& subMenu, const QString& menu, const int group, const int idx )
1005 : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
1006 CrMenu( const int id, const int menu, const int group, const int idx )
1007 : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
1008 CrMenu( const int id, const QString& menu, const int group, const int idx )
1009 : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
1010 CrMenu( QAction* action, const int menu, const int id, const int group, const int idx )
1011 : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1012 CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx )
1013 : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1015 int execute( SALOME_PYQT_Module* module ) const
1020 return module->createMenu( mySubMenuName, myMenuId, -1, myGroup, myIndex );
1022 return module->createMenu( mySubMenuName, myMenuName, -1, myGroup, myIndex );
1024 return module->createMenu( myId, myMenuId, myGroup, myIndex );
1026 return module->createMenu( myId, myMenuName, myGroup, myIndex );
1028 return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
1030 return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
1039 QString mySubMenuName;
1045 class TCreateMenuEvent: public SALOME_Event {
1047 typedef int TResult;
1049 const CrMenu& myCrMenu;
1050 TCreateMenuEvent( const CrMenu& crMenu )
1051 : myResult( -1 ), myCrMenu( crMenu ) {}
1052 virtual void Execute() {
1053 if ( SalomeApp_Application* anApp = getApplication() ) {
1054 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1056 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1057 myResult = myCrMenu.execute( module );
1061 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int group, const int idx )
1063 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, group, idx ) ) );
1066 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int group, const int idx )
1068 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, group, idx ) ) );
1071 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
1073 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1076 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
1078 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1081 int SalomePyQt::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
1083 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1086 int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
1088 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1092 SalomePyQt::createSeparator
1093 Create a separator action which can be then used in the menu or toolbar.
1095 class TCreateSepEvent: public SALOME_Event {
1097 typedef QAction* TResult;
1101 virtual void Execute() {
1102 if ( SalomeApp_Application* anApp = getApplication() ) {
1103 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1105 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1107 myResult = module->createSeparator();
1111 QAction* SalomePyQt::createSeparator()
1113 return ProcessEvent( new TCreateSepEvent() );
1117 SalomePyQt::createAction
1118 Create an action which can be then used in the menu or toolbar:
1119 - id : the unique id action to be registered to;
1120 - menuText : action text which should appear in menu;
1121 - tipText : text which should appear in the tooltip;
1122 - statusText : text which should appear in the status bar when action is activated;
1123 - icon : the name of the icon file (the actual icon file name can be coded in the translation files);
1124 - key : the key accelrator for the action
1125 - toggle : if true the action is checkable
1127 class TCreateActionEvent: public SALOME_Event {
1129 typedef QAction* TResult;
1134 QString myStatusText;
1138 TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
1139 const QString& statusText, const QString& icon, const int key, const bool toggle )
1140 : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
1141 myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
1142 virtual void Execute() {
1143 if ( SalomeApp_Application* anApp = getApplication() ) {
1144 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1146 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1148 myResult = module->createAction( myId, myTipText, myIcon, myMenuText, myStatusText, myKey, myToggle );
1152 QAction* SalomePyQt::createAction( const int id, const QString& menuText,
1153 const QString& tipText, const QString& statusText,
1154 const QString& icon, const int key, const bool toggle )
1156 return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
1161 Get an action by its id. Returns 0 if the action with such id was not registered.
1163 class TActionEvent: public SALOME_Event {
1165 typedef QAction* TResult;
1168 TActionEvent( const int id )
1169 : myResult( 0 ), myId( id ) {}
1170 virtual void Execute() {
1171 if ( SalomeApp_Application* anApp = getApplication() ) {
1172 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1174 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1176 myResult = module->action( myId );
1180 QAction* SalomePyQt::action( const int id )
1182 return ProcessEvent( new TActionEvent( id ) );
1186 SalomePyQt::actionId
1187 Get an action id. Returns -1 if the action was not registered.
1189 class TActionIdEvent: public SALOME_Event {
1191 typedef int TResult;
1193 const QAction* myAction;
1194 TActionIdEvent( const QAction* action )
1195 : myResult( -1 ), myAction( action ) {}
1196 virtual void Execute() {
1197 if ( SalomeApp_Application* anApp = getApplication() ) {
1198 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1200 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1202 myResult = module->actionId( myAction );
1206 int SalomePyQt::actionId( const QAction* a )
1208 return ProcessEvent( new TActionIdEvent( a ) );