Defining Button Callback Functions

Each button defined in the extension ExtToolbarSample has a unique callback function. Each callback function passes the toolbar ID and the ID of the button clicked to the function LogButtonClicked, which stores them in the variables toolbarId and buttonId. These variables are referenced within the function where their string values are written.

The functions LogButtonClicked and SetUserOutput demonstrate how to reduce redundant code in callbacks using utility functions. The object Analysis is passed to each callback <entry> and then used in the function SetUserOutput to query for the working directory of the analysis.

The script in toolbarsample.py makes use of the namespace datetime from the .NET framework. The namespace datetime exposes a class that is also called datetime. The function LogButtonClicked invokes datetime to query the current date and time and then stores the result in the variable named now. The utility str() is used to extract the string definition of the variable now to write out the date and time.