Version: 8.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PyModuleHelper Class Reference

This class implements API helper for all the Python-based SALOME GUI modules.

#include <SALOME_PYQT_PyModule.h>

Inheritance diagram for PyModuleHelper:
Inheritance graph

Classes

class  InitLocker
 Initialization locker. More...
 
class  XmlHandler
 XML resource files parser. More...
 

Public Slots

void initialize (CAM_Application *)
 Initialization of the Python-based SALOME module. More...
 
bool activate (SUIT_Study *study)
 Activation of the module. More...
 
bool deactivate (SUIT_Study *study)
 Deactivation of the module. More...
 
void modelClosed (SUIT_Study *study)
 Close of the module. More...
 
void preferencesChanged (const QString &, const QString &setting)
 Process module's preferences changing. More...
 
void preferenceChanged (const QString &, const QString &, const QString &setting)
 Process application preferences changing. More...
 
void studyActivated (SUIT_Study *)
 Process study activation. More...
 
void actionActivated ()
 Process action activation. More...
 
void selectionUpdated (const QStringList &)
 update selection from other views or modules. More...
 
void contextMenu (const QString &, QMenu *)
 Process context popup menu request. More...
 
void createPreferences ()
 Export preferences for the Python module. Called only once when the first instance of the module is created or when common Preferences dialog box is first time invoked. More...
 
void activeViewChanged (SUIT_ViewWindow *)
 Signal handler windowActivated(SUIT_ViewWindow*) of SUIT_Desktop. More...
 
void tryCloseView (SUIT_ViewWindow *)
 Signal handler tryClose(SUIT_ViewWindow*) of a view. More...
 
void closeView (SUIT_ViewWindow *)
 Signal handler closing(SUIT_ViewWindow*) of a view. More...
 
void cloneView (SUIT_ViewWindow *)
 Signal handler cloneView() of OCCViewer_ViewWindow. More...
 
void save (QStringList &, const QString &)
 Save module data. Called when user saves study. More...
 
bool load (const QStringList &, const QString &)
 
void dumpPython (QStringList &files)
 Dump module data to the Python script. Called when user activates dump study operation. More...
 
bool isDraggable (const SUIT_DataObject *) const
 Test if object what can be dragged by the user. More...
 
bool isDropAccepted (const SUIT_DataObject *) const
 Test if drop operation can be done on the where object. More...
 
void dropObjects (const DataObjectList &, SUIT_DataObject *, const int, Qt::DropAction)
 Perform drop operation. More...
 
QString engineIOR () const
 Get module engine IOR. More...
 
void onObjectBrowserClicked (SUIT_DataObject *, int)
 

Public Member Functions

 PyModuleHelper (LightApp_Module *)
 Constructor. More...
 
 ~PyModuleHelper ()
 Destructor. More...
 
LightApp_Modulemodule () const
 Get owner module. More...
 
PyObject * pythonModule () const
 Get Python GUI module object. More...
 
void connectAction (QAction *)
 Connect action to the internal actionActivated() slot. More...
 
QMap< int, int > windows () const
 Get the dockable windows associated with the module. More...
 
QStringList viewManagers () const
 Define the compatible view windows associated with the module. More...
 

Static Public Member Functions

static LightApp_ModulegetInitModule ()
 Get the module being initialized. More...
 
static int defaultMenuGroup ()
 Get default menu group identifier. More...
 

Private Types

typedef QMap< int,
PyInterp_Interp * > 
InterpMap
 

Private Member Functions

void initInterp (int)
 Initialize python subinterpreter (one per study). More...
 
void importModule ()
 Import Python GUI module and store reference to the module. More...
 
void setWorkSpace ()
 Set study workspace to the Python module. More...
 
void internalInitialize (CAM_Application *)
 Initialization callback function. More...
 
void internalActivate (SUIT_Study *)
 Activation callback function. More...
 
void internalCustomize (SUIT_Study *)
 Additional menu customization callback function. More...
 
void internalDeactivate (SUIT_Study *)
 Deactivation callback function. More...
 
void internalClosedStudy (SUIT_Study *)
 Internal closure: More...
 
void internalPreferencesChanged (const QString &, const QString &)
 Preference changing callback function. More...
 
void internalStudyChanged (SUIT_Study *)
 Active study change callback function. More...
 
void internalActionActivated (int)
 GUI event handling callback function. More...
 
void internalSelectionUpdated (const QStringList &)
 update selection from other views or modules More...
 
void internalContextMenu (const QString &, QMenu *)
 Context popup menu handling callback function. More...
 
void internalCreatePreferences ()
 Preferences initialization callback function. More...
 
