OnContextMenuSelected (GridData)
 
 
 

OnContextMenuSelected (GridData)


Description

Fired when a contextual menu item is selected over a grid widget associated with a grid data parameter.


Applies To

GridData parameters on Custom Properties implemented in a scripting language.


Syntax

function <property_name>_<parameter_name>_OnContextMenuSelected()
{
...
}
def <property_name>_<parameter_name>_OnContextMenuSelected():
                                ...
Function <property_name>_<parameter_name>_OnContextMenuSelected()
                                ...
End Function
sub <property_name>_<parameter_name>_OnContextMenuSelected
{ 
        ... 
}

<property_name> is the name specified in the call to PluginRegistrar.RegisterProperty, with any spaces converted to underscores. For example, if you register a property with the name "My Property", the callback function names start with "My_Property".

<parameter_name> is the name specified in the call to CustomProperty.AddGridParameter, with any spaces converted to underscores. For example, if you added a grid parameter with the name "My Grid", the callback function names start with "<property_name>_My_Grid".


Parameters

Parameter Language Type Description
extra_param Scripting Array The first item is another Array containing the column and row indices of the selected cells. Indices are arranged as [col1, row1, col2, row2, ...].

The second item the index of the selected item in the context menu.

Examples

import win32com.client
from win32com.client import constants

def XSILoadPlugin( in_reg ):
        in_reg.Author = "Autodesk"
        in_reg.Name = "MyPropertyPlugin"
        in_reg.Major = 1
        in_reg.Minor = 0

        in_reg.RegisterProperty("MyProperty")
        #RegistrationInsertionPoint - do not remove this line

        return True

def XSIUnloadPlugin( in_reg ):
        strPluginName = in_reg.Name
        return True

def MyProperty_Define( in_ctxt ):
        oCustomProperty = in_ctxt.Source
        oCustomProperty.AddGridParameter("MyGrid")
        return True

def MyProperty_DefineLayout( in_ctxt ):
        oLayout = in_ctxt.Source
        oLayout.Clear()
        oItem = oLayout.AddItem("MyGrid")
        return True

def MyProperty_OnInit( ):
        Application.LogMessage("MyProperty_OnInit called",constants.siVerbose)
        param = PPG.MyGrid

        # Basic population of the grid data
        gridData = param.Value
        gridData.ColumnCount = 3
        gridData.RowCount = 3
        
        for col in range( gridData.ColumnCount ):
                gridData.SetColumnLabel( col, "Col %d"%col )
                gridData.SetColumnDef( col, constants.siColumnStandard )
                for row in range( gridData.RowCount ):
                        if col == 0:
                                gridData.SetRowLabel( row, "Row %d"%row )
                        gridData.SetCell( col, row, "%d,%d"%(col, row) )

def MyProperty_OnClosed( ):
        pass


GLOBAL_LAST_MENU_DEFINITION = []

def MyProperty_MyGrid_OnContextMenuInit( in_ExtraParams ):
        param = PPG.MyGrid
        gridData = param.Value
        
        menuEntries = [ "First menu item", 0 ]
        
        # Retrieve the set of cells that were selected when the 
        # right-mouse click occurred
        columnRowPair = in_ExtraParams[0]

        # Add one menu item for the cell on which the right-click occurred
        col = columnRowPair[0]
        row = columnRowPair[1]
        menuEntries.extend( [ "(%d,%d)"%(col, row), 1 ] );

        # A last entry
        menuEntries.extend( [ "Last menu item", 100 ] )

        global GLOBAL_LAST_MENU_DEFINITION
        GLOBAL_LAST_MENU_DEFINITION = menuEntries
        
        return menuEntries
        
def MyProperty_MyGrid_OnContextMenuSelected( in_ExtraParams ):
        param = PPG.MyGrid
        gridData = param.Value
        
        # Retrieve the set of cells that were selected when the 
        # right-mouse click occurred
        columnRowPair = in_ExtraParams[0]

        # Add one menu item for the cell on which the right-click occurred
        col = columnRowPair[0]
        row = columnRowPair[1]
        
        selectedMenuItemID = in_ExtraParams[1]
        
        global GLOBAL_LAST_MENU_DEFINITION
        
        for itr in range( len( GLOBAL_LAST_MENU_DEFINITION ) / 2 ):
                menuItemString = GLOBAL_LAST_MENU_DEFINITION[ itr*2 ]
                menuItemID = GLOBAL_LAST_MENU_DEFINITION[ itr*2 + 1 ]
                
                if menuItemID == selectedMenuItemID:
                        Application.LogMessage("Contextual menu item \"%s\" (ID=%d) was selected"%(menuItemString, menuItemID) )
                        break

See Also