1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SALOME_PYQT_Module.h" // this include must be first!!!
21 #include "SalomePyQt.h"
23 #include <qapplication.h>
26 #include <qpopupmenu.h>
28 #include <qstringlist.h>
30 #include "SALOME_Event.hxx"
32 #include "SUIT_Session.h"
33 #include "SUIT_Desktop.h"
34 #include "SUIT_ResourceMgr.h"
35 #include "SUIT_Tools.h"
36 #include "STD_MDIDesktop.h"
37 #include "SalomeApp_Application.h"
38 #include "SalomeApp_Study.h"
39 #include "LightApp_SelectionMgr.h"
40 #include "OB_Browser.h"
41 #include "QtxAction.h"
42 #include "LogWindow.h"
47 \return active application object [ static ]
49 static SalomeApp_Application* getApplication() {
50 if ( SUIT_Session::session() )
51 return dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
56 \return active study or 0 if there is no study opened [ static ]
58 static SalomeApp_Study* getActiveStudy()
60 if ( getApplication() )
61 return dynamic_cast<SalomeApp_Study*>( getApplication()->activeStudy() );
65 static QMap<SalomeApp_Application*, SALOME_Selection*> SelMap;
68 Creates or finds the selection object (one per study).
70 SALOME_Selection* SALOME_Selection::GetSelection( SalomeApp_Application* app )
72 SALOME_Selection* sel = 0;
73 if ( app && SelMap.find( app ) != SelMap.end() )
76 sel = SelMap[ app ] = new SALOME_Selection( app );
81 Selection constructor.
83 SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( p ), mySelMgr( 0 )
85 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( p );
87 mySelMgr = app->selectionMgr();
88 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SIGNAL( currentSelectionChanged() ) );
89 connect( mySelMgr, SIGNAL( destroyed() ), this, SLOT ( onSelMgrDestroyed() ) );
93 Selection destructor. Removes selection object from the map.
95 SALOME_Selection::~SALOME_Selection()
97 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( parent() );
98 if ( app && SelMap.find( app ) != SelMap.end() )
103 Watches for the selection manager destroying when study is closed.
105 void SALOME_Selection::onSelMgrDestroyed()
111 Clears the selection.
113 void SALOME_Selection::Clear()
115 class TEvent: public SALOME_Event {
116 LightApp_SelectionMgr* mySelMgr;
118 TEvent( LightApp_SelectionMgr* selMgr )
119 : mySelMgr( selMgr ) {}
120 virtual void Execute() {
122 mySelMgr->clearSelected();
125 ProcessVoidEvent( new TEvent( mySelMgr ) );
129 Clears the selection.
131 void SALOME_Selection::ClearIObjects()
137 Removes all selection filters.
139 void SALOME_Selection::ClearFilters()
141 class TEvent: public SALOME_Event {
142 LightApp_SelectionMgr* mySelMgr;
144 TEvent( LightApp_SelectionMgr* selMgr )
145 : mySelMgr( selMgr ) {}
146 virtual void Execute() {
148 mySelMgr->clearFilters();
151 ProcessVoidEvent( new TEvent( mySelMgr ) );
155 \return desktop (0 if error)
157 class TGetDesktopEvent: public SALOME_Event {
159 typedef QWidget* TResult;
161 TGetDesktopEvent() : myResult( 0 ) {}
162 virtual void Execute() {
163 if ( getApplication() )
164 myResult = (QWidget*)( getApplication()->desktop() );
171 QWidget* SalomePyQt::getDesktop()
173 return ProcessEvent( new TGetDesktopEvent() );
177 \return workspace widget (0 if error)
179 class TGetMainFrameEvent: public SALOME_Event {
181 typedef QWidget* TResult;
183 TGetMainFrameEvent() : myResult( 0 ) {}
184 virtual void Execute() {
185 if ( getApplication() ) {
186 SUIT_Desktop* aDesktop = getApplication()->desktop();
187 myResult = (QWidget*)( aDesktop->centralWidget() );
193 \return workspace widget (0 if error)
195 QWidget* SalomePyQt::getMainFrame()
197 return ProcessEvent( new TGetMainFrameEvent() );
201 SalomePyQt::getMainMenuBar
202 Gets main menu. Returns 0 in error.
204 class TGetMainMenuBarEvent: public SALOME_Event {
206 typedef QMenuBar* TResult;
208 TGetMainMenuBarEvent() : myResult( 0 ) {}
209 virtual void Execute() {
210 if ( SalomeApp_Application* anApp = getApplication() ) {
211 myResult = anApp->desktop()->menuBar();
220 QMenuBar* SalomePyQt::getMainMenuBar()
222 return ProcessEvent( new TGetMainMenuBarEvent() );
226 SalomePyQt::getPopupMenu
227 Gets an main menu's child popup menu by its id
229 class TGetPopupMenuEvent: public SALOME_Event {
231 typedef QPopupMenu* TResult;
234 TGetPopupMenuEvent( const MenuName menu ) : myResult( 0 ), myMenuName( menu ) {}
235 virtual void Execute() {
236 if ( SalomeApp_Application* anApp = getApplication() ) {
237 QMenuBar* menuBar = anApp->desktop()->menuBar();
240 switch( myMenuName) {
242 menu = QObject::tr( "MEN_DESK_FILE" ); break;
244 menu = QObject::tr( "MEN_DESK_VIEW" ); break;
246 menu = QObject::tr( "MEN_DESK_EDIT" ); break;
248 menu = QObject::tr( "MEN_DESK_PREFERENCES" ); break;
250 menu = QObject::tr( "MEN_DESK_TOOLS" ); break;
252 menu = QObject::tr( "MEN_DESK_WINDOW" ); break;
254 menu = QObject::tr( "MEN_DESK_HELP" ); break;
256 for ( int i = 0; i < menuBar->count() && !myResult; i++ ) {
257 QMenuItem* item = menuBar->findItem( menuBar->idAt( i ) );
258 if ( item && item->text() == menu && item->popup() )
259 myResult = item->popup();
268 \param menu - menu name
270 QPopupMenu* SalomePyQt::getPopupMenu( const MenuName menu )
272 return ProcessEvent( new TGetPopupMenuEvent( menu ) );
276 SalomePyQt::getStudyId
277 Returns active study's ID or 0 if there is no active study.
279 class TGetStudyIdEvent: public SALOME_Event {
283 TGetStudyIdEvent() : myResult( 0 ) {}
284 virtual void Execute() {
285 if ( SalomeApp_Study* aStudy = getActiveStudy() ) {
286 myResult = aStudy->studyDS()->StudyId();
292 SalomePyQt::getStudyId
293 Returns active study's ID or 0 if there is no active study.
295 int SalomePyQt::getStudyId()
297 return ProcessEvent( new TGetStudyIdEvent() );
301 SalomePyQt::getSelection
302 Creates a Selection object (to provide a compatibility with previous SALOME GUI).
304 class TGetSelectionEvent: public SALOME_Event {
306 typedef SALOME_Selection* TResult;
308 TGetSelectionEvent() : myResult( 0 ) {}
309 virtual void Execute() {
310 myResult = SALOME_Selection::GetSelection( getApplication() );
315 Creates a Selection object (to provide a compatibility with previous SALOME GUI).
316 \return just created selection object
318 SALOME_Selection* SalomePyQt::getSelection()
320 return ProcessEvent( new TGetSelectionEvent() );
325 Puts an information message to the desktop's status bar
326 (with optional delay parameter given in seconds)
328 class TPutInfoEvent: public SALOME_Event {
332 TPutInfoEvent( const QString& msg, const int sec = 0 ) : myMsg( msg ), mySecs( sec ) {}
333 virtual void Execute() {
334 if ( SalomeApp_Application* anApp = getApplication() ) {
335 anApp->putInfo( myMsg, mySecs * 1000 );
341 Puts an information message to the desktop's status bar
342 (with optional delay parameter given in seconds)
343 \param msg - message text
344 \param sec - delay in seconds
346 void SalomePyQt::putInfo( const QString& msg, const int sec )
348 ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
352 SalomePyQt::getActiveComponent
353 Returns an active component name or empty string if there is no active component
355 class TGetActiveComponentEvent: public SALOME_Event {
357 typedef QString TResult;
359 TGetActiveComponentEvent() {}
360 virtual void Execute() {
361 if ( SalomeApp_Application* anApp = getApplication() ) {
362 if ( CAM_Module* mod = anApp->activeModule() ) {
363 myResult = mod->name("");
370 \return an active component name or empty string if there is no active component
372 const QString SalomePyQt::getActiveComponent()
374 return ProcessEvent( new TGetActiveComponentEvent() );
378 SalomePyQt::updateObjBrowser
379 Updates an Object Browser of a given study.
380 If <studyId> <= 0 the active study's object browser is updated.
381 <updateSelection> parameter is obsolete parameter and currently not used. To be removed lately.
383 void SalomePyQt::updateObjBrowser( const int studyId, bool updateSelection )
385 class TEvent: public SALOME_Event {
387 bool myUpdateSelection;
389 TEvent( const int studyId, bool updateSelection )
390 : myStudyId( studyId ), myUpdateSelection( updateSelection ) {}
391 virtual void Execute() {
392 if ( SUIT_Session::session() ) {
393 if ( getActiveStudy() && myStudyId <= 0 )
394 myStudyId = getActiveStudy()->id();
395 if ( myStudyId > 0 ) {
396 QPtrList<SUIT_Application> apps = SUIT_Session::session()->applications();
397 QPtrListIterator<SUIT_Application> it( apps );
398 for( ; it.current(); ++it ) {
399 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( it.current() );
400 if ( anApp && anApp->activeStudy() && anApp->activeStudy()->id() == myStudyId )
401 anApp->updateObjectBrowser();
407 ProcessVoidEvent( new TEvent( studyId, updateSelection ) );
410 const char* DEFAULT_SECTION = "SalomePyQt";
413 SalomePyQt::addStringSetting
414 Adds a string setting to the application preferences
415 <autoValue> parameter is obsolete parameter and currently not used. To be removed lately.
416 This function is obsolete. Use addSetting() instead.
418 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
420 class TEvent: public SALOME_Event {
425 TEvent( const QString& name, const QString& value, bool autoValue )
426 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
427 virtual void Execute() {
428 if ( SUIT_Session::session() ) {
429 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
430 QStringList sl = QStringList::split( ":", myName );
431 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
432 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
433 if ( !_sec.isEmpty() && !_nam.isEmpty() )
434 resMgr->setValue( _sec, _nam, myValue );
438 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
442 SalomePyQt::addIntSetting
443 Adds an integer setting to the application preferences
444 <autoValue> parameter is obsolete parameter and currently not used. To be removed lately.
445 This function is obsolete. Use addSetting() instead.
447 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
449 class TEvent: public SALOME_Event {
454 TEvent( const QString& name, const int value, bool autoValue )
455 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
456 virtual void Execute() {
457 if ( SUIT_Session::session() ) {
458 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
459 QStringList sl = QStringList::split( ":", myName );
460 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
461 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
462 if ( !_sec.isEmpty() && !_nam.isEmpty() )
463 resMgr->setValue( _sec, _nam, myValue );
467 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
471 SalomePyQt::addDoubleSetting
472 Adds an double setting to the application preferences
473 <autoValue> parameter is obsolete parameter and currently not used. To be removed lately.
474 This function is obsolete. Use addSetting() instead.
476 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
478 class TEvent: public SALOME_Event {
483 TEvent( const QString& name, const double value, bool autoValue )
484 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
485 virtual void Execute() {
486 if ( SUIT_Session::session() ) {
487 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
488 QStringList sl = QStringList::split( ":", myName );
489 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
490 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
491 if ( !_sec.isEmpty() && !_nam.isEmpty() )
492 resMgr->setValue( _sec, _nam, myValue );
496 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
500 SalomePyQt::addBoolSetting
501 Adds an boolean setting to the application preferences
502 <autoValue> parameter is obsolete parameter and currently not used. To be removed lately.
503 This function is obsolete. Use addSetting() instead.
505 void SalomePyQt::addBoolSetting( const QString& name, const bool value, bool autoValue )
507 class TEvent: public SALOME_Event {
512 TEvent( const QString& name, const bool value, bool autoValue )
513 : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
514 virtual void Execute() {
515 if ( SUIT_Session::session() ) {
516 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
517 QStringList sl = QStringList::split( ":", myName );
518 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
519 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
520 if ( !_sec.isEmpty() && !_nam.isEmpty() )
521 resMgr->setValue( _sec, _nam, myValue );
525 ProcessVoidEvent( new TEvent( name, value, autoValue ) );
529 SalomePyQt::removeSettings
530 Removes a setting from the application preferences
531 This function is obsolete. Use removeSetting() instead.
533 void SalomePyQt::removeSettings( const QString& name )
535 class TEvent: public SALOME_Event {
538 TEvent( const QString& name ) : myName( name ) {}
539 virtual void Execute() {
540 if ( SUIT_Session::session() ) {
541 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
542 QStringList sl = QStringList::split( ":", myName );
543 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
544 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
545 if ( !_sec.isEmpty() && !_nam.isEmpty() )
546 resMgr->remove( _sec, _nam );
550 ProcessVoidEvent( new TEvent( name ) );
554 SalomePyQt::getSetting
555 Gets a setting value (as string)
556 This function is obsolete. Use stringSetting(), integerSetting(),
557 boolSetting(), stringSetting() or colorSetting() instead.
559 class TGetSettingEvent: public SALOME_Event {
561 typedef QString TResult;
564 TGetSettingEvent( const QString& name ) : myName( name ) {}
565 virtual void Execute() {
566 if ( SUIT_Session::session() ) {
567 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
568 QStringList sl = QStringList::split( ":", myName );
569 QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION );
570 QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" );
571 myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" );
577 \return a setting value (as string)
578 This function is obsolete. Use stringSetting(), integerSetting(),
579 boolSetting(), stringSetting() or colorSetting() instead.
581 QString SalomePyQt::getSetting( const QString& name )
583 return ProcessEvent( new TGetSettingEvent( name ) );
587 SalomePyQt::addSetting
588 Adds a double setting to the application preferences
590 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
592 class TEvent: public SALOME_Event {
597 TEvent( const QString& section, const QString& name, double value )
598 : mySection( section ), myName( name ), myValue( value ) {}
599 virtual void Execute() {
600 if ( SUIT_Session::session() ) {
601 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
602 if ( !mySection.isEmpty() && !myName.isEmpty() )
603 resMgr->setValue( mySection, myName, myValue );
607 ProcessVoidEvent( new TEvent( section, name, value ) );
611 SalomePyQt::addSetting
612 Adds an integer setting to the application preferences
614 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
616 class TEvent: public SALOME_Event {
621 TEvent( const QString& section, const QString& name, int value )
622 : mySection( section ), myName( name ), myValue( value ) {}
623 virtual void Execute() {
624 if ( SUIT_Session::session() ) {
625 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
626 if ( !mySection.isEmpty() && !myName.isEmpty() )
627 resMgr->setValue( mySection, myName, myValue );
631 ProcessVoidEvent( new TEvent( section, name, value ) );
635 SalomePyQt::addSetting
636 Adds a boolean setting to the application preferences
637 (note: the last "dumb" parameter is used in order to avoid
638 sip compilation error because of conflicting int and bool types)
640 void SalomePyQt::addSetting( const QString& section, const QString& name, const bool value, const int )
642 class TEvent: public SALOME_Event {
647 TEvent( const QString& section, const QString& name, bool value )
648 : mySection( section ), myName( name ), myValue( value ) {}
649 virtual void Execute() {
650 if ( SUIT_Session::session() ) {
651 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
652 if ( !mySection.isEmpty() && !myName.isEmpty() )
653 resMgr->setValue( mySection, myName, myValue );
657 ProcessVoidEvent( new TEvent( section, name, value ) );
661 SalomePyQt::addSetting
662 Adds a string setting to the application preferences
664 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
666 class TEvent: public SALOME_Event {
671 TEvent( const QString& section, const QString& name, const QString& value )
672 : mySection( section ), myName( name ), myValue( value ) {}
673 virtual void Execute() {
674 if ( SUIT_Session::session() ) {
675 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
676 if ( !mySection.isEmpty() && !myName.isEmpty() )
677 resMgr->setValue( mySection, myName, myValue );
681 ProcessVoidEvent( new TEvent( section, name, value ) );
685 SalomePyQt::addSetting
686 Adds a color setting to the application preferences
688 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
690 class TEvent: public SALOME_Event {
695 TEvent( const QString& section, const QString& name, const QColor& value )
696 : mySection( section ), myName( name ), myValue( value ) {}
697 virtual void Execute() {
698 if ( SUIT_Session::session() ) {
699 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
700 if ( !mySection.isEmpty() && !myName.isEmpty() )
701 resMgr->setValue( mySection, myName, myValue );
705 ProcessVoidEvent( new TEvent( section, name, value ) );
709 SalomePyQt::integerSetting
710 Gets an integer setting from the application preferences
712 class TGetIntSettingEvent: public SALOME_Event {
719 TGetIntSettingEvent( const QString& section, const QString& name, const int def )
720 : mySection( section ), myName( name ), myDefault( def ) {}
721 virtual void Execute() {
722 if ( SUIT_Session::session() ) {
723 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
724 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
730 \return an integer setting from the application preferences
732 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
734 return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
738 SalomePyQt::doubleSetting
739 Gets a double setting from the application preferences
741 class TGetDblSettingEvent: public SALOME_Event {
743 typedef double TResult;
748 TGetDblSettingEvent( const QString& section, const QString& name, const double def )
749 : mySection( section ), myName( name ), myDefault( def ) {}
750 virtual void Execute() {
751 if ( SUIT_Session::session() ) {
752 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
753 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
759 \return an double setting from the application preferences
761 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const double def )
763 return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
767 SalomePyQt::boolSetting
768 Gets a boolean setting from the application preferences
770 class TGetBoolSettingEvent: public SALOME_Event {
772 typedef bool TResult;
777 TGetBoolSettingEvent( const QString& section, const QString& name, const bool def )
778 : mySection( section ), myName( name ), myDefault( def ) {}
779 virtual void Execute() {
780 if ( SUIT_Session::session() ) {
781 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
782 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
788 \return an boolean setting from the application preferences
790 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
792 return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
796 SalomePyQt::stringSetting
797 Gets a string setting from the application preferences
799 class TGetStrSettingEvent: public SALOME_Event {
801 typedef QString TResult;
806 TGetStrSettingEvent( const QString& section, const QString& name, const QString& def )
807 : mySection( section ), myName( name ), myDefault( def ) {}
808 virtual void Execute() {
809 if ( SUIT_Session::session() ) {
810 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
811 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault ) : myDefault;
817 \return an string setting from the application preferences
819 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def )
821 return ProcessEvent( new TGetStrSettingEvent( section, name, def ) );
825 SalomePyQt::colorSetting
826 Gets a color setting from the application preferences
828 class TGetColorSettingEvent: public SALOME_Event {
830 typedef QColor TResult;
835 TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def )
836 : mySection( section ), myName( name ), myDefault( def ) {}
837 virtual void Execute() {
838 if ( SUIT_Session::session() ) {
839 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
840 myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
846 \return a color setting from the application preferences
848 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
850 return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
854 SalomePyQt::removeSetting
855 Removes a setting from the application preferences
857 void SalomePyQt::removeSetting( const QString& section, const QString& name )
859 class TEvent: public SALOME_Event {
863 TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
864 virtual void Execute() {
865 if ( SUIT_Session::session() ) {
866 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
867 if ( !mySection.isEmpty() && !myName.isEmpty() )
868 resMgr->remove( mySection, myName );
872 ProcessVoidEvent( new TEvent( section, name ) );
876 SalomePyQt::hasSetting
877 Returns True if the settings exists
879 class THasColorSettingEvent: public SALOME_Event {
881 typedef bool TResult;
885 THasColorSettingEvent( const QString& section, const QString& name )
886 : mySection( section ), myName( name ) {}
887 virtual void Execute() {
888 if ( SUIT_Session::session() ) {
889 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
890 myResult = resMgr->hasValue( mySection, myName );
894 bool SalomePyQt::hasSetting( const QString& section, const QString& name )
896 return ProcessEvent( new THasColorSettingEvent( section, name ) );
900 SalomePyQt::getFileName
901 Displays 'Open/Save file' dialog box and returns a user's choice (file name)
903 class TGetFileNameEvent: public SALOME_Event {
905 typedef QString TResult;
909 QStringList myFilters;
912 TGetFileNameEvent( QWidget* parent,
913 const QString& initial,
914 const QStringList& filters,
915 const QString& caption,
917 : myParent ( parent ),
918 myInitial( initial ),
919 myFilters( filters ),
920 myCaption( caption ),
922 virtual void Execute() {
923 if ( SalomeApp_Application* anApp = getApplication() ) {
924 myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"), myCaption, myParent );
930 Displays 'Open/Save file' dialog box and returns a user's choice (file name)
932 QString SalomePyQt::getFileName( QWidget* parent,
933 const QString& initial,
934 const QStringList& filters,
935 const QString& caption,
938 return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
942 SalomePyQt::getOpenFileNames
943 Displays 'Open files' dialog box and returns a user's choice (a list of file names)
945 class TGetOpenFileNamesEvent: public SALOME_Event {
947 typedef QStringList TResult;
951 QStringList myFilters;
953 TGetOpenFileNamesEvent( QWidget* parent,
954 const QString& initial,
955 const QStringList& filters,
956 const QString& caption )
957 : myParent ( parent ),
958 myInitial( initial ),
959 myFilters( filters ),
960 myCaption( caption ) {}
961 virtual void Execute() {
962 if ( SalomeApp_Application* anApp = getApplication() ) {
963 myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
969 Displays 'Open files' dialog box and returns a user's choice (a list of file names)
971 QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
972 const QString& initial,
973 const QStringList& filters,
974 const QString& caption )
976 return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
980 SalomePyQt::getExistingDirectory
981 Displays 'Get Directory' dialog box and returns a user's choice (a directory name)
983 class TGetExistingDirectoryEvent: public SALOME_Event {
985 typedef QString TResult;
990 TGetExistingDirectoryEvent( QWidget* parent,
991 const QString& initial,
992 const QString& caption )
993 : myParent ( parent ),
994 myInitial( initial ),
995 myCaption( caption ) {}
996 virtual void Execute() {
997 if ( SalomeApp_Application* anApp = getApplication() ) {
998 myResult = anApp->getDirectory( myInitial, myCaption, myParent );
1004 Displays 'Get Directory' dialog box and returns a user's choice (a directory name)
1006 QString SalomePyQt::getExistingDirectory( QWidget* parent,
1007 const QString& initial,
1008 const QString& caption )
1010 return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
1014 SalomePyQt::helpContext
1015 Opens external browser to display 'context help' information
1016 current implementation does nothing.
1018 void SalomePyQt::helpContext( const QString& source, const QString& context ) {
1019 class TEvent: public SALOME_Event {
1023 TEvent( const QString& source, const QString& context )
1024 : mySource( source ), myContext( context ) {}
1025 virtual void Execute() {
1026 if ( /*SalomeApp_Application* anApp =*/ getApplication() ) {
1028 // anApp->helpContext( mySource, myContext );
1032 ProcessVoidEvent( new TEvent( source, context ) );
1036 SalomePyQt::dumpView
1037 Dumps the contents of the currently active view to the image file
1038 in the given format (JPEG, PNG, BMP are supported)
1040 class TDumpViewEvent: public SALOME_Event {
1042 typedef bool TResult;
1045 TDumpViewEvent( const QString& filename )
1046 : myResult ( false ), myFileName( filename ) {}
1047 virtual void Execute() {
1048 if ( SalomeApp_Application* anApp = getApplication() ) {
1049 SUIT_ViewManager* vm = anApp->activeViewManager();
1051 SUIT_ViewWindow* vw = vm->getActiveView();
1053 QImage im = vw->dumpView();
1054 if ( !im.isNull() && !myFileName.isEmpty() ) {
1055 QString fmt = SUIT_Tools::extension( myFileName ).upper();
1056 if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
1057 if ( fmt == "JPG" ) fmt = "JPEG";
1058 myResult = im.save( myFileName, fmt.latin1() );
1067 Dumps the contents of the currently active view to the image file
1068 in the given format (JPEG, PNG, BMP are supported)
1070 bool SalomePyQt::dumpView( const QString& filename )
1072 return ProcessEvent( new TDumpViewEvent( filename ) );
1076 SalomePyQt::defaultMenuGroup
1077 Returns default menu group
1079 class TDefMenuGroupEvent: public SALOME_Event {
1081 typedef int TResult;
1083 TDefMenuGroupEvent() : myResult( -1 ) {}
1084 virtual void Execute() {
1085 myResult = SALOME_PYQT_Module::defaultMenuGroup();
1090 \return default menu group
1092 int SalomePyQt::defaultMenuGroup()
1094 return ProcessEvent( new TDefMenuGroupEvent() );
1098 SalomePyQt::createTool
1099 These methods allow operating with the toolbars:
1100 - create a new toolbar or get the existing one (the toolbar name is passed as parameter);
1101 this method returns an id of the toolbar;
1102 - add action with given id (must be created previously) and optional index to the existing toolbar
1103 (toobar is identified either by its id or by its name)
1104 these methods return an id of the action.
1105 If error occurs, the -1 value is returned.
1110 CrTool( const QString& tBar )
1111 : myCase( 0 ), myTbName( tBar ) {}
1112 CrTool( const int id, const int tBar, const int idx )
1113 : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
1114 CrTool( const int id, const QString& tBar, const int idx )
1115 : myCase( 2 ), myId( id ), myTbName( tBar ), myIndex( idx ) {}
1116 CrTool( QtxAction* action, const int tbId, const int id, const int idx )
1117 : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
1118 CrTool( QtxAction* action, const QString& tBar, const int id, const int idx )
1119 : myCase( 4 ), myAction( action ), myTbName( tBar ), myId( id ), myIndex( idx ) {}
1121 int execute( SALOME_PYQT_Module* module ) const
1126 return module->createTool( myTbName );
1128 return module->createTool( myId, myTbId, myIndex );
1130 return module->createTool( myId, myTbName, myIndex );
1132 return module->createTool( myAction, myTbId, myId, myIndex );
1134 return module->createTool( myAction, myTbName, myId, myIndex );
1143 QtxAction* myAction;
1147 class TCreateToolEvent: public SALOME_Event {
1149 typedef int TResult;
1151 const CrTool& myCrTool;
1152 TCreateToolEvent( const CrTool& crTool )
1153 : myResult( -1 ), myCrTool( crTool ) {}
1154 virtual void Execute() {
1155 if ( SalomeApp_Application* anApp = getApplication() ) {
1156 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1158 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1159 myResult = myCrTool.execute( module );
1165 create new toolbar or get existing by name
1167 int SalomePyQt::createTool( const QString& tBar )
1169 return ProcessEvent( new TCreateToolEvent( CrTool( tBar ) ) );
1171 /*! add action with id and index to the existing tollbar
1173 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
1175 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1177 /*! add action with id and index to the existing tollbar
1179 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
1181 return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
1183 /*! add action with id and index to the existing tollbar
1185 int SalomePyQt::createTool( QtxAction* a, const int tBar, const int id, const int idx )
1187 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1189 /*! add action with id and index to the existing tollbar
1191 int SalomePyQt::createTool( QtxAction* a, const QString& tBar, const int id, const int idx )
1193 return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
1197 SalomePyQt::createMenu
1198 These methods allow operating with the main menu:
1199 - create a new menu or submenu or get the existing one (the parent menu name or id is passed as parameter,
1200 if it is empty or -1, it means that main menu is created, otherwise submenu is created);
1201 this method returns an id of the menu/submenu;
1202 - add action with given id (must be created previously) and optional index and group number to the existing menu
1203 or submenu (menu name or id us passed as parameter)
1204 these methods return an id of the action.
1205 If error occurs, the -1 value is returned.
1210 CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1211 : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1212 CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1213 : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1214 CrMenu( const int id, const int menu, const int group, const int idx )
1215 : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
1216 CrMenu( const int id, const QString& menu, const int group, const int idx )
1217 : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
1218 CrMenu( QtxAction* action, const int menu, const int id, const int group, const int idx )
1219 : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1220 CrMenu( QtxAction* action, const QString& menu, const int id, const int group, const int idx )
1221 : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
1223 int execute( SALOME_PYQT_Module* module ) const
1228 return module->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
1230 return module->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
1232 return module->createMenu( myId, myMenuId, myGroup, myIndex );
1234 return module->createMenu( myId, myMenuName, myGroup, myIndex );
1236 return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
1238 return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
1247 QString mySubMenuName;
1249 QtxAction* myAction;
1253 class TCreateMenuEvent: public SALOME_Event {
1255 typedef int TResult;
1257 const CrMenu& myCrMenu;
1258 TCreateMenuEvent( const CrMenu& crMenu )
1259 : myResult( -1 ), myCrMenu( crMenu ) {}
1260 virtual void Execute() {
1261 if ( SalomeApp_Application* anApp = getApplication() ) {
1262 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1264 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1265 myResult = myCrMenu.execute( module );
1269 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
1271 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1274 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
1276 return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
1279 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
1281 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1284 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
1286 return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
1289 int SalomePyQt::createMenu( QtxAction* a, const int menu, const int id, const int group, const int idx )
1291 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1294 int SalomePyQt::createMenu( QtxAction* a, const QString& menu, const int id, const int group, const int idx )
1296 return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
1300 SalomePyQt::createSeparator
1301 Create a separator action which can be then used in the menu or toolbar.
1303 class TCreateSepEvent: public SALOME_Event {
1305 typedef QtxAction* TResult;
1309 virtual void Execute() {
1310 if ( SalomeApp_Application* anApp = getApplication() ) {
1311 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1313 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1315 myResult = (QtxAction*)module->createSeparator();
1319 QtxAction* SalomePyQt::createSeparator()
1321 return ProcessEvent( new TCreateSepEvent() );
1325 SalomePyQt::createAction
1326 Create an action which can be then used in the menu or toolbar:
1327 - id : the unique id action to be registered to;
1328 - menuText : action text which should appear in menu;
1329 - tipText : text which should appear in the tooltip;
1330 - statusText : text which should appear in the status bar when action is activated;
1331 - icon : the name of the icon file (the actual icon file name can be coded in the translation files);
1332 - key : the key accelrator for the action
1333 - toggle : if true the action is checkable
1335 class TCreateActionEvent: public SALOME_Event {
1337 typedef QtxAction* TResult;
1342 QString myStatusText;
1346 TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
1347 const QString& statusText, const QString& icon, const int key, const bool toggle )
1348 : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
1349 myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
1350 virtual void Execute() {
1351 if ( SalomeApp_Application* anApp = getApplication() ) {
1352 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1354 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1356 myResult = (QtxAction*)module->createAction( myId, myTipText, myIcon, myMenuText, myStatusText, myKey, myToggle );
1360 QtxAction* SalomePyQt::createAction( const int id, const QString& menuText,
1361 const QString& tipText, const QString& statusText,
1362 const QString& icon, const int key, const bool toggle )
1364 return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
1369 Get an action by its id. Returns 0 if the action with such id was not registered.
1371 class TActionEvent: public SALOME_Event {
1373 typedef QtxAction* TResult;
1376 TActionEvent( const int id )
1377 : myResult( 0 ), myId( id ) {}
1378 virtual void Execute() {
1379 if ( SalomeApp_Application* anApp = getApplication() ) {
1380 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1382 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1384 myResult = (QtxAction*)module->action( myId );
1388 QtxAction* SalomePyQt::action( const int id )
1390 return ProcessEvent( new TActionEvent( id ) );
1394 SalomePyQt::actionId
1395 Get an action id. Returns -1 if the action was not registered.
1397 class TActionIdEvent: public SALOME_Event {
1399 typedef int TResult;
1401 const QtxAction* myAction;
1402 TActionIdEvent( const QtxAction* action )
1403 : myResult( -1 ), myAction( action ) {}
1404 virtual void Execute() {
1405 if ( SalomeApp_Application* anApp = getApplication() ) {
1406 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1408 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1410 myResult = module->actionId( myAction );
1414 int SalomePyQt::actionId( const QtxAction* a )
1416 return ProcessEvent( new TActionIdEvent( a ) );
1420 SalomePyQt::clearMenu
1421 Clears given menu (recursively if necessary)
1423 class TClearMenuEvent: public SALOME_Event {
1425 typedef bool TResult;
1429 bool myRemoveActions;
1430 TClearMenuEvent( const int id, const int menu, const bool removeActions )
1431 : myResult( false ), myId( id ), myMenu( menu ), myRemoveActions( removeActions ) {}
1432 virtual void Execute() {
1433 if ( SalomeApp_Application* anApp = getApplication() ) {
1434 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1436 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1438 myResult = module->clearMenu( myId, myMenu, myRemoveActions );
1442 bool SalomePyQt::clearMenu( const int id, const int menu, const bool removeActions )
1444 return ProcessEvent( new TClearMenuEvent( id, menu, removeActions ) );
1448 SalomePyQt::addGlobalPreference
1449 Adds global (not module) preferences group
1451 class TAddGlobalPrefEvent: public SALOME_Event {
1453 typedef int TResult;
1456 TAddGlobalPrefEvent( const QString& label )
1457 : myResult( -1 ), myLabel( label ) {}
1458 virtual void Execute() {
1459 if ( SalomeApp_Application* anApp = getApplication() ) {
1460 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1462 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1464 myResult = module->addGlobalPreference( myLabel );
1468 int SalomePyQt::addGlobalPreference( const QString& label )
1470 return ProcessEvent( new TAddGlobalPrefEvent( label ) );
1474 SalomePyQt::addPreference
1477 class TAddPrefEvent: public SALOME_Event {
1479 typedef int TResult;
1482 TAddPrefEvent( const QString& label )
1483 : myResult( -1 ), myLabel( label ) {}
1484 virtual void Execute() {
1485 if ( SalomeApp_Application* anApp = getApplication() ) {
1486 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1488 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1490 myResult = module->addPreference( myLabel );
1494 int SalomePyQt::addPreference( const QString& label )
1496 return ProcessEvent( new TAddPrefEvent( label ) );
1500 SalomePyQt::addPreference
1503 class TAddPrefParamEvent: public SALOME_Event {
1505 typedef int TResult;
1512 TAddPrefParamEvent( const QString& label,
1513 const int pId, const int type,
1514 const QString& section,
1515 const QString& param )
1517 myLabel( label ), myPId( pId ), myType( type ),
1518 mySection( section ), myParam ( param ) {}
1519 virtual void Execute() {
1520 if ( SalomeApp_Application* anApp = getApplication() ) {
1521 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1523 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1525 myResult = module->addPreference( myLabel, myPId, myType, mySection, myParam );
1529 int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
1530 const QString& section, const QString& param )
1532 return ProcessEvent( new TAddPrefParamEvent( label, pId, type, section, param ) );
1536 SalomePyQt::preferenceProperty
1537 Gets the property value for the given (by id) preference
1539 class TPrefPropEvent: public SALOME_Event {
1541 typedef QVariant TResult;
1545 TPrefPropEvent( const int id, const QString& prop )
1546 : myId( id ), myProp( prop )
1548 myResult = QVariant();
1550 virtual void Execute() {
1551 if ( SalomeApp_Application* anApp = getApplication() ) {
1552 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1554 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1556 myResult = module->preferenceProperty( myId, myProp );
1560 QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop )
1562 return ProcessEvent( new TPrefPropEvent( id, prop ) );
1566 SalomePyQt::setPreferenceProperty
1567 Sets the property value for the given (by id) preference
1569 void SalomePyQt::setPreferenceProperty( const int id,
1570 const QString& prop,
1571 const QVariant& var )
1573 class TEvent: public SALOME_Event {
1578 TEvent( const int id, const QString& prop, const QVariant& var )
1579 : myId( id ), myProp( prop ), myVar( var ) {}
1580 virtual void Execute() {
1581 if ( SalomeApp_Application* anApp = getApplication() ) {
1582 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1584 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1586 module->setPreferenceProperty( myId, myProp, myVar );
1590 ProcessVoidEvent( new TEvent( id, prop, var) );
1594 SalomePyQt::addPreferenceProperty
1595 Adds the property value to the list of values
1596 for the given (by id) preference
1598 This method allows creating properties which are QValueList<QVariant>
1599 - there is no way to pass such values directly to QVariant parameter
1602 void SalomePyQt::addPreferenceProperty( const int id,
1603 const QString& prop,
1605 const QVariant& var )
1607 class TEvent: public SALOME_Event {
1613 TEvent( const int id, const QString& prop, const int idx, const QVariant& var )
1614 : myId( id ), myProp( prop ), myIdx( idx), myVar( var ) {}
1615 virtual void Execute() {
1616 if ( SalomeApp_Application* anApp = getApplication() ) {
1617 SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
1619 module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
1621 QVariant var = module->preferenceProperty( myId, myProp );
1622 if ( var.isValid() ) {
1623 if ( var.type() == QVariant::StringList ) {
1624 QStringList sl = var.asStringList();
1625 if ( myIdx >= 0 && myIdx < sl.count() )
1626 sl[myIdx] = myVar.asString();
1628 sl.append( myVar.asString() );
1629 module->setPreferenceProperty( myId, myProp, sl );
1631 else if ( var.type() == QVariant::List ) {
1632 QValueList<QVariant> vl = var.asList();
1633 if ( myIdx >= 0 && myIdx < vl.count() )
1637 module->setPreferenceProperty( myId, myProp, vl );
1641 QValueList<QVariant> vl;
1643 module->setPreferenceProperty( myId, myProp, vl );
1649 ProcessVoidEvent( new TEvent( id, prop, idx, var) );
1654 Puts the message to the Log output window
1656 void SalomePyQt::message( const QString& msg, bool addSeparator )
1658 class TEvent: public SALOME_Event {
1662 TEvent( const QString& msg, bool addSeparator )
1663 : myMsg( msg ), myAddSep( addSeparator ) {}
1664 virtual void Execute() {
1665 if ( SalomeApp_Application* anApp = getApplication() ) {
1666 LogWindow* lw = anApp->logWindow();
1668 lw->putMessage( myMsg, myAddSep );
1672 ProcessVoidEvent( new TEvent( msg, addSeparator ) );
1676 SalomePyQt::clearMessages
1677 Removes all the messages from the Log output window
1679 void SalomePyQt::clearMessages()
1681 class TEvent: public SALOME_Event {
1684 virtual void Execute() {
1685 if ( SalomeApp_Application* anApp = getApplication() ) {
1686 LogWindow* lw = anApp->logWindow();
1692 ProcessVoidEvent( new TEvent() );