void internalActiveViewChanged (SUIT_ViewWindow *)
 Active view changing callback function. More...
 
void internalTryCloseView (SUIT_ViewWindow *)
 View closing callback function. More...
 
void internalCloseView (SUIT_ViewWindow *)
 View closing callback function. More...
 
void internalCloneView (SUIT_ViewWindow *)
 View cloning callback function. More...
 
void internalSave (QStringList &, const QString &)
 Module data saving callback function. More...
 
void internalLoad (const QStringList &, const QString &, bool &)
 Module data loading callback function. More...
 
void internalDumpPython (QStringList &)
 Module dump python callback function. More...
 
bool internalIsDraggable (LightApp_DataObject *)
 Check data object's 'draggable' status callback function. More...
 
bool internalIsDropAccepted (LightApp_DataObject *)
 Check data object's 'drop allowed' status callback function. More...
 
void internalDropObjects (const DataObjectList &, SUIT_DataObject *, const int, Qt::DropAction)
 Data dropping callback function. More...
 
QString internalEngineIOR () const
 Get engine IOR callback function. More...
 
void internalOBClickedPython (const QString &, int)
 
void connectView (SUIT_ViewWindow *)
 Connects signals about activating and cloning view on internal slots. More...
 

Private Attributes

LightApp_ModulemyModule
 GUI module. More...
 
PyObject * myPyModule
 Python GUI module. More...
 
PyInterp_InterpmyInterp
 current Python subinterpreter More...
 
XmlHandlermyXmlHandler
 XML resource file parser. More...
 
QMap< int, int > myWindowsMap
 windows map More...
 
QStringList myViewMgrList
 compatible view managers list More...
 
bool myLastActivateStatus
 latest module activation status More...
 

Static Private Attributes

static InterpMap myInterpMap
 study to Python subinterpreter map More...
 
static LightApp_ModulemyInitModule = 0
 Python GUI being initialized (not zero only during the initialization) More...
 

Member Typedef Documentation

typedef QMap<int, PyInterp_Interp*> PyModuleHelper::InterpMap
private

Constructor & Destructor Documentation

PyModuleHelper::PyModuleHelper ( LightApp_Module module)
Parameters
moduleowner module
PyModuleHelper::~PyModuleHelper ( )

References myInterp, myPyModule, and myXmlHandler.

Member Function Documentation

void PyModuleHelper::actionActivated ( )
slot

Called when action is activated. Used for notifying the Python module about any related action activation.

See Also
connectAction()

References CAM_Module::actionId(), myInterp, and myModule.

bool PyModuleHelper::activate ( SUIT_Study study)
slot

This function is usually used in order to show the module's specific menus and toolbars, update actions state and perform other such actions required when the module is activated.

Note
Returning false from this function prevents the module activation.
Parameters
studyparent study
Returns
true if activation is successful and false otherwise

References PyModuleHelper::XmlHandler::activateMenus(), activeViewChanged(), SUIT_Study::application(), connectView(), SUIT_Application::desktop(), LightApp_Module::getApp(), myLastActivateStatus, myModule, myXmlHandler, preferenceChanged(), CAM_Module::setMenuShown(), and CAM_Module::setToolShown().

void PyModuleHelper::activeViewChanged ( SUIT_ViewWindow view)
slot

Used to notify Python module that active view has been changed by the user.

Parameters
viewview being activated

References connectView(), and myInterp.

void PyModuleHelper::cloneView ( SUIT_ViewWindow view)
slot
Parameters
viewview being cloned

References myInterp.

void PyModuleHelper::closeView ( SUIT_ViewWindow view)
slot
Parameters
viewview being closed

References myInterp.

void PyModuleHelper::connectAction ( QAction a)

Actions connected to internal actionActivated(), when activated, will be forwarded to the Python GUI module OnGUIEvent() function.

Parameters
aaction being connected

References actionActivated(), and myModule.

void PyModuleHelper::connectView ( SUIT_ViewWindow view)
private
void PyModuleHelper::contextMenu ( const QString &  context,
QMenu menu 
)
slot

Called when user activates popup menu in some window (view, object browser, etc).

Parameters
contextpopup menu context (e.g. "ObjectBrowser")
menupopup menu

References myInterp.

void PyModuleHelper::createPreferences ( )
slot

References myInterp, and myModule.

bool PyModuleHelper::deactivate ( SUIT_Study study)
slot

This function is usually used in order to hide the module's specific menus and toolbars and perform other such actions required when the module is deactivated.

Parameters
studyparent study
Returns
true if deactivation is successful and false otherwise

