#include "STD_TabDesktop.h"
#include "SalomeApp_Application.h"
#include "SalomeApp_Study.h"
-#include "SalomeApp_DataModel.h"
#include "QtxWorkstack.h"
#include <SALOME_LifeCycleCORBA.hxx>
#include <sipqtQWidget.h>
#include <sipqtQPopupMenu.h>
+#include <CORBA.h>
+
using namespace std;
// Default name of the module, should be replaced at the moment
//=============================================================================
-//=============================================================================
-// The default PyQt module data model.
-// Reuses common data model from SalomeApp.
-//=============================================================================
-class SALOME_PYQT_DataModel: public SalomeApp_DataModel
-{
-public:
- SALOME_PYQT_DataModel( CAM_Module* theModule ) : SalomeApp_DataModel( theModule ) {}
- bool isModified() const { return false; }
- bool isSaved() const { return false; }
-};
-
//=============================================================================
// The class for parsing of the XML resource files.
// Used for backward compatibility with existing Python modules.
* Static variables definition
*/
SALOME_PYQT_Module::InterpMap SALOME_PYQT_Module::myInterpMap;
+SALOME_PYQT_Module* SALOME_PYQT_Module::myInitModule = 0;
+
+/*!
+ * Little trick : provide an access to being activated Python module from outside;
+ * needed by the SalomePyQt library :(
+*/
+SALOME_PYQT_Module* SALOME_PYQT_Module::getInitModule()
+{
+ return myInitModule;
+}
/*!
* Constructor
delete myXmlHandler;
}
-/*!
- * Creates data model for the module.
- * Reimplemented from CAM_Module.
- */
-CAM_DataModel* SALOME_PYQT_Module::createDataModel()
-{
- // VSR: this is a temporary solution :
- // should reuse default data model from SalomeApp
- return new SALOME_PYQT_DataModel( this );
-}
-
/*!
* Initialization of the module.
* Inherited from CAM_Module.
if ( !res )
return res;
- // activate menus, toolbars, etc
- setMenuShown( true );
- setToolShown( true );
-
// ActivateReq: request class for internal activate() operation
class ActivateReq : public PyInterp_Request
{
// Posting the request
PyInterp_Dispatcher::Get()->Exec( new ActivateReq( theStudy, this ) );
- // connect desktop activation signal
- connect( application()->desktop(), SIGNAL( activated() ), this, SLOT( onDesktopActivated() ) );
-
+ // activate menus, toolbars, etc
+ setMenuShown( true );
+ setToolShown( true );
+
return true;
}
// Posting the request
PyInterp_Dispatcher::Get()->Exec( new DeactivateReq( myInterp, theStudy, this ) );
- // disconnect desktop activation signal
- disconnect( application()->desktop(), SIGNAL( activated() ), this, SLOT( onDesktopActivated() ) );
-
return res;
}
PyInterp_Dispatcher::Get()->Exec( new GUIEvent( myInterp, this, id ) );
}
-/*!
- * Desktop activation slot. Used for notifying about changing of the active study.
- */
-void SALOME_PYQT_Module::onDesktopActivated()
-{
- // StudyChangedReq: request class for internal studyChanged() operation
- class StudyChangedReq : public PyInterp_Request
- {
- public:
- StudyChangedReq( SUIT_Study* _study,
- SALOME_PYQT_Module* _obj )
- : PyInterp_Request( 0, true ), // this request should be processed synchronously (sync == true)
- myStudy ( _study ),
- myObj ( _obj ) {}
-
- protected:
- virtual void execute()
- {
- myObj->studyChanged( myStudy );
- }
-
- private:
- SUIT_Study* myStudy;
- SALOME_PYQT_Module* myObj;
- };
-
- // Posting the request
- PyInterp_Dispatcher::Get()->Exec( new StudyChangedReq( application()->activeStudy(), this ) );
-}
-
/*!
Context popup menu request.
Called when user activates popup menu in some window (view, object browser, etc).
if ( !myModule )
return; // Error
+ myInitModule = this;
+
#ifdef __CALL_OLD_METHODS__
// call Python module's setWorkspace() method
setWorkSpace();
}
}
}
+ myInitModule = 0;
}
/*!
*/
Engines::Component_var SALOME_PYQT_Module::getEngine() const
{
- Engines::Component_var comp = getApp()->lcc()->FindOrLoad_Component( "FactoryServerPy", name( "" ) );
+ Engines::Component_var comp;
+ // temporary solution
+ try {
+ comp = getApp()->lcc()->FindOrLoad_Component( "FactoryServerPy", name( "" ) );
+ }
+ catch (CORBA::Exception&) {
+ }
return comp;
}
return QString( "" );
}
+/*!
+ * Called when study desktop is activated.
+ * Used for notifying about changing of the active study.
+ */
+void SALOME_PYQT_Module::studyActivated()
+{
+ // StudyChangedReq: request class for internal studyChanged() operation
+ class StudyChangedReq : public PyInterp_Request
+ {
+ public:
+ StudyChangedReq( SUIT_Study* _study,
+ SALOME_PYQT_Module* _obj )
+ : PyInterp_Request( 0, true ), // this request should be processed synchronously (sync == true)
+ myStudy ( _study ),
+ myObj ( _obj ) {}
+
+ protected:
+ virtual void execute()
+ {
+ myObj->studyChanged( myStudy );
+ }
+
+ private:
+ SUIT_Study* myStudy;
+ SALOME_PYQT_Module* myObj;
+ };
+
+ // Posting the request
+ PyInterp_Dispatcher::Get()->Exec( new StudyChangedReq( application()->activeStudy(), this ) );
+}
+
/*!
* Processes context popup menu request
* - calls Python module's definePopup(...) method (obsolete function, used for compatibility with old code)
}
}
+
+/*!
+ * The next methods just call the parent implementation.
+ * This is done to open protected methods from CAM_Module class.
+*/
+int SALOME_PYQT_Module::createTool( const QString& name )
+{
+ return SalomeApp_Module::createTool( name );
+}
+int SALOME_PYQT_Module::createTool( const int id, const int tBar, const int idx )
+{
+ return SalomeApp_Module::createTool( id, tBar, idx );
+}
+int SALOME_PYQT_Module::createTool( const int id, const QString& tBar, const int idx )
+{
+ return SalomeApp_Module::createTool( id, tBar, idx );
+}
+int SALOME_PYQT_Module::createTool( QAction* a, const int tBar, const int id, const int idx )
+{
+ return SalomeApp_Module::createTool( a, tBar, id, idx );
+}
+int SALOME_PYQT_Module::createTool( QAction* a, const QString& tBar, const int id, const int idx )
+{
+ return SalomeApp_Module::createTool( a, tBar, id, idx );
+}
+int SALOME_PYQT_Module::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
+{
+ return SalomeApp_Module::createMenu( subMenu, menu, id, group, idx );
+}
+int SALOME_PYQT_Module::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
+{
+ return SalomeApp_Module::createMenu( subMenu, menu, id, group, idx );
+}
+int SALOME_PYQT_Module::createMenu( const int id, const int menu, const int group, const int idx )
+{
+ return SalomeApp_Module::createMenu( id, menu, group, idx );
+}
+int SALOME_PYQT_Module::createMenu( const int id, const QString& menu, const int group, const int idx )
+{
+ return SalomeApp_Module::createMenu( id, menu, group, idx );
+}
+int SALOME_PYQT_Module::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
+{
+ return SalomeApp_Module::createMenu( a, menu, id, group, idx );
+}
+int SALOME_PYQT_Module::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
+{
+ return SalomeApp_Module::createMenu( a, menu, id, group, idx );
+}
+QAction* SALOME_PYQT_Module::createSeparator()
+{
+ return SalomeApp_Module::separator();
+}
+QAction* SALOME_PYQT_Module::action( const int id ) const
+{
+ return SalomeApp_Module::action( id );
+}
+int SALOME_PYQT_Module::actionId( const QAction* a ) const
+{
+ return SalomeApp_Module::actionId( a );
+}
+QAction* SALOME_PYQT_Module::createAction( const int id, const QString& text, const QString& icon,
+ const QString& menu, const QString& tip, const int key,
+ const bool toggle )
+{
+ QIconSet anIcon;
+ if ( !icon.isEmpty() ) {
+ QPixmap pixmap = getApp()->resourceMgr()->loadPixmap( name(""), tr( icon ) );
+ if ( !pixmap.isNull() )
+ anIcon = QIconSet( pixmap );
+ }
+ return SalomeApp_Module::createAction( id, text, anIcon, menu, tip, key, getApp()->desktop(), toggle, this, SLOT( onGUIEvent() ) );
+}
+
+
//=============================================================================
// SALOME_PYQT_XmlHandler class implementation
//=============================================================================
QString tooltip = attribute( elem, "tooltip-id" );
QString accel = attribute( elem, "accel-id" );
bool toggle = checkBool( attribute( elem, "toggle-id" ) );
- QString execute = attribute( elem, "execute-action" ); // not used
-
- QIconSet anIcon;
- if ( !icon.isEmpty() ) {
- QPixmap pixmap = myModule->getApp()->resourceMgr()->loadPixmap( myModule->name(""), icon );
- if ( !pixmap.isNull() )
- anIcon = QIconSet( pixmap );
- }
+ ////QString execute = attribute( elem, "execute-action" ); // not used
// -1 action ID is not allowed : it means that <item-id> attribute is missed in the XML file!
// also check if the action with given ID is already created
// create menu action
QAction* action = myModule->createAction( id, // ID
tooltip, // tooltip
- anIcon, // icon
+ icon, // icon
label, // menu text
tooltip, // status-bar text
QKeySequence( accel ), // keyboard accelerator
- myModule->getApp()->desktop(), // desktop
- toggle, // toogled action
- myModule, // receiver
- SLOT( onGUIEvent() ) ); // slot
+ toggle ); // toogled action
myModule->addAction( SALOME_PYQT_Module::PYQT_ACTION_MENU, action );
myModule->createMenu( action, menuId, -1, 100, pos );
}
QString tooltip = attribute( elem, "tooltip-id" );
QString accel = attribute( elem, "accel-id" );
bool toggle = checkBool( attribute( elem, "toggle-id" ) );
- QString execute = attribute( elem, "execute-action" ); // not used
-
- QIconSet anIcon;
- if ( !icon.isEmpty() ) {
- QPixmap pixmap = myModule->getApp()->resourceMgr()->loadPixmap( myModule->name(""), icon );
- if ( !pixmap.isNull() )
- anIcon = QIconSet( pixmap );
- }
+ ////QString execute = attribute( elem, "execute-action" ); // not used
// -1 action ID is not allowed : it means that <item-id> attribute is missed in the XML file!
// also check if the action with given ID is already created
// create toolbar action
QAction* action = myModule->createAction( id, // ID
tooltip, // tooltip
- anIcon, // icon
+ icon, // icon
label, // menu text
tooltip, // status-bar text
QKeySequence( accel ), // keyboard accelerator
- myModule->getApp()->desktop(), // desktop
- toggle, // toogled action
- myModule, // receiver
- SLOT( onGUIEvent() ) ); // slot
+ toggle ); // toogled action
myModule->addAction( SALOME_PYQT_Module::PYQT_ACTION_TOOLBAL, action );
myModule->createTool( action, tbId, -1, pos );
}
int pos = checkInt( attribute( elem, "pos-id" ) );
QString label = attribute( elem, "label-id" );
QString icon = attribute( elem, "icon-id" );
- QString tooltip = attribute( elem, "tooltip-id" ); // not used
+ /////QString tooltip = attribute( elem, "tooltip-id" ); // not used
QString accel = attribute( elem, "accel-id" );
- bool toggle = checkBool( attribute( elem, "toggle-id" ) ); // not used
- QString execute = attribute( elem, "execute-action" ); // not used
+ /////bool toggle = checkBool( attribute( elem, "toggle-id" ) ); // not used
+ /////QString execute = attribute( elem, "execute-action" ); // not used
QIconSet anIcon;
if ( !icon.isEmpty() ) {
SALOME_PYQT_PyInterp* myInterp;
/* Python GUI module loaded */
PyObjWrapper myModule;
+ /* Pytho GUI being initialized (not zero only during the initialization)*/
+ static SALOME_PYQT_Module* myInitModule;
typedef QPtrList<QAction> ActionList;
Engines::Component_var getEngine() const;
/******************************
- * Inherited from CAM_Module
+ * Inherited from SalomeApp_Module
******************************/
public:
+ /* little trick : provide an access to being activated Python module from outside;
+ needed by the SalomePyQt library :(
+ */
+ static SALOME_PYQT_Module* getInitModule();
+
/* initialization */
void initialize ( CAM_Application* );
/* get module engine IOR */
virtual QString engineIOR() const;
-protected:
- /* data model creation */
- CAM_DataModel* createDataModel();
+ /* called when study desktop is activated */
+ virtual void studyActivated();
+
+ /* working with toolbars : open protected methods */
+ int createTool( const QString& );
+ int createTool( const int, const int, const int = -1 );
+ int createTool( const int, const QString&, const int = -1 );
+ int createTool( QAction*, const int, const int = -1, const int = -1 );
+ int createTool( QAction*, const QString&, const int = -1, const int = -1 );
+
+ /* working with menus : open protected methods */
+ int createMenu( const QString&, const int, const int = -1, const int = -1, const int = -1 );
+ int createMenu( const QString&, const QString&, const int = -1, const int = -1, const int = -1 );
+ int createMenu( const int, const int, const int = -1, const int = -1 );
+ int createMenu( const int, const QString&, const int = -1, const int = -1 );
+ int createMenu( QAction*, const int, const int = -1, const int = -1, const int = -1 );
+ int createMenu( QAction*, const QString&, const int = -1, const int = -1, const int = -1 );
+
+ /* create separator : open protected method */
+ QAction* createSeparator();
+
+ /* working with actions : open protected methods */
+ QAction* action( const int ) const;
+ int actionId( const QAction* ) const;
+ QAction* createAction( const int, const QString&, const QString&, const QString&,
+ const QString&, const int, const bool = false );
public slots:
/* activation */
# Compilation/linkage flags
CPPFLAGS += $(QT_INCLUDES) $(PYTHON_INCLUDES) $(SIP_INCLUDES) $(OCC_INCLUDES) $(VTK_INCLUDES) $(OGL_INCLUDES) $(BOOST_CPPFLAGS) -DHAVE_CONFIG_H -I${KERNEL_ROOT_DIR}/include/salome
LIBS += $(PYTHON_LIBS) $(SIP_LIBS) $(PYQT_LIBS) $(VTK_LIBS) $(OGL_LIBS)
-LDFLAGS += -lsuit -lCAM -lstd -lqtx -lSalomeApp -lSalomeSession -lEvent -lLogWindow -lVTKViewer -lToolsGUI -L${KERNEL_ROOT_DIR}/lib/salome -lSalomeDS
+LDFLAGS += -lsuit -lCAM -lstd -lqtx -lSalomeApp -lSalomeSession -lEvent -lLogWindow -lVTKViewer -lToolsGUI -L${KERNEL_ROOT_DIR}/lib/salome -lSalomeDS -lSalomePyQtGUI
# Custom build step: generate C++ wrapping according to $(SIP_FILES)
// $Header : $
//=============================================================================
+#include "SALOME_PYQT_Module.h" // this include must be first!!!
#include "SalomePyQt.h"
#include <qapplication.h>
#include <qmenubar.h>
+#include <qwidget.h>
+#include <qpopupmenu.h>
+#include <qaction.h>
#include <qstringlist.h>
#include "SALOME_Event.hxx"
return ProcessEvent( new TDumpViewEvent( filename ) );
}
+/*!
+ SalomePyQt::createTool
+ These methods allow operating with the toolbars:
+ - create a new toolbar or get the existing one (the toolbar name is passed as parameter);
+ this method returns an id of the toolbar;
+ - add action with given id (must be created previously) and optional index to the existing toolbar
+ (toobar is identified either by its id or by its name)
+ these methods return an id of the action.
+ If error occurs, the -1 value is returned.
+*/
+class CrTool
+{
+public:
+ CrTool( const QString& tBar )
+ : myCase( 0 ), myTbName( tBar ) {}
+ CrTool( const int id, const int tBar, const int idx )
+ : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
+ CrTool( const int id, const QString& tBar, const int idx )
+ : myCase( 2 ), myId( id ), myTbName( tBar ), myIndex( idx ) {}
+ CrTool( QAction* action, const int tbId, const int id, const int idx )
+ : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
+ CrTool( QAction* action, const QString& tBar, const int id, const int idx )
+ : myCase( 4 ), myAction( action ), myTbName( tBar ), myId( id ), myIndex( idx ) {}
+
+ int execute( SALOME_PYQT_Module* module ) const
+ {
+ if ( module ) {
+ switch ( myCase ) {
+ case 0:
+ return module->createTool( myTbName );
+ case 1:
+ return module->createTool( myId, myTbId, myIndex );
+ case 2:
+ return module->createTool( myId, myTbName, myIndex );
+ case 3:
+ return module->createTool( myAction, myTbId, myId, myIndex );
+ case 4:
+ return module->createTool( myAction, myTbName, myId, myIndex );
+ }
+ }
+ return -1;
+ }
+private:
+ int myCase;
+ QString myTbName;
+ int myTbId;
+ QAction* myAction;
+ int myId;
+ int myIndex;
+};
+class TCreateToolEvent: public SALOME_Event {
+public:
+ typedef int TResult;
+ TResult myResult;
+ const CrTool& myCrTool;
+ TCreateToolEvent( const CrTool& crTool )
+ : myResult( -1 ), myCrTool( crTool ) {}
+ virtual void Execute() {
+ if ( SalomeApp_Application* anApp = getApplication() ) {
+ SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
+ if ( !module )
+ module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
+ myResult = myCrTool.execute( module );
+ }
+ }
+};
+// create new toolbar or get existing by name
+int SalomePyQt::createTool( const QString& tBar )
+{
+ return ProcessEvent( new TCreateToolEvent( CrTool( tBar ) ) );
+}
+// add action with id and index to the existing tollbar
+int SalomePyQt::createTool( const int id, const int tBar, const int idx )
+{
+ return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
+}
+// add action with id and index to the existing tollbar
+int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
+{
+ return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
+}
+// add action with id and index to the existing tollbar
+int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int idx )
+{
+ return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
+}
+// add action with id and index to the existing tollbar
+int SalomePyQt::createTool( QAction* a, const QString& tBar, const int id, const int idx )
+{
+ return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
+}
+
+/*!
+ SalomePyQt::createMenu
+ These methods allow operating with the main menu:
+ - create a new menu or submenu or get the existing one (the parent menu name or id is passed as parameter,
+ if it is empty or -1, it means that main menu is created, otherwise submenu is created);
+ this method returns an id of the menu/submenu;
+ - add action with given id (must be created previously) and optional index and group number to the existing menu
+ or submenu (menu name or id us passed as parameter)
+ these methods return an id of the action.
+ If error occurs, the -1 value is returned.
+*/
+class CrMenu
+{
+public:
+ CrMenu( const QString& subMenu, const int menu, const int group, const int idx )
+ : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
+ CrMenu( const QString& subMenu, const QString& menu, const int group, const int idx )
+ : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
+ CrMenu( const int id, const int menu, const int group, const int idx )
+ : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
+ CrMenu( const int id, const QString& menu, const int group, const int idx )
+ : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
+ CrMenu( QAction* action, const int menu, const int id, const int group, const int idx )
+ : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
+ CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx )
+ : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
+
+ int execute( SALOME_PYQT_Module* module ) const
+ {
+ if ( module ) {
+ switch ( myCase ) {
+ case 0:
+ return module->createMenu( mySubMenuName, myMenuId, -1, myGroup, myIndex );
+ case 1:
+ return module->createMenu( mySubMenuName, myMenuName, -1, myGroup, myIndex );
+ case 2:
+ return module->createMenu( myId, myMenuId, myGroup, myIndex );
+ case 3:
+ return module->createMenu( myId, myMenuName, myGroup, myIndex );
+ case 4:
+ return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
+ case 5:
+ return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
+ }
+ }
+ return -1;
+ }
+private:
+ int myCase;
+ QString myMenuName;
+ int myMenuId;
+ QString mySubMenuName;
+ int myGroup;
+ QAction* myAction;
+ int myId;
+ int myIndex;
+};
+class TCreateMenuEvent: public SALOME_Event {
+public:
+ typedef int TResult;
+ TResult myResult;
+ const CrMenu& myCrMenu;
+ TCreateMenuEvent( const CrMenu& crMenu )
+ : myResult( -1 ), myCrMenu( crMenu ) {}
+ virtual void Execute() {
+ if ( SalomeApp_Application* anApp = getApplication() ) {
+ SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
+ if ( !module )
+ module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
+ myResult = myCrMenu.execute( module );
+ }
+ }
+};
+int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int group, const int idx )
+{
+ return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, group, idx ) ) );
+}
+
+int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int group, const int idx )
+{
+ return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, group, idx ) ) );
+}
+
+int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
+{
+ return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
+}
+
+int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
+{
+ return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
+}
+
+int SalomePyQt::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
+{
+ return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
+}
+
+int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
+{
+ return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
+}
+
+/*!
+ SalomePyQt::createSeparator
+ Create a separator action which can be then used in the menu or toolbar.
+*/
+class TCreateSepEvent: public SALOME_Event {
+public:
+ typedef QAction* TResult;
+ TResult myResult;
+ TCreateSepEvent()
+ : myResult( 0 ) {}
+ virtual void Execute() {
+ if ( SalomeApp_Application* anApp = getApplication() ) {
+ SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
+ if ( !module )
+ module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
+ if ( module )
+ myResult = module->createSeparator();
+ }
+ }
+};
+QAction* SalomePyQt::createSeparator()
+{
+ return ProcessEvent( new TCreateSepEvent() );
+}
+
+/*!
+ SalomePyQt::createAction
+ Create an action which can be then used in the menu or toolbar:
+ - id : the unique id action to be registered to;
+ - menuText : action text which should appear in menu;
+ - tipText : text which should appear in the tooltip;
+ - statusText : text which should appear in the status bar when action is activated;
+ - icon : the name of the icon file (the actual icon file name can be coded in the translation files);
+ - key : the key accelrator for the action
+ - toggle : if true the action is checkable
+*/
+class TCreateActionEvent: public SALOME_Event {
+public:
+ typedef QAction* TResult;
+ TResult myResult;
+ int myId;
+ QString myMenuText;
+ QString myTipText;
+ QString myStatusText;
+ QString myIcon;
+ int myKey;
+ bool myToggle;
+ TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
+ const QString& statusText, const QString& icon, const int key, const bool toggle )
+ : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
+ myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
+ virtual void Execute() {
+ if ( SalomeApp_Application* anApp = getApplication() ) {
+ printf("TCreateActionEvent::Execute() - 1\n");
+ SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
+ printf("TCreateActionEvent::Execute() - 2: module = %d\n",module);
+ if ( !module )
+ module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
+ printf("TCreateActionEvent::Execute() - 3: module = %d\n",module);
+ if ( module )
+ myResult = module->createAction( myId, myTipText, myIcon, myMenuText, myStatusText, myKey, myToggle );
+ printf("TCreateActionEvent::Execute() - 4: myResult = %d\n",myResult);
+ }
+ }
+};
+QAction* SalomePyQt::createAction( const int id, const QString& menuText,
+ const QString& tipText, const QString& statusText,
+ const QString& icon, const int key, const bool toggle )
+{
+ return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
+}
+
+/*!
+ SalomePyQt::action
+ Get an action by its id. Returns 0 if the action with such id was not registered.
+*/
+class TActionEvent: public SALOME_Event {
+public:
+ typedef QAction* TResult;
+ TResult myResult;
+ int myId;
+ TActionEvent( const int id )
+ : myResult( 0 ), myId( id ) {}
+ virtual void Execute() {
+ if ( SalomeApp_Application* anApp = getApplication() ) {
+ SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
+ if ( !module )
+ module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
+ if ( module )
+ myResult = module->action( myId );
+ }
+ }
+};
+QAction* SalomePyQt::action( const int id )
+{
+ return ProcessEvent( new TActionEvent( id ) );
+}
+
+/*!
+ SalomePyQt::actionId
+ Get an action id. Returns -1 if the action was not registered.
+*/
+class TActionIdEvent: public SALOME_Event {
+public:
+ typedef int TResult;
+ TResult myResult;
+ const QAction* myAction;
+ TActionIdEvent( const QAction* action )
+ : myResult( -1 ), myAction( action ) {}
+ virtual void Execute() {
+ if ( SalomeApp_Application* anApp = getApplication() ) {
+ SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
+ if ( !module )
+ module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
+ if ( module )
+ myResult = module->actionId( myAction );
+ }
+ }
+};
+int SalomePyQt::actionId( const QAction* a )
+{
+ return ProcessEvent( new TActionIdEvent( a ) );
+}
#ifndef SALOME_PYQT_H
#define SALOME_PYQT_H
-#include <qwidget.h>
#include <qstring.h>
-#include <qmenubar.h>
+#include <qobject.h>
+#include <qcolor.h>
class SalomeApp_SelectionMgr;
+class QAction;
+class QMenuBar;
+class QPopupMenu;
+class QWidget;
class SALOME_Selection : public QObject
{
static bool dumpView( const QString& );
+ static int createTool( const QString& );
+ static int createTool( const int, const int, const int = -1 );
+ static int createTool( const int, const QString&, const int = -1 );
+ static int createTool( QAction*, const int, const int = -1, const int = -1 );
+ static int createTool( QAction*, const QString&, const int = -1, const int = -1 );
+
+ static int createMenu( const QString&, const int = -1,
+ const int = -1, const int = -1 );
+ static int createMenu( const QString&, const QString& = QString::null,
+ const int = -1, const int = -1 );
+ static int createMenu( const int, const int = -1,
+ const int = -1, const int = -1 );
+ static int createMenu( const int, const QString& = QString::null,
+ const int = -1, const int = -1 );
+ static int createMenu( QAction*, const int, const int = -1,
+ const int = -1, const int = -1 );
+ static int createMenu( QAction*, const QString&, const int = -1,
+ const int = -1, const int = -1 );
+
+ static QAction* createSeparator();
+
+ static QAction* createAction( const int, const QString&,
+ const QString& = QString::null, const QString& = QString::null,
+ const QString& = QString::null, const int = 0, const bool = false );
+
+ static QAction* action( const int );
+ static int actionId( const QAction* );
+
static void addSetting ( const QString&, const QString&, const double );
static void addSetting ( const QString&, const QString&, const int );
static void addSetting ( const QString&, const QString&, const QString& );
static bool dumpView( const QString& );
+ static int createTool( const QString& );
+ static int createTool( const int, const int, int = -1 );
+ static int createTool( const int, const QString&, int = -1 );
+ static int createTool( QAction*, const int, int = -1, int = -1 );
+ static int createTool( QAction*, const QString&, int = -1, int = -1 );
+
+ static int createMenu( const QString&, const int,
+ int = -1, int = -1 );
+ static int createMenu( const QString&, const QString&,
+ int = -1, int = -1 );
+ static int createMenu( const int, const int,
+ int = -1, int = -1 );
+ static int createMenu( const int, const QString&,
+ int = -1, int = -1 );
+ static int createMenu( QAction*, const int, int = -1,
+ int = -1, int = -1 );
+ static int createMenu( QAction*, const QString&, int = -1,
+ int = -1, int = -1 );
+
+ static QAction* createSeparator();
+
+ static QAction* createAction( const int, const QString&,
+ const QString& = QString::null, const QString& = QString::null,
+ const QString& = QString::null, int = 0, bool = false );
+
+ static QAction* action( const int );
+ static int actionId( const QAction* );
+
static void addSetting ( const QString&, const QString&, const double );
static void addSetting ( const QString&, const QString&, const int /Constrained/ );
static void addSetting ( const QString&, const QString&, const QString& );
static bool dumpView( const QString& );
+ static int createTool( const QString& );
+ static int createTool( const int, const int, const int = -1 );
+ static int createTool( const int, const QString&, const int = -1 );
+ static int createTool( QAction*, const int, const int = -1, const int = -1 );
+ static int createTool( QAction*, const QString&, const int = -1, const int = -1 );
+
+ static int createMenu( const QString&, const int,
+ const int = -1, const int = -1 );
+ static int createMenu( const QString&, const QString&,
+ const int = -1, const int = -1 );
+ static int createMenu( const int, const int,
+ const int = -1, const int = -1 );
+ static int createMenu( const int, const QString&,
+ const int = -1, const int = -1 );
+ static int createMenu( QAction*, const int, const int = -1,
+ const int = -1, const int = -1 );
+ static int createMenu( QAction*, const QString&, const int = -1,
+ const int = -1, const int = -1 );
+
+ static QAction* createSeparator();
+
+ static QAction* createAction( const int, const QString&,
+ const QString& = QString::null, const QString& = QString::null,
+ const QString& = QString::null, const int = 0, const bool = false );
+
+ static QAction* action( const int );
+ static int actionId( const QAction* );
+
static void addSetting ( const QString&, const QString&, const double );
static void addSetting ( const QString&, const QString&, const int /Constrained/ );
static void addSetting ( const QString&, const QString&, const QString& );