1 //=============================================================================
2 // File : SalomePyQt.cxx
4 // Author : Vadim SANDLER
6 // Copyright : 2003-2005 CEA/DEN, EDF R&D
8 //=============================================================================
10 #include "SalomePyQt.h"
12 #include <qapplication.h>
14 #include <qstringlist.h>
16 #include "SALOME_Event.hxx"
18 #include "SUIT_Session.h"
19 #include "SUIT_Desktop.h"
20 #include "SUIT_ResourceMgr.h"
21 #include "SUIT_Tools.h"
22 #include "STD_MDIDesktop.h"
23 #include "SalomeApp_Application.h"
24 #include "SalomeApp_Study.h"
25 #include "SalomeApp_SelectionMgr.h"
26 #include "OB_Browser.h"
30 //====================================================================================
32 //====================================================================================
35 Returns active application object [ static ]
37 static SalomeApp_Application* getApplication() {
38 if ( SUIT_Session::session() )
39 return dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
45 Gets active study or 0 if there is no study opened [ static ]
47 static SalomeApp_Study* getActiveStudy()
49 if ( getApplication() )
50 return dynamic_cast<SalomeApp_Study*>( getApplication()->activeStudy() );
54 //====================================================================================
55 // SALOME_Selection class.
56 //====================================================================================
58 SALOME_Selection::SALOME_Selection
59 Selection constructor. Gets an instance of selection manager.
61 SALOME_Selection::SALOME_Selection() : mySelMgr( 0 )
63 if ( SalomeApp_Application* anApp = getApplication() ) {
64 mySelMgr = anApp->selectionMgr();
65 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SIGNAL( currentSelectionChanged() ) );
66 connect( mySelMgr, SIGNAL( destroyed() ), this, SLOT ( onSelMgrDestroyed() ) );
71 SALOME_Selection::onSelMgrDestroyed
72 Watches for the selection manager destroying when study is closed.
74 void SALOME_Selection::onSelMgrDestroyed()
80 SALOME_Selection::Clear
83 void SALOME_Selection::Clear()
85 class TEvent: public SALOME_Event {
86 SalomeApp_SelectionMgr* mySelMgr;
88 TEvent( SalomeApp_SelectionMgr* selMgr )
89 : mySelMgr( selMgr ) {}
90 virtual void Execute() {
92 mySelMgr->clearSelected();
95 ProcessVoidEvent( new TEvent( mySelMgr ) );
99 SALOME_Selection::ClearIObjects
100 Clears the selection.
102 void SALOME_Selection::ClearIObjects()
108 SALOME_Selection::ClearFilters
109 Removes all selection filters.
111 void SALOME_Selection::ClearFilters()
113 class TEvent: public SALOME_Event {
114 SalomeApp_SelectionMgr* mySelMgr;
116 TEvent( SalomeApp_SelectionMgr* selMgr )
117 : mySelMgr( selMgr ) {}
118 virtual void Execute() {
120 mySelMgr->clearFilters();
125 //====================================================================================
127 //====================================================================================
130 SalomePyQt::getDesktop
131 Gets desktop. Returns 0 in error.
133 class TGetDesktopEvent: public SALOME_Event {
135 typedef QWidget* TResult;
137 TGetDesktopEvent() : myResult( 0 ) {}
138 virtual void Execute() {
139 if ( getApplication() )
140 myResult = (QWidget*)( getApplication()->desktop() );
143 QWidget* SalomePyQt::getDesktop()
145 return ProcessEvent( new TGetDesktopEvent() );
149 SalomePyQt::getMainFrame
150 Gets workspace widget. Returns 0 in error.
152 class TGetMainFrameEvent: public SALOME_Event {
154 typedef QWidget* TResult;
156 TGetMainFrameEvent() : myResult( 0 ) {}
157 virtual void Execute() {
158 if ( getApplication() ) {
159 SUIT_Desktop* aDesktop = getApplication()->desktop();
160 myResult = (QWidget*)( aDesktop->centralWidget() );
164 QWidget* SalomePyQt::getMainFrame()
166 return ProcessEvent( new TGetMainFrameEvent() );
170 SalomePyQt::getMainMenuBar
171 Gets main menu. Returns 0 in error.
173 class TGetMainMenuBarEvent: public SALOME_Event {
175 typedef QMenuBar* TResult;
177 TGetMainMenuBarEvent() : myResult( 0 ) {}
178 virtual void Execute() {
179 if ( SalomeApp_Application* anApp = getApplication() ) {
180 myResult = anApp->desktop()->menuBar();
184 QMenuBar* SalomePyQt::getMainMenuBar()
186 return ProcessEvent( new TGetMainMenuBarEvent() );
190 SalomePyQt::getPopupMenu
191 Gets an main menu's child popup menu by its id
193 class TGetPopupMenuEvent: public SALOME_Event {
195 typedef QPopupMenu* TResult;
198 TGetPopupMenuEvent( const MenuName menu ) : myResult( 0 ), myMenuName( menu ) {}
199 virtual void Execute() {
200 if ( SalomeApp_Application* anApp = getApplication() ) {
201 QMenuBar* menuBar = anApp->desktop()->menuBar();
204 switch( myMenuName) {
206 menu = QObject::tr( "MEN_DESK_FILE" ); break;
208 menu = QObject::tr( "MEN_DESK_VIEW" ); break;
210 menu = QObject::tr( "MEN_DESK_EDIT" ); break;
212 menu = QObject::tr( "MEN_DESK_PREFERENCES" ); break;
214 menu = QObject::tr( "MEN_DESK_TOOLS" ); break;
216 menu = QObject::tr( "MEN_DESK_WINDOW" ); break;
218 menu = QObject::tr( "MEN_DESK_HELP" ); break;
220 for ( int i = 0; i < menuBar->count() && !myResult; i++ ) {
221 QMenuItem* item = menuBar->findItem( menuBar->idAt( i ) );
222 if ( item && item->text() == menu && item->popup() )
223 myResult = item->popup();
229 QPopupMenu* SalomePyQt::getPopupMenu( const MenuName menu )
231 return ProcessEvent( new TGetPopupMenuEvent( menu ) );
235 SalomePyQt::getStudyId
236 Returns active study's ID or 0 if there is no active study.
238 class TGetStudyIdEvent: public SALOME_Event {
242 TGetStudyIdEvent() : myResult( 0 ) {}
243 virtual void Execute() {
244 if ( SalomeApp_Study* aStudy = getActiveStudy() ) {
245 myResult = aStudy->studyDS()->StudyId();
249 int SalomePyQt::getStudyId()
251 return ProcessEvent( new TGetStudyIdEvent() );
255 SalomePyQt::getSelection
256 Creates a Selection object (to provide a compatibility with previous SALOME GUI).
258 class TGetSelectionEvent: public SALOME_Event {
260 typedef SALOME_Selection* TResult;
262 TGetSelectionEvent() : myResult( 0 ) {}
263 virtual void Execute() {
264 myResult = new SALOME_Selection();
267 SALOME_Selection* SalomePyQt::getSelection()
269 return ProcessEvent( new TGetSelectionEvent() );
274 Puts an information message to the desktop's status bar
275 (with optional delay parameter given in seconds)
277 class TPutInfoEvent: public SALOME_Event {
281 TPutInfoEvent( const QString& msg, const int sec = 0 ) : myMsg( msg ), mySecs( sec ) {}
282 virtual void Execute() {
283 if ( SalomeApp_Application* anApp = getApplication() ) {
284 anApp->putInfo( myMsg, mySecs * 1000 );
288 void SalomePyQt::putInfo( const QString& msg, const int sec )
290 ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
294 SalomePyQt::getActiveComponent
295 Returns an active component name or empty string if there is no active component
297 class TGetActiveComponentEvent: public SALOME_Event {
299 typedef QString TResult;
301 TGetActiveComponentEvent() {}
302 virtual void Execute() {
303 if ( SalomeApp_Application* anApp = getApplication() ) {
304 if ( CAM_Module* mod = anApp->activeModule() ) {
305 myResult = mod->name("");
310 const QString SalomePyQt::getActiveComponent()
312 return ProcessEvent( new TGetActiveComponentEvent() );
316 SalomePyQt::updateObjBrowser
317 Updates an Object Browser of a given study.
318 If <studyId> <= 0 the active study's object browser is updated.
319 <updateSelection> parameter is obsolete parameter and currently not used. To be removed lately.
321 void SalomePyQt::updateObjBrowser( const int studyId, bool updateSelection )
323 class TEvent: public SALOME_Event {
325 bool myUpdateSelection;
327 TEvent( const int studyId, bool updateSelection )
328 : myStudyId( studyId ), myUpdateSelection( updateSelection ) {}
329 virtual void Execute() {
330 if ( SUIT_Session::session() ) {
331 if ( getActiveStudy() && myStudyId <= 0 )
332 myStudyId = getActiveStudy()->id();
333 if ( myStudyId > 0 ) {
334 QPtrList<SUIT_Application> apps = SUIT_Session::session()->applications();
335 QPtrListIterator<SUIT_Application> it( apps );
336 for( ; it.current(); ++it ) {
337 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( it.current() );
338 if ( anApp && anApp->activeStudy() && anApp->activeStudy()->id() == myStudyId )
339 anApp->updateObjectBrowser();
345 ProcessVoidEvent( new TEvent( studyId, updateSelection ) );
348 const char* DEFAULT_SECTION = "SalomePyQt";
351 SalomePyQt::addStringSetting
352 Adds a string setting to the application preferences
353 <autoValue> parameter is obsolete parameter and currently not used. To be removed lately.
354 This function is obsolete. Use addSetting() instead.
356 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
358 class TEvent: public SALOME_Event {
363 TEvent( const QString& name, const QString& value, bool autoValue )
364 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
365 virtual void Execute() {
366 if ( SUIT_Session::session() ) {
367 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
368 QStringList sl = QStringList::split( ":", myName );
369 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
370 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
371 if ( !_sec.isEmpty() && !_nam.isEmpty() )
372 resMgr->setValue( _sec, _nam, myValue );
376 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
380 SalomePyQt::addIntSetting
381 Adds an integer setting to the application preferences
382 <autoValue> parameter is obsolete parameter and currently not used. To be removed lately.
383 This function is obsolete. Use addSetting() instead.
385 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
387 class TEvent: public SALOME_Event {
392 TEvent( const QString& name, const int value, bool autoValue )
393 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
394 virtual void Execute() {
395 if ( SUIT_Session::session() ) {
396 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
397 QStringList sl = QStringList::split( ":", myName );
398 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
399 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
400 if ( !_sec.isEmpty() && !_nam.isEmpty() )
401 resMgr->setValue( _sec, _nam, myValue );
405 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
409 SalomePyQt::addDoubleSetting
410 Adds an double setting to the application preferences
411 <autoValue> parameter is obsolete parameter and currently not used. To be removed lately.
412 This function is obsolete. Use addSetting() instead.
414 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
416 class TEvent: public SALOME_Event {
421 TEvent( const QString& name, const double value, bool autoValue )
422 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
423 virtual void Execute() {
424 if ( SUIT_Session::session() ) {
425 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
426 QStringList sl = QStringList::split( ":", myName );
427 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
428 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
429 if ( !_sec.isEmpty() && !_nam.isEmpty() )
430 resMgr->setValue( _sec, _nam, myValue );
434 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
438 SalomePyQt::removeSettings
439 Removes a setting from the application preferences
440 This function is obsolete. Use removeSetting() instead.
442 void SalomePyQt::removeSettings( const QString& name )
444 class TEvent: public SALOME_Event {
447 TEvent( const QString& name ) : myName( name ) {}
448 virtual void Execute() {
449 if ( SUIT_Session::session() ) {
450 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
451 QStringList sl = QStringList::split( ":", myName );
452 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
453 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
454 if ( !_sec.isEmpty() && !_nam.isEmpty() )
455 resMgr->remove( _sec, _nam );
459 ProcessVoidEvent( new TEvent( name ) );
463 SalomePyQt::getSetting
464 Gets a setting value (as string)
465 This function is obsolete. Use stringSetting(), integerSetting(),
466 boolSetting(), stringSetting() or colorSetting() instead.
468 class TGetSettingEvent: public SALOME_Event {
470 typedef QString TResult;
473 TGetSettingEvent( const QString& name ) : myName( name ) {}
474 virtual void Execute() {
475 if ( SUIT_Session::session() ) {
476 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
477 QStringList sl = QStringList::split( ":", myName );
478 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
479 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
480 myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" );
484 QString SalomePyQt::getSetting( const QString& name )
486 return ProcessEvent( new TGetSettingEvent( name ) );
490 SalomePyQt::addSetting
491 Adds a double setting to the application preferences
493 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
495 class TEvent: public SALOME_Event {
500 TEvent( const QString& section, const QString& name, double value )
501 : mySection( section ), myName( name ), myValue( value ) {}
502 virtual void Execute() {
503 if ( SUIT_Session::session() ) {
504 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
505 if ( !mySection.isEmpty() && !myName.isEmpty() )
506 resMgr->setValue( mySection, myName, myValue );
510 ProcessVoidEvent( new TEvent( section, name, value ) );
514 SalomePyQt::addSetting
515 Adds an integer setting to the application preferences
517 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
519 class TEvent: public SALOME_Event {
524 TEvent( const QString& section, const QString& name, int value )
525 : mySection( section ), myName( name ), myValue( value ) {}
526 virtual void Execute() {
527 if ( SUIT_Session::session() ) {
528 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
529 if ( !mySection.isEmpty() && !myName.isEmpty() )
530 resMgr->setValue( mySection, myName, myValue );
534 ProcessVoidEvent( new TEvent( section, name, value ) );
538 SalomePyQt::addSetting
539 Adds a string setting to the application preferences
541 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
543 class TEvent: public SALOME_Event {
548 TEvent( const QString& section, const QString& name, const QString& value )
549 : mySection( section ), myName( name ), myValue( value ) {}
550 virtual void Execute() {
551 if ( SUIT_Session::session() ) {
552 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
553 if ( !mySection.isEmpty() && !myName.isEmpty() )
554 resMgr->setValue( mySection, myName, myValue );
558 ProcessVoidEvent( new TEvent( section, name, value ) );
562 SalomePyQt::addSetting
563 Adds a color setting to the application preferences
565 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
567 class TEvent: public SALOME_Event {
572 TEvent( const QString& section, const QString& name, const QColor& value )
573 : mySection( section ), myName( name ), myValue( value ) {}
574 virtual void Execute() {
575 if ( SUIT_Session::session() ) {
576 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
577 if ( !mySection.isEmpty() && !myName.isEmpty() )
578 resMgr->setValue( mySection, myName, myValue );
582 ProcessVoidEvent( new TEvent( section, name, value ) );
586 SalomePyQt::integerSetting
587 Gets an integer setting from the application preferences
589 class TGetIntSettingEvent: public SALOME_Event {
596 TGetIntSettingEvent( const QString& section, const QString& name, const int def )
597 : mySection( section ), myName( name ), myDefault( def ) {}
598 virtual void Execute() {
599 if ( SUIT_Session::session() ) {
600 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
601 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
605 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
607 return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
611 SalomePyQt::doubleSetting
612 Gets a double setting from the application preferences
614 class TGetDblSettingEvent: public SALOME_Event {
616 typedef double TResult;
621 TGetDblSettingEvent( const QString& section, const QString& name, const double def )
622 : mySection( section ), myName( name ), myDefault( def ) {}
623 virtual void Execute() {
624 if ( SUIT_Session::session() ) {
625 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
626 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
630 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const int def )
632 return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
636 SalomePyQt::boolSetting
637 Gets a boolean setting from the application preferences
639 class TGetBoolSettingEvent: public SALOME_Event {
641 typedef bool TResult;
646 TGetBoolSettingEvent( const QString& section, const QString& name, const bool def )
647 : mySection( section ), myName( name ), myDefault( def ) {}
648 virtual void Execute() {
649 if ( SUIT_Session::session() ) {
650 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
651 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
655 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
657 return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
661 SalomePyQt::stringSetting
662 Gets a string setting from the application preferences
664 class TGetStrSettingEvent: public SALOME_Event {
666 typedef QString TResult;
671 TGetStrSettingEvent( const QString& section, const QString& name, const QString& def )
672 : mySection( section ), myName( name ), myDefault( def ) {}
673 virtual void Execute() {
674 if ( SUIT_Session::session() ) {
675 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
676 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault ) : myDefault;
680 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def )
682 return ProcessEvent( new TGetStrSettingEvent( section, name, def ) );
686 SalomePyQt::colorSetting
687 Gets a color setting from the application preferences
689 class TGetColorSettingEvent: public SALOME_Event {
691 typedef QColor TResult;
696 TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def )
697 : mySection( section ), myName( name ), myDefault( def ) {}
698 virtual void Execute() {
699 if ( SUIT_Session::session() ) {
700 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
701 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
705 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
707 return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
711 SalomePyQt::removeSetting
712 Removes a setting from the application preferences
714 void SalomePyQt::removeSetting( const QString& section, const QString& name )
716 class TEvent: public SALOME_Event {
720 TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
721 virtual void Execute() {
722 if ( SUIT_Session::session() ) {
723 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
724 if ( !mySection.isEmpty() && !myName.isEmpty() )
725 resMgr->remove( mySection, myName );
729 ProcessVoidEvent( new TEvent( section, name ) );
733 SalomePyQt::getFileName
734 Displays 'Open/Save file' dialog box and returns a user's choice (file name)
736 class TGetFileNameEvent: public SALOME_Event {
738 typedef QString TResult;
742 QStringList myFilters;
745 TGetFileNameEvent( QWidget* parent,
746 const QString& initial,
747 const QStringList& filters,
748 const QString& caption,
750 : myParent ( parent ),
751 myInitial( initial ),
752 myFilters( filters ),
753 myCaption( caption ),
755 virtual void Execute() {
756 if ( SalomeApp_Application* anApp = getApplication() ) {
757 myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"), myCaption, myParent );
761 QString SalomePyQt::getFileName( QWidget* parent,
762 const QString& initial,
763 const QStringList& filters,
764 const QString& caption,
767 return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
771 SalomePyQt::getOpenFileNames
772 Displays 'Open files' dialog box and returns a user's choice (a list of file names)
774 class TGetOpenFileNamesEvent: public SALOME_Event {
776 typedef QStringList TResult;
780 QStringList myFilters;
782 TGetOpenFileNamesEvent( QWidget* parent,
783 const QString& initial,
784 const QStringList& filters,
785 const QString& caption )
786 : myParent ( parent ),
787 myInitial( initial ),
788 myFilters( filters ),
789 myCaption( caption ) {}
790 virtual void Execute() {
791 if ( SalomeApp_Application* anApp = getApplication() ) {
792 myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
796 QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
797 const QString& initial,
798 const QStringList& filters,
799 const QString& caption )
801 return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
805 SalomePyQt::getExistingDirectory
806 Displays 'Get Directory' dialog box and returns a user's choice (a directory name)
808 class TGetExistingDirectoryEvent: public SALOME_Event {
810 typedef QString TResult;
815 TGetExistingDirectoryEvent( QWidget* parent,
816 const QString& initial,
817 const QString& caption )
818 : myParent ( parent ),
819 myInitial( initial ),
820 myCaption( caption ) {}
821 virtual void Execute() {
822 if ( SalomeApp_Application* anApp = getApplication() ) {
823 myResult = anApp->getDirectory( myInitial, myCaption, myParent );
827 QString SalomePyQt::getExistingDirectory( QWidget* parent,
828 const QString& initial,
829 const QString& caption )
831 return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
835 SalomePyQt::helpContext
836 Opens external browser to display 'context help' information
837 current implementation does nothing.
839 void SalomePyQt::helpContext( const QString& source, const QString& context ) {
840 class TEvent: public SALOME_Event {
844 TEvent( const QString& source, const QString& context )
845 : mySource( source ), myContext( context ) {}
846 virtual void Execute() {
847 if ( /*SalomeApp_Application* anApp =*/ getApplication() ) {
849 // anApp->helpContext( mySource, myContext );
853 ProcessVoidEvent( new TEvent( source, context ) );
858 Dumps the contents of the currently active view to the image file
859 in the given format (JPEG, PNG, BMP are supported)
861 class TDumpViewEvent: public SALOME_Event {
863 typedef bool TResult;
866 TDumpViewEvent( const QString& filename )
867 : myResult ( false ), myFileName( filename ) {}
868 virtual void Execute() {
869 if ( SalomeApp_Application* anApp = getApplication() ) {
870 SUIT_ViewManager* vm = anApp->activeViewManager();
872 SUIT_ViewWindow* vw = vm->getActiveView();
874 QImage im = vw->dumpView();
875 if ( !im.isNull() && !myFileName.isEmpty() ) {
876 QString fmt = SUIT_Tools::extension( myFileName ).upper();
877 if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
878 if ( fmt == "JPG" ) fmt = "JPEG";
879 myResult = im.save( myFileName, fmt.latin1() );
886 bool SalomePyQt::dumpView( const QString& filename )
888 return ProcessEvent( new TDumpViewEvent( filename ) );