References PyModuleHelper::XmlHandler::activateMenus(), activeViewChanged(), SUIT_Study::application(), SUIT_Application::desktop(), LightApp_Module::getApp(), myInterp, myModule, myXmlHandler, preferenceChanged(), CAM_Module::setMenuShown(), and CAM_Module::setToolShown().

int PyModuleHelper::defaultMenuGroup ( )
static
Returns
menu group ID (40 by default)

References DEFAULT_GROUP.

void PyModuleHelper::dropObjects ( const DataObjectList what,
SUIT_DataObject where,
const int  row,
Qt::DropAction  action 
)
slot
Parameters
whatlist of data objects being dropped
wheretarget data object for drop operation
rowline (child item index) where drop operation is performed to
actioncurrent drop action (copy or move)

References myInterp.

void PyModuleHelper::dumpPython ( QStringList &  files)
slot
Parameters
filesoutput list of files where module stores python script

References myInterp, and myModule.

QString PyModuleHelper::engineIOR ( ) const
slot
Returns
engine IOR as it is supplied by GUI Python module

References myInterp.

LightApp_Module * PyModuleHelper::getInitModule ( )
static

This is a little trick :) needed to provide an access from Python (SalomePyQt) to the module being currently activated. The problem that during the process of module initialization (initialize() function) it is not yet available via application->activeModule() call.

This method returns valid pointer only if called in scope of initialize() function or in several other specific cases.

Returns
the module being currently initialized

References myInitModule, and myInitMutex.

void PyModuleHelper::importModule ( )
private

Warning! initInterp() should be called first!!!

References myInterp, myModule, myPyModule, and CAM_Module::name().

void PyModuleHelper::initialize ( CAM_Application app)
slot

This method can be used for creation of the menus, toolbars and other such stuff.

There are two ways to do this: 1) for obsolete modules, the implementation of this method first tries to read the <module>_<language>.xml resource file which contains a menu, toolbars and popup menus description; 2) new modules can create menus by direct calling of the corresponding methods of SalomePyQt Python API in the Python module's initialize() method which is called from here.

Note
SALOME supports two modes of modules loading:
  • immediate (all the modules are created and initialized immediately when the application object is created);
  • postponed modules loading (used currently); in this mode the module is loaded only by explicit request. If postponed modules loading is not used, the active study might be not yet defined at this stage, so initialize() method should not perform any study-based initialization. Such actions can be better done in activate() function.
Parameters
appparent application object

References PyModuleHelper::XmlHandler::createActions(), LightApp_Module::getApp(), myModule, myXmlHandler, CAM_Module::name(), QtxResourceMgr::path(), SUIT_Application::resourceMgr(), and QtxResourceMgr::stringValue().

void PyModuleHelper::initInterp ( int  studyId)
private
Parameters
studyIdstudy ID

References SUIT_PYTHON::initialized, myInitMutex, myInterp, and myInterpMap.

void PyModuleHelper::internalActionActivated ( int  id)
private

Performs the following actions:

  • calls Python module's OnGUIEvent() method
Parameters
idGUI action ID

References FuncMsg::message(), myInterp, and myPyModule.

void PyModuleHelper::internalActivate ( SUIT_Study study)
private

Performs the following actions:

  • initialize or get the Python interpreter (one per study)
  • import the Python GUI module
  • call Python module's activate() method
Parameters
studyparent study

References SUIT_Study::id(), importModule(), initInterp(), myInterp, myLastActivateStatus, and myPyModule.

void PyModuleHelper::internalActiveViewChanged ( SUIT_ViewWindow view)
private
Parameters
viewview being activated

References SUIT_ViewWindow::getId(), FuncMsg::message(), myInterp, and myPyModule.

void PyModuleHelper::internalCloneView ( SUIT_ViewWindow view)
private
Parameters
viewview being cloned

References SUIT_ViewWindow::getId(), FuncMsg::message(), myInterp, and myPyModule.

void PyModuleHelper::internalClosedStudy ( SUIT_Study theStudy)
private

Performs the following actions:

  • call Python module's closeStudy() method
Parameters
theStudyparent study object

References SUIT_Study::id(), myInterp, and myPyModule.

void PyModuleHelper::internalCloseView ( SUIT_ViewWindow view)
private
Parameters
viewview being closed

References SUIT_ViewWindow::getId(), FuncMsg::message(), myInterp, and myPyModule.

void PyModuleHelper::internalContextMenu ( const QString &  context,
QMenu menu 
)
private

Performs the following actions:

  • calls Python module's definePopup(...) method (obsolete function, used for compatibility with old code) to define the popup menu context
  • parses XML resourses file (if exists) and fills the popup menu with the items)
  • calls Python module's customPopup(...) method (obsolete function, used for compatibility with old code) to allow module to customize the popup menu
  • for new modules calls createPopupMenu() function to allow the modules to build the popup menu by using insertItem(...) Qt functions.
