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>
17 #include <qstringlist.h>
19 #include "SALOME_Event.hxx"
21 #include "SUIT_Session.h"
22 #include "SUIT_Desktop.h"
23 #include "SUIT_ResourceMgr.h"
24 #include "SUIT_Tools.h"
25 #include "STD_MDIDesktop.h"
26 #include "SalomeApp_Application.h"
27 #include "SalomeApp_Study.h"
28 #include "SalomeApp_SelectionMgr.h"
29 #include "OB_Browser.h"
30 #include "QtxAction.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 //====================================================================================
61 static QMap<SalomeApp_Application*, SALOME_Selection*> SelMap;
64 SALOME_Selection::GetSelection
65 Creates or finds the selection object (one per study).
67 SALOME_Selection* SALOME_Selection::GetSelection( SalomeApp_Application* app )
69 SALOME_Selection* sel = 0;
70 if ( app && SelMap.find( app ) != SelMap.end() )
73 sel = SelMap[ app ] = new SALOME_Selection( app );
78 SALOME_Selection::SALOME_Selection
79 Selection constructor.
81 SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( p ), mySelMgr( 0 )
83 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( p );
85 mySelMgr = app->selectionMgr();
86 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SIGNAL( currentSelectionChanged() ) );
87 connect( mySelMgr, SIGNAL( destroyed() ), this, SLOT ( onSelMgrDestroyed() ) );
91 SALOME_Selection::~SALOME_Selection
92 Selection destructor. Removes selection object from the map.
94 SALOME_Selection::~SALOME_Selection()
96 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( parent() );
97 if ( app && SelMap.find( app ) != SelMap.end() )
102 SALOME_Selection::onSelMgrDestroyed
103 Watches for the selection manager destroying when study is closed.
105 void SALOME_Selection::onSelMgrDestroyed()
111 SALOME_Selection::Clear
112 Clears the selection.
114 void SALOME_Selection::Clear()
116 class TEvent: public SALOME_Event {
117 SalomeApp_SelectionMgr* mySelMgr;
119 TEvent( SalomeApp_SelectionMgr* selMgr )
120 : mySelMgr( selMgr ) {}
121 virtual void Execute() {
123 mySelMgr->clearSelected();
126 ProcessVoidEvent( new TEvent( mySelMgr ) );
130 SALOME_Selection::ClearIObjects
131 Clears the selection.
133 void SALOME_Selection::ClearIObjects()
139 SALOME_Selection::ClearFilters
140 Removes all selection filters.
142 void SALOME_Selection::ClearFilters()
144 class TEvent: public SALOME_Event {
145 SalomeApp_SelectionMgr* mySelMgr;
147 TEvent( SalomeApp_SelectionMgr* selMgr )
148 : mySelMgr( selMgr ) {}
149 virtual void Execute() {
151 mySelMgr->clearFilters();
154 ProcessVoidEvent( new TEvent( mySelMgr ) );
157 //====================================================================================
159 //====================================================================================
162 SalomePyQt::getDesktop
163 Gets desktop. Returns 0 in error.
165 class TGetDesktopEvent: public SALOME_Event {
167 typedef QWidget* TResult;
169 TGetDesktopEvent() : myResult( 0 ) {}
170 virtual void Execute() {
171 if ( getApplication() )
172 myResult = (QWidget*)( getApplication()->desktop() );
175 QWidget* SalomePyQt::getDesktop()
177 return ProcessEvent( new TGetDesktopEvent() );
181 SalomePyQt::getMainFrame
182 Gets workspace widget. Returns 0 in error.
184 class TGetMainFrameEvent: public SALOME_Event {
186 typedef QWidget* TResult;
188 TGetMainFrameEvent() : myResult( 0 ) {}
189 virtual void Execute() {
190 if ( getApplication() ) {
191 SUIT_Desktop* aDesktop = getApplication()->desktop();
192 myResult = (QWidget*)( aDesktop->centralWidget() );
196 QWidget* SalomePyQt::getMainFrame()
198 return ProcessEvent( new TGetMainFrameEvent() );
202 SalomePyQt::getMainMenuBar
203 Gets main menu. Returns 0 in error.
205 class TGetMainMenuBarEvent: public SALOME_Event {
207 typedef QMenuBar* TResult;
209 TGetMainMenuBarEvent() : myResult( 0 ) {}
210 virtual void Execute() {
211 if ( SalomeApp_Application* anApp = getApplication() ) {
212 myResult = anApp->desktop()->menuBar();
216 QMenuBar* SalomePyQt::getMainMenuBar()
218 return ProcessEvent( new TGetMainMenuBarEvent() );
222 SalomePyQt::getPopupMenu
223 Gets an main menu's child popup menu by its id
225 class TGetPopupMenuEvent: public SALOME_Event {
227 typedef QPopupMenu* TResult;
230 TGetPopupMenuEvent( const MenuName menu ) : myResult( 0 ), myMenuName( menu ) {}
231 virtual void Execute() {
232 if ( SalomeApp_Application* anApp = getApplication() ) {
233 QMenuBar* menuBar = anApp->desktop()->menuBar();
236 switch( myMenuName) {
238 menu = QObject::tr( "MEN_DESK_FILE" ); break;
240 menu = QObject::tr( "MEN_DESK_VIEW" ); break;
242 menu = QObject::tr( "MEN_DESK_EDIT" ); break;
244 menu = QObject::tr( "MEN_DESK_PREFERENCES" ); break;
246 menu = QObject::tr( "MEN_DESK_TOOLS" ); break;
248 menu = QObject::tr( "MEN_DESK_WINDOW" ); break;
250 menu = QObject::tr( "MEN_DESK_HELP" ); break;
252 for ( int i = 0; i < menuBar->count() && !myResult; i++ ) {
253 QMenuItem* item = menuBar->findItem( menuBar->idAt( i ) );
254 if ( item && item->text() == menu && item->popup() )
255 myResult = item->popup();
261 QPopupMenu* SalomePyQt::getPopupMenu( const MenuName menu )
263 return ProcessEvent( new TGetPopupMenuEvent( menu ) );
267 SalomePyQt::getStudyId
268 Returns active study's ID or 0 if there is no active study.
270 class TGetStudyIdEvent: public SALOME_Event {
274 TGetStudyIdEvent() : myResult( 0 ) {}
275 virtual void Execute() {
276 if ( SalomeApp_Study* aStudy = getActiveStudy() ) {
277 myResult = aStudy->studyDS()->StudyId();
281 int SalomePyQt::getStudyId()
283 return ProcessEvent( new TGetStudyIdEvent() );
287 SalomePyQt::getSelection
288 Creates a Selection object (to provide a compatibility with previous SALOME GUI).
290 class TGetSelectionEvent: public SALOME_Event {
292 typedef SALOME_Selection* TResult;
294 TGetSelectionEvent() : myResult( 0 ) {}
295 virtual void Execute() {
296 myResult = SALOME_Selection::GetSelection( getApplication() );
299 SALOME_Selection* SalomePyQt::getSelection()
301 return ProcessEvent( new TGetSelectionEvent() );
306 Puts an information message to the desktop's status bar
307 (with optional delay parameter given in seconds)
309 class TPutInfoEvent: public SALOME_Event {
313 TPutInfoEvent( const QString& msg, const int sec = 0 ) : myMsg( msg ), mySecs( sec ) {}
314 virtual void Execute() {
315 if ( SalomeApp_Application* anApp = getApplication() ) {
316 anApp->putInfo( myMsg, mySecs * 1000 );
320 void SalomePyQt::putInfo( const QString& msg, const int sec )
322 ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
326 SalomePyQt::getActiveComponent
327 Returns an active component name or empty string if there is no active component
329 class TGetActiveComponentEvent: public SALOME_Event {
331 typedef QString TResult;
333 TGetActiveComponentEvent() {}
334 virtual void Execute() {
335 if ( SalomeApp_Application* anApp = getApplication() ) {
336 if ( CAM_Module* mod = anApp->activeModule() ) {
337 myResult = mod->name("");
342 const QString SalomePyQt::getActiveComponent()
344 return ProcessEvent( new TGetActiveComponentEvent() );
348 SalomePyQt::updateObjBrowser
349 Updates an Object Browser of a given study.
350 If <studyId> <= 0 the active study's object browser is updated.
351 <updateSelection> parameter is obsolete parameter and currently not used. To be removed lately.
353 void SalomePyQt::updateObjBrowser( const int studyId, bool updateSelection )
355 class TEvent: public SALOME_Event {
357 bool myUpdateSelection;
359 TEvent( const int studyId, bool updateSelection )
360 : myStudyId( studyId ), myUpdateSelection( updateSelection ) {}
361 virtual void Execute() {
362 if ( SUIT_Session::session() ) {
363 if ( getActiveStudy() && myStudyId <= 0 )
364 myStudyId = getActiveStudy()->id();
365 if ( myStudyId > 0 ) {
366 QPtrList<SUIT_Application> apps = SUIT_Session::session()->applications();
367 QPtrListIterator<SUIT_Application> it( apps );
368 for( ; it.current(); ++it ) {
369 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( it.current() );
370 if ( anApp && anApp->activeStudy() && anApp->activeStudy()->id() == myStudyId )
371 anApp->updateObjectBrowser();
377 ProcessVoidEvent( new TEvent( studyId, updateSelection ) );
380 const char* DEFAULT_SECTION = "SalomePyQt";
383 SalomePyQt::addStringSetting
384 Adds a string setting to the application preferences
385 <autoValue> parameter is obsolete parameter and currently not used. To be removed lately.
386 This function is obsolete. Use addSetting() instead.
388 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
390 class TEvent: public SALOME_Event {
395 TEvent( const QString& name, const QString& value, bool autoValue )
396 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
397 virtual void Execute() {
398 if ( SUIT_Session::session() ) {
399 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
400 QStringList sl = QStringList::split( ":", myName );
401 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
402 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
403 if ( !_sec.isEmpty() && !_nam.isEmpty() )
404 resMgr->setValue( _sec, _nam, myValue );
408 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
412 SalomePyQt::addIntSetting
413 Adds an integer setting to the application preferences
414 <autoValue> parameter is obsolete parameter and currently not used. To be removed lately.
415 This function is obsolete. Use addSetting() instead.
417 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
419 class TEvent: public SALOME_Event {
424 TEvent( const QString& name, const int value, bool autoValue )
425 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
426 virtual void Execute() {
427 if ( SUIT_Session::session() ) {
428 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
429 QStringList sl = QStringList::split( ":", myName );
430 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
431 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
432 if ( !_sec.isEmpty() && !_nam.isEmpty() )
433 resMgr->setValue( _sec, _nam, myValue );
437 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
441 SalomePyQt::addDoubleSetting
442 Adds an double setting to the application preferences
443 <autoValue> parameter is obsolete parameter and currently not used. To be removed lately.
444 This function is obsolete. Use addSetting() instead.
446 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
448 class TEvent: public SALOME_Event {
453 TEvent( const QString& name, const double value, bool autoValue )
454 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
455 virtual void Execute() {
456 if ( SUIT_Session::session() ) {
457 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
458 QStringList sl = QStringList::split( ":", myName );
459 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
460 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
461 if ( !_sec.isEmpty() && !_nam.isEmpty() )
462 resMgr->setValue( _sec, _nam, myValue );
466 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
470 SalomePyQt::removeSettings
471 Removes a setting from the application preferences
472 This function is obsolete. Use removeSetting() instead.
474 void SalomePyQt::removeSettings( const QString& name )
476 class TEvent: public SALOME_Event {
479 TEvent( const QString& name ) : myName( name ) {}
480 virtual void Execute() {
481 if ( SUIT_Session::session() ) {
482 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
483 QStringList sl = QStringList::split( ":", myName );
484 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
485 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
486 if ( !_sec.isEmpty() && !_nam.isEmpty() )
487 resMgr->remove( _sec, _nam );
491 ProcessVoidEvent( new TEvent( name ) );
495 SalomePyQt::getSetting
496 Gets a setting value (as string)
497 This function is obsolete. Use stringSetting(), integerSetting(),
498 boolSetting(), stringSetting() or colorSetting() instead.
500 class TGetSettingEvent: public SALOME_Event {
502 typedef QString TResult;
505 TGetSettingEvent( const QString& name ) : myName( name ) {}
506 virtual void Execute() {
507 if ( SUIT_Session::session() ) {
508 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
509 QStringList sl = QStringList::split( ":", myName );
510 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
511 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
512 myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" );
516 QString SalomePyQt::getSetting( const QString& name )
518 return ProcessEvent( new TGetSettingEvent( name ) );
522 SalomePyQt::addSetting
523 Adds a double setting to the application preferences
525 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
527 class TEvent: public SALOME_Event {
532 TEvent( const QString& section, const QString& name, double value )
533 : mySection( section ), myName( name ), myValue( value ) {}
534 virtual void Execute() {
535 if ( SUIT_Session::session() ) {
536 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
537 if ( !mySection.isEmpty() && !myName.isEmpty() )
538 resMgr->setValue( mySection, myName, myValue );
542 ProcessVoidEvent( new TEvent( section, name, value ) );
546 SalomePyQt::addSetting
547 Adds an integer setting to the application preferences
549 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
551 class TEvent: public SALOME_Event {
556 TEvent( const QString& section, const QString& name, int value )
557 : mySection( section ), myName( name ), myValue( value ) {}
558 virtual void Execute() {
559 if ( SUIT_Session::session() ) {
560 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
561 if ( !mySection.isEmpty() && !myName.isEmpty() )
562 resMgr->setValue( mySection, myName, myValue );
566 ProcessVoidEvent( new TEvent( section, name, value ) );
570 SalomePyQt::addSetting
571 Adds a string setting to the application preferences
573 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
575 class TEvent: public SALOME_Event {
580 TEvent( const QString& section, const QString& name, const QString& value )
581 : mySection( section ), myName( name ), myValue( value ) {}
582 virtual void Execute() {
583 if ( SUIT_Session::session() ) {
584 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
585 if ( !mySection.isEmpty() && !myName.isEmpty() )
586 resMgr->setValue( mySection, myName, myValue );
590 ProcessVoidEvent( new TEvent( section, name, value ) );
594 SalomePyQt::addSetting
595 Adds a color setting to the application preferences
597 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
599 class TEvent: public SALOME_Event {
604 TEvent( const QString& section, const QString& name, const QColor& value )
605 : mySection( section ), myName( name ), myValue( value ) {}
606 virtual void Execute() {
607 if ( SUIT_Session::session() ) {
608 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
609 if ( !mySection.isEmpty() && !myName.isEmpty() )
610 resMgr->setValue( mySection, myName, myValue );
614 ProcessVoidEvent( new TEvent( section, name, value ) );
618 SalomePyQt::integerSetting
619 Gets an integer setting from the application preferences
621 class TGetIntSettingEvent: public SALOME_Event {
628 TGetIntSettingEvent( const QString& section, const QString& name, const int def )
629 : mySection( section ), myName( name ), myDefault( def ) {}
630 virtual void Execute() {
631 if ( SUIT_Session::session() ) {
632 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
633 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
637 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
639 return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
643 SalomePyQt::doubleSetting
644 Gets a double setting from the application preferences
646 class TGetDblSettingEvent: public SALOME_Event {
648 typedef double TResult;
653 TGetDblSettingEvent( const QString& section, const QString& name, const double def )
654 : mySection( section ), myName( name ), myDefault( def ) {}
655 virtual void Execute() {
656 if ( SUIT_Session::session() ) {
657 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
658 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
662 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const int def )
664 return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
668 SalomePyQt::boolSetting
669 Gets a boolean setting from the application preferences
671 class TGetBoolSettingEvent: public SALOME_Event {
673 typedef bool TResult;
678 TGetBoolSettingEvent( const QString& section, const QString& name, const bool def )
679 : mySection( section ), myName( name ), myDefault( def ) {}
680 virtual void Execute() {
681 if ( SUIT_Session::session() ) {
682 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
683 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
687 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
689 return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
693 SalomePyQt::stringSetting
694 Gets a string setting from the application preferences
696 class TGetStrSettingEvent: public SALOME_Event {
698 typedef QString TResult;
703 TGetStrSettingEvent( const QString& section, const QString& name, const QString& def )
704 : mySection( section ), myName( name ), myDefault( def ) {}
705 virtual void Execute() {
706 if ( SUIT_Session::session() ) {
707 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
708 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault ) : myDefault;
712 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def )
714 return ProcessEvent( new TGetStrSettingEvent( section, name, def ) );
718 SalomePyQt::colorSetting
719 Gets a color setting from the application preferences
721 class TGetColorSettingEvent: public SALOME_Event {
723 typedef QColor TResult;
728 TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def )
729 : mySection( section ), myName( name ), myDefault( def ) {}
730 virtual void Execute() {
731 if ( SUIT_Session::session() ) {
732 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
733 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
737 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
739 return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
743 SalomePyQt::removeSetting
744 Removes a setting from the application preferences
746 void SalomePyQt::removeSetting( const QString& section, const QString& name )
748 class TEvent: public SALOME_Event {
752 TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
753 virtual void Execute() {
754 if ( SUIT_Session::session() ) {
755 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
756 if ( !mySection.isEmpty() && !myName.isEmpty() )
757 resMgr->remove( mySection, myName );
761 ProcessVoidEvent( new TEvent( section, name ) );
765 SalomePyQt::getFileName
766 Displays 'Open/Save file' dialog box and returns a user's choice (file name)
768 class TGetFileNameEvent: public SALOME_Event {
770 typedef QString TResult;
774 QStringList myFilters;
777 TGetFileNameEvent( QWidget* parent,
778 const QString& initial,
779 const QStringList& filters,
780 const QString& caption,
782 : myParent ( parent ),
783 myInitial( initial ),
784 myFilters( filters ),
785 myCaption( caption ),
787 virtual void Execute() {
788 if ( SalomeApp_Application* anApp = getApplication() ) {
789 myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"), myCaption, myParent );
793 QString SalomePyQt::getFileName( QWidget* parent,
794 const QString& initial,
795 const QStringList& filters,
796 const QString& caption,
799 return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
803 SalomePyQt::getOpenFileNames
804 Displays 'Open files' dialog box and returns a user's choice (a list of file names)
806 class TGetOpenFileNamesEvent: public SALOME_Event {
808 typedef QStringList TResult;
812 QStringList myFilters;
814 TGetOpenFileNamesEvent( QWidget* parent,
815 const QString& initial,
816 const QStringList& filters,
817 const QString& caption )
818 : myParent ( parent ),
819 myInitial( initial ),
820 myFilters( filters ),
821 myCaption( caption ) {}
822 virtual void Execute() {
823 if ( SalomeApp_Application* anApp = getApplication() ) {
824 myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
828 QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
829 const QString& initial,
830 const QStringList& filters,
831 const QString& caption )
833 return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
837 SalomePyQt::getExistingDirectory
838 Displays 'Get Directory' dialog box and returns a user's choice (a directory name)
840 class TGetExistingDirectoryEvent: public SALOME_Event {
842 typedef QString TResult;
847 TGetExistingDirectoryEvent( QWidget* parent,
848 const QString& initial,
849 const QString& caption )
850 : myParent ( parent ),
851 myInitial( initial ),
852 myCaption( caption ) {}
853 virtual void Execute() {
854 if ( SalomeApp_Application* anApp = getApplication() ) {
855 myResult = anApp->getDirectory( myInitial, myCaption, myParent );
859 QString SalomePyQt::getExistingDirectory( QWidget* parent,
860 const QString& initial,
861 const QString& caption )
863 return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
867 SalomePyQt::helpContext
868 Opens external browser to display 'context help' information
869 current implementation does nothing.
871 void SalomePyQt::helpContext( const QString& source, const QString& context ) {
872 class TEvent: public SALOME_Event {
876 TEvent( const QString& source, const QString& context )
877 : mySource( source ), myContext( context ) {}
878 virtual void Execute() {
879 if ( /*SalomeApp_Application* anApp =*/ getApplication() ) {
881 // anApp->helpContext( mySource, myContext );
885 ProcessVoidEvent( new TEvent( source, context ) );
890 Dumps the contents of the currently active view to the image file
891 in the given format (JPEG, PNG, BMP are supported)
893 class TDumpViewEvent: public SALOME_Event {
895 typedef bool TResult;
898 TDumpViewEvent( const QString& filename )
899 : myResult ( false ), myFileName( filename ) {}
900 virtual void Execute() {
901 if ( SalomeApp_Application* anApp = getApplication() ) {
902 SUIT_ViewManager* vm = anApp->activeViewManager();
904 SUIT_ViewWindow* vw = vm->getActiveView();
906 QImage im = vw->dumpView();
907 if ( !im.isNull() && !myFileName.isEmpty() ) {
908 QString fmt = SUIT_Tools::extension( myFileName ).upper();
909 if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
910 if ( fmt == "JPG" ) fmt = "JPEG";
911 myResult = im.save( myFileName, fmt.latin1() );
918 bool SalomePyQt::dumpView( const QString& filename )
920 return ProcessEvent( new TDumpViewEvent( filename ) );
924 SalomePyQt::createTool
925 These methods allow operating with the toolbars:
926 - create a new toolbar or get the existing one (the toolbar name is passed as parameter);
927 this method returns an id of the toolbar;
928 - add action with given id (must be created previously) and optional index to the existing toolbar
929 (toobar is identified either by its id or by its name)
930 these methods return an id of the action.
931 If error occurs, the -1 value is returned.
936 CrTool( const QString& tBar )
937 : myCase( 0 ), myTbName( tBar ) {}
938 CrTool( const int id, const int tBar, const int idx )
939 : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
940 CrTool( const int id, const QString& tBar, const int idx )
941 : myCase( 2 ), myId( id ), myTbName( tBar ), myIndex( idx ) {}
942 CrTool( QtxAction* action, const int tbId, const int id, const int idx )
943 : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
944 CrTool( QtxAction* action, const QString& tBar, const int id, const int idx )
945 : myCase( 4 ), myAction( action ), myTbName( tBar ), myId( id ), myIndex( idx ) {}
947 int execute( SALOME_PYQT_Module* module ) const
952 return module->createTool( myTbName );
954 return module->createTool( myId, myTbId, myIndex );
956 return module->createTool( myId, myTbName, myIndex );
958 return module->createTool( myAction, myTbId, myId, myIndex );
960 return module->createTool( myAction, myTbName, myId, myIndex );
973 class TCreateToolEvent: public SALOME_Event {
977 const CrTool& myCrTool;
978 TCreateToolEvent( const CrTool& crTool )
979 : myResult( -1 ), myCrTool( crTool ) {}
980 virtual void Execute() {
981 if ( SalomeApp_Application* anApp = getApplication() ) {
982 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
984 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
985 myResult = myCrTool.execute( module );
989 // create new toolbar or get existing by name
990 int SalomePyQt::createTool( const QString& tBar )
992 return ProcessEvent( new TCreateToolEvent( CrTool( tBar ) ) );
994 // add action with id and index to the existing tollbar
995 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
997 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
999 // add action with id and index to the existing tollbar
1000 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
1002 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1004 // add action with id and index to the existing tollbar
1005 int SalomePyQt::createTool( QtxAction* a, const int tBar, const int id, const int idx )
1007 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1009 // add action with id and index to the existing tollbar
1010 int SalomePyQt::createTool( QtxAction* a, const QString& tBar, const int id, const int idx )
1012 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1016 SalomePyQt::createMenu
1017 These methods allow operating with the main menu:
1018 - create a new menu or submenu or get the existing one (the parent menu name or id is passed as parameter,
1019 if it is empty or -1, it means that main menu is created, otherwise submenu is created);
1020 this method returns an id of the menu/submenu;
1021 - add action with given id (must be created previously) and optional index and group number to the existing menu
1022 or submenu (menu name or id us passed as parameter)
1023 these methods return an id of the action.
1024 If error occurs, the -1 value is returned.
1029 CrMenu( const QString& subMenu, const int menu, const int group, const int idx )
1030 : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
1031 CrMenu( const QString& subMenu, const QString& menu, const int group, const int idx )
1032 : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
1033 CrMenu( const int id, const int menu, const int group, const int idx )
1034 : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
1035 CrMenu( const int id, const QString& menu, const int group, const int idx )
1036 : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
1037 CrMenu( QtxAction* action, const int menu, const int id, const int group, const int idx )
1038 : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1039 CrMenu( QtxAction* action, const QString& menu, const int id, const int group, const int idx )
1040 : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1042 int execute( SALOME_PYQT_Module* module ) const
1047 return module->createMenu( mySubMenuName, myMenuId, -1, myGroup, myIndex );
1049 return module->createMenu( mySubMenuName, myMenuName, -1, myGroup, myIndex );
1051 return module->createMenu( myId, myMenuId, myGroup, myIndex );
1053 return module->createMenu( myId, myMenuName, myGroup, myIndex );
1055 return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
1057 return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
1066 QString mySubMenuName;
1068 QtxAction* myAction;
1072 class TCreateMenuEvent: public SALOME_Event {
1074 typedef int TResult;
1076 const CrMenu& myCrMenu;
1077 TCreateMenuEvent( const CrMenu& crMenu )
1078 : myResult( -1 ), myCrMenu( crMenu ) {}
1079 virtual void Execute() {
1080 if ( SalomeApp_Application* anApp = getApplication() ) {
1081 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1083 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1084 myResult = myCrMenu.execute( module );
1088 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int group, const int idx )
1090 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, group, idx ) ) );
1093 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int group, const int idx )
1095 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, group, idx ) ) );
1098 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
1100 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1103 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
1105 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1108 int SalomePyQt::createMenu( QtxAction* a, const int menu, const int id, const int group, const int idx )
1110 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1113 int SalomePyQt::createMenu( QtxAction* a, const QString& menu, const int id, const int group, const int idx )
1115 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1119 SalomePyQt::createSeparator
1120 Create a separator action which can be then used in the menu or toolbar.
1122 class TCreateSepEvent: public SALOME_Event {
1124 typedef QtxAction* TResult;
1128 virtual void Execute() {
1129 if ( SalomeApp_Application* anApp = getApplication() ) {
1130 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1132 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1134 myResult = (QtxAction*)module->createSeparator();
1138 QtxAction* SalomePyQt::createSeparator()
1140 return ProcessEvent( new TCreateSepEvent() );
1144 SalomePyQt::createAction
1145 Create an action which can be then used in the menu or toolbar:
1146 - id : the unique id action to be registered to;
1147 - menuText : action text which should appear in menu;
1148 - tipText : text which should appear in the tooltip;
1149 - statusText : text which should appear in the status bar when action is activated;
1150 - icon : the name of the icon file (the actual icon file name can be coded in the translation files);
1151 - key : the key accelrator for the action
1152 - toggle : if true the action is checkable
1154 class TCreateActionEvent: public SALOME_Event {
1156 typedef QtxAction* TResult;
1161 QString myStatusText;
1165 TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
1166 const QString& statusText, const QString& icon, const int key, const bool toggle )
1167 : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
1168 myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
1169 virtual void Execute() {
1170 if ( SalomeApp_Application* anApp = getApplication() ) {
1171 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1173 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1175 myResult = (QtxAction*)module->createAction( myId, myTipText, myIcon, myMenuText, myStatusText, myKey, myToggle );
1179 QtxAction* SalomePyQt::createAction( const int id, const QString& menuText,
1180 const QString& tipText, const QString& statusText,
1181 const QString& icon, const int key, const bool toggle )
1183 return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
1188 Get an action by its id. Returns 0 if the action with such id was not registered.
1190 class TActionEvent: public SALOME_Event {
1192 typedef QtxAction* TResult;
1195 TActionEvent( const int id )
1196 : myResult( 0 ), myId( id ) {}
1197 virtual void Execute() {
1198 if ( SalomeApp_Application* anApp = getApplication() ) {
1199 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1201 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1203 myResult = (QtxAction*)module->action( myId );
1207 QtxAction* SalomePyQt::action( const int id )
1209 return ProcessEvent( new TActionEvent( id ) );
1213 SalomePyQt::actionId
1214 Get an action id. Returns -1 if the action was not registered.
1216 class TActionIdEvent: public SALOME_Event {
1218 typedef int TResult;
1220 const QtxAction* myAction;
1221 TActionIdEvent( const QtxAction* action )
1222 : myResult( -1 ), myAction( action ) {}
1223 virtual void Execute() {
1224 if ( SalomeApp_Application* anApp = getApplication() ) {
1225 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1227 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1229 myResult = module->actionId( myAction );
1233 int SalomePyQt::actionId( const QtxAction* a )
1235 return ProcessEvent( new TActionIdEvent( a ) );