5.19. The src directory

The src contains all source files required to build and install CORBA engine and (optionally) GUI of the module. Each of these entities usually has (but this is not actually obligatory) its own directory.

The CMakeLists.txt simply triggers the path of sub-directories described by the SUBDIRS target.

  • The src/SMITER directory

This directory contains the Python files that implement the engine of the module. The CMakeLists.txt defines the rules used to install these files to the destination folder. The name of the module engine Python file is predefined and should be set as <MODULE>.py where <MODULE> is a name of the module. In the case of the SMITER module, the name of the engine Python script should be SMITER.so.

The SMITER.py Python script implements SMITER class that is derived from the SMITER_Gen interface of the SMITER_ORB__POA CORBA module, the SALOME_ComponentPy_i class (base implementation of SALOME Python module engine exported by the KERNEL module) and SALOME_DriverPy_i class that provides base implementation of persistence mechanism.

In particular, SMITER class implements makeBanner() function that is defined in the IDL interface SMITER_ORB::SMITER_Gen.

def makeBanner( self , name ):
    banner = "SMITER %s!" % name
    return banner

Other services defined in SMITER_Gen CORBA interface also should be implemented by this class.

  • The src/SMITERGUI directory

This directory contains the Python files that implement the GUI of SMITER module. The name of the module GUI Python script is predefined and should be set as <MODULE>GUI.py where <MODULE> is a name of the module. In the case of the SMITER module, the name of the GUI Python script should be SMITERGUI.py.

The implementation of GUI of the SMITER module should be done according to the architecture and rules specified by the SALOME GUI module. The SMITER.py script should implement a set of the functions which define the module behavior in GUI, for example, create menus, toolbars, define context popup menus, objects selection behavior, implement dialog boxes etc.

Here below is a short description of these methods. For more details please refer to the SALOME GUI module documentation.

  • initialize() - module first initialization; usually used to create GUI actions, menus, toolbars and so on;
  • activate() - module activation; perform actions which should be done when the module is activated by the user;
  • deactivate() - module deactivation; perform actions which should be done when the module is deactivated by the user;
  • windows() - get a list and a position of the windows to be associated with the module; these windows will be automatically opened and positioned according to the setting defined by the value returned by this function;
  • views() - get a list of the compatible viewers; these viewers will be automatically opened/raised on the module activation;
  • createPopupMenu() - create and return context popup menu according to the current selection;
  • createPreferences() - initialize module’s preferences;
  • preferenceChanged() - callback function that is called when some module’s preference is changed by the user; allows to perform the corresponding actions;
  • engineIOR() - to get the reference to the module CORBA engine

Note, that some of these methods are optional and need not be obligatory implemented because SalomePyQtGUI_Module class provides a base implementation of these functions. It’s sometimes enough to implement only some of them, depending on the module needs.

In the case of SMITER module, some of these functions are implemented to provide a for the development:

  • engineIOR() that initializes SMITER module’s eggine:
def engineIOR():
    IOR = ""
    if getORB() and getEngine():
        IOR = getORB().object_to_string( getEngine() )
        pass
    return IOR
  • initialize() that sets default module preferences
def initialize():
    if not sgPyQt.hasSetting( "SMITER" , "def_obj_name" ):
        sgPyQt.addSetting( "SMITER" , "def_obj_name" , GUIcontext.DEFAULT_NAME )
    if not sgPyQt.hasSetting( "SMITER" , "creation_mode" ):
        sgPyQt.addSetting( "SMITER" , "creation_mode" , 0 )
  • createPreferences() that initializes module preferences for the application’s Preferences dialog box
def createPreferences():
    if verbose() : print "SMITERGUI.createPreferences() : study : %d" % _getStudyId()
    gid = sgPyQt.addPreference( "General" )
    gid = sgPyQt.addPreference( "Object creation" , gid )
    pid = sgPyQt.addPreference( "Default name" ,  gid, SalomePyQt.PT_String,   "SMITER" , "def_obj_name" )
    pid = sgPyQt.addPreference( "Default creation mode" , gid, SalomePyQt.PT_Selector, "SMITER" , "creation_mode" )
    strings = QStringList()
    strings.append( "Default name" )
    strings.append( "Generate name" )
    strings.append( "Ask name" )
    indexes = []
    indexes.append( QVariant(0) )
    indexes.append( QVariant(1) )
    indexes.append( QVariant(2) )
    sgPyQt.setPreferenceProperty( pid, "strings" , QVariant( strings ) )
    sgPyQt.setPreferenceProperty( pid, "indexes" , QVariant( indexes ) )
    pass
  • windows() that defines dockable windows layout
def windows():
    if verbose() : print "SMITERGUI.windows() : study : %d" % _getStudyId()
    wm = {}
    wm[SalomePyQt.WT_ObjectBrowser] = Qt.LeftDockWidgetArea
    wm[SalomePyQt.WT_PyConsole]     = Qt.BottomDockWidgetArea
    return wm

Please refer to SMITERGUI.py script for more details about implementation of other callback functions.

An implemention of the ShowSMITER() function is quite simple. It shows the small dialog box allowing user to enter the name, and then uses reference to the module CORBA engine to invoke its makeBanner() service.

Note, that GUI elements of the Python module are implemented with help of PyQt toolkit which provides a Python wrappings of the Qt library.