Parameters
contextpopup menu context
menupopup menu

References PyModuleHelper::XmlHandler::createPopup(), IsCallOldMethods, FuncMsg::message(), myInterp, myPyModule, and myXmlHandler.

void PyModuleHelper::internalCreatePreferences ( )
private

Performs the following actions:

References myInterp, and myPyModule.

void PyModuleHelper::internalCustomize ( SUIT_Study study)
private

Performs the following actions:

  • get the Python interpreter (one per study)
  • import the Python GUI module
  • call Python module's setSettings() method (obsolete function, used for compatibility with old code)
Parameters
studyparent study

References SUIT_Study::id(), importModule(), initInterp(), IsCallOldMethods, myInterp, myLastActivateStatus, myPyModule, and setWorkSpace().

void PyModuleHelper::internalDeactivate ( SUIT_Study study)
private

Performs the following actions:

Parameters
studyparent study

References myInterp, and myPyModule.

void PyModuleHelper::internalDropObjects ( const DataObjectList what,
SUIT_DataObject where,
const int  row,
Qt::DropAction  action 
)
private
Parameters
whatlist of data objects being dropped
wheretarget data object for drop operation
rowline (child item index) where drop operation is performed to
actioncurrent drop action (copy or move)

References LightApp_DataObject::entry(), myInterp, and myPyModule.

void PyModuleHelper::internalDumpPython ( QStringList &  files)
private
Parameters
filesoutput list of files where module stores python script

References myInterp, and myPyModule.

QString PyModuleHelper::internalEngineIOR ( ) const
private

Tries to get engine IOR from the Python module using engineIOR() function. That function can load module engine using appropriate container if required.

Returns
engine IOR or empty string if it is not provided by Python module

References myInterp, myModule, and myPyModule.

void PyModuleHelper::internalInitialize ( CAM_Application app)
private

Performs the following actions:

  • initialize or get the Python interpreter (one per study)
  • import the Python module
  • pass the workspace widget to the Python module
  • call Python module's initialize() method
  • call Python module's windows() method
  • call Python module's views() method
Parameters
appparent application object

References SUIT_Application::activeStudy(), app, SUIT_Study::id(), importModule(), initInterp(), myInterp, myPyModule, myViewMgrList, myWindowsMap, LightApp_Application::WT_LogWindow, LightApp_Application::WT_ObjectBrowser, and LightApp_Application::WT_PyConsole.

bool PyModuleHelper::internalIsDraggable ( LightApp_DataObject what)
private
Parameters
whatdata object being tested
Returns
true if object can be dragged or false otherwise

References LightApp_DataObject::entry(), myInterp, and myPyModule.

bool PyModuleHelper::internalIsDropAccepted ( LightApp_DataObject where)
private
Parameters
wheredata object being tested
Returns
true if if drop operation is supported by object or false otherwise

References LightApp_DataObject::entry(), myInterp, and myPyModule.

void PyModuleHelper::internalLoad ( const QStringList &  files,
const QString &  url,
bool &  opened 
)
private
Parameters
fileslist of files where module data is stored
urlstudy URL
openedoutput success flag

References myInterp, and myPyModule.

void PyModuleHelper::internalOBClickedPython ( const QString &  theObj,
int  theColumn 
)
private

References myInterp, and myPyModule.

void PyModuleHelper::internalPreferencesChanged ( const QString &  section,
const QString &  setting 
)
private

Performs the following actions:

Parameters
sectionresources section name
settingresources parameter name

References myInterp, and myPyModule.

void PyModuleHelper::internalSave ( QStringList &  files,
const QString &  url 
)
private
Parameters
filesoutput list of files where module stores data
urlstudy URL

References myInterp, and myPyModule.

void PyModuleHelper::internalSelectionUpdated ( const QStringList &  entries)
private

Performs the following actions:

  • calls Python module's onSelectionpdated(entries) method
Parameters
listof entries

References myInterp, and myPyModule.

void PyModuleHelper::internalStudyChanged ( SUIT_Study study)
private

Called when active the study is actived (user brings its desktop to top):

  • initialize or get the Python interpreter (one per study)
  • import the Python GUI module
  • call Python module's activeStudyChanged() method
Parameters
studystudy being activated

References SUIT_Study::id(), importModule(), initInterp(), FuncMsg::message(), myInterp, myPyModule, and setWorkSpace().

void PyModuleHelper::internalTryCloseView ( SUIT_ViewWindow view)
private
Parameters
viewview user tries to close

