GUI module example

This section provides an example of how to create a GUI module.

The AFXModuleGui base class provides various module infrastructure support functions. For example, the AFXModuleGui base class keeps track of the module’s menus, along with its toolbar and toolbox icons. As a result, the menus, toolbars, and icons can be swapped in and out automatically as the user changes modules.

The following example shows how to create a module GUI; subsequent sections explain the details of this example.

from abaqusGui import * 
from myModes import mode_1, mode_2, mode_3 
from myIcons import * 
from myToolsetGui import MyToolsetGui 
class MyModuleGui(AFXModuleGui):           
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    def __init__(self):          

        # Construct the base class             
        #         
        mw=getAFXApp().getAFXMainWindow()
        AFXModuleGui.__init__(self, moduleName='My Module',
            displayTypes=AFXModuleGui.PART)
        mw.appendApplicableModuleForTreeTab('Model',
            self.getModuleName() )
        mw.appendVisibleModuleForTreeTab('Model',
            self.getModuleName() )


        # Menu items
        # 
        menu = AFXMenuPane(self)
        AFXMenuTitle(self, '&Menu1', None, menu)
        AFXMenuCommand(self, menu, '&Item 1', None, mode_1,
            AFXMode.ID_ACTIVATE)

        subMenu = AFXMenuPane(self)   
        AFXMenuCascade(self, menu, '&Submenu', None, subMenu) 
        AFXMenuCommand(self, subMenu, '&Subitem 1', None, mode_2,
            AFXMode.ID_ACTIVATE)
 
        # Toolbar items  
        # 
        group = AFXToolbarGroup(self)
        icon = FXXpmIcon(getAFXApp(), iconData1)  
        AFXToolButton(group, '\tTool Tip', icon, mode_1,  
            AFXMode.ID_ACTIVATE)  

        # Toolbox items  
        #  
        group = AFXToolboxGroup(self)  
        icon = FXXPMIcon(getAFXApp(), iconData2)  
        AFXToolButton(group, '\tTool Tip’, icon, mode_1,
            AFXMode.ID_ACTIVATE) 

        popup = FXPopup(getAFXApp().getAFXMainWindow()) 
        AFXFlyoutItem(popup, '\tFlyout Button1', squareIcon, 
            mode_1, AFXMode.ID_ACTIVATE) 
        AFXFlyoutItem(popup, '\tFlyout Button 2', circleIcon, 
            mode_2, AFXMode.ID_ACTIVATE)
        AFXFlyoutItem(popup, '\tFlyout Button 3', triangleIcon, 
            mode_3, AFXMode.ID_ACTIVATE) 
        AFXFlyoutButton(group, popup)     

        # Register toolsets  
        #  
        self.registerToolset(MyToolsetGui(),
            GUI_IN_MENUBAR|GUI_IN_TOOL_PANE) 

    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    def getKernelInitializationCommand(self):  
        return 'import myModule'

# Instantiate the module 
#
MyModuleGui()