References SUIT_ViewWindow::getId(), FuncMsg::message(), myInterp, and myPyModule.

bool PyModuleHelper::isDraggable ( const SUIT_DataObject what) const
slot
Parameters
whatdata object being tested
Returns
true if object can be dragged or false otherwise

References myInterp.

bool PyModuleHelper::isDropAccepted ( const SUIT_DataObject where) const
slot
Parameters
wheredata object being tested
Returns
true if if drop operation is supported by object or false otherwise

References myInterp.

bool PyModuleHelper::load ( const QStringList &  files,
const QString &  url 
)
slot

References myInterp.

void PyModuleHelper::modelClosed ( SUIT_Study study)
slot

This function is usually used in order to close the module's specific menus and toolbars and perform other such actions required when the module is closed.

References PyModuleHelper::XmlHandler::activateMenus(), activeViewChanged(), SUIT_Study::application(), SUIT_Application::desktop(), LightApp_Module::getApp(), myInterp, myModule, myXmlHandler, preferenceChanged(), CAM_Module::setMenuShown(), and CAM_Module::setToolShown().

LightApp_Module * PyModuleHelper::module ( ) const
Returns
owner module

References myModule.

void PyModuleHelper::onObjectBrowserClicked ( SUIT_DataObject theObj,
int  theColumn 
)
slot
void PyModuleHelper::preferenceChanged ( const QString &  module,
const QString &  section,
const QString &  parameter 
)
slot

Called when any application setting is changed.

Parameters
modulepreference module
sectionpreference resources section
parameterpreference resources parameter name

References CAM_Module::moduleName(), myModule, and preferencesChanged().

void PyModuleHelper::preferencesChanged ( const QString &  section,
const QString &  parameter 
)
slot

Called when the module's own preferences are changed.

Parameters
sectionpreference resources section
parameterpreference resources parameter name

References myInterp.

PyObject * PyModuleHelper::pythonModule ( ) const
Returns
python module

References myPyModule.

void PyModuleHelper::save ( QStringList &  files,
const QString &  url 
)
slot
Parameters
filesoutput list of files where module stores data
urlstudy URL

References myInterp, and myModule.

void PyModuleHelper::selectionUpdated ( const QStringList &  entries)
slot

Called when selection is modified outside.

References myInterp.

void PyModuleHelper::setWorkSpace ( )
private

Calls setWorkSpace() method of the Python module with PyQt QWidget object to use with interpreter.

Attention! initInterp() and importModule() should be called first!!!

References SUIT_Application::desktop(), LightApp_Module::getApp(), IsCallOldMethods, myInterp, myModule, myPyModule, STD_MDIDesktop::workspace(), and STD_TabDesktop::workstack().

void PyModuleHelper::studyActivated ( SUIT_Study study)
slot

Called when study desktop is activated. Used for notifying the Python module about changing of the active study.

Parameters
studystudy being activated
void PyModuleHelper::tryCloseView ( SUIT_ViewWindow view)
slot
Parameters
viewview being closed

References myInterp.

QStringList PyModuleHelper::viewManagers ( ) const

The associated view windows are opened automatically when the module is activated.

To fill the list of views the correspondind Python module's views() method is called during the module initialization. By default, the list of view types is empty.

Returns
list of view windows types

References myViewMgrList.

QMap< int, int > PyModuleHelper::windows ( ) const

To fill the list of windows the correspondind Python module's windows() method is called during the module initialization.

By default, ObjectBrowser, PythonConsole and LogWindow windows are associated to the module.

Allowed dockable windows:

Dock area is defined by Qt::DockWidgetArea enumeration:

  • Qt::TopDockWidgetArea : top dock area
  • Qt::BottomDockWidgetArea : bottom dock area
  • Qt::LeftDockWidgetArea : left dock area
  • Qt::RightDockWidgetArea : right dock area
Returns
map of dockable windows in form { <window_type> : <dock_area> }

References myWindowsMap.

Member Data Documentation

LightApp_Module * PyModuleHelper::myInitModule = 0
staticprivate
PyInterp_Interp* PyModuleHelper::myInterp
private
PyModuleHelper::InterpMap PyModuleHelper::myInterpMap
staticprivate
bool PyModuleHelper::myLastActivateStatus
private
LightApp_Module* PyModuleHelper::myModule
private
PyObject* PyModuleHelper::myPyModule
private
QStringList PyModuleHelper::myViewMgrList
private
QMap<int, int> PyModuleHelper::myWindowsMap
private
XmlHandler* PyModuleHelper::myXmlHandler
private

The documentation for this class was generated from the following files: