Running Operations
Use the DoAction method of the IDLitTool class to execute an operation on the currently selected item in the currently selected iTool. For example, suppose you have created an iPlot tool with the following command:
To call the Median operation on the plot line, you could use the following statements:
idTool = IGETCURRENT(TOOL=oTool) idMedian = oTool->FindIdentifiers('*median*', /OPERATIONS) success = oTool->DoAction(idMedian)
The Median operation would be applied. If the SHOW_EXECUTION_UI property for the operation is set to True, the operation's dialog appears before the operation is executed. See Note on the SHOW_EXECUTION_UI Property.
Warning
This example relies on the fact that the plot is selected after the iTool is created; see Selecting Items in the iTool for details on how to set the selection explicitly.
You can insert one or more calls to the DoSetProperty method (as described in Changing Property Values) before the call to the DoAction method. For example, to change the Width property used by the Median operation to 9, and set the Even Average property to True you could do the following:
idTool = IGETCURRENT(TOOL=oTool) idMedian = oTool->FindIdentifiers('*median*', /OPERATIONS) success = oTool->DoSetProperty(idMedian, 'WIDTH', 9) success = oTool->DoSetProperty(idMedian, 'EVEN', 1) success = oTool->DoAction(idMedian)
In this example both property changes and the application of the Median operation are entered into the undo-redo buffer as a single item.
Note on the SHOW_EXECUTION_UI Property
Every iTool operation included with the standard iTools that has a visible user interface has a registered property named SHOW_EXECUTION_UI. Setting this property to 1 (True) will cause the operation's graphical user interface to be displayed before the operation is executed, giving the user the option to change any parameters the operation may have. If the property is set to 0 (False), the operation will execute without displaying the graphical user interface.
When executing operations using the mechanisms described in this chapter, you may want to set the SHOW_EXECUTION_UI property to 0 (False), since leaving it set to True will require user interaction. To change the value of the property temporarily, you could use statements similar to the following to first retrieve the value of the property, save that value, and set it back after the operation has executed:
idTool = IGETCURRENT(TOOL=oTool) idMedian = oTool->FindIdentifiers('*median*', /OPERATIONS) oMedian = oTool->GetByIdentifier(idMedian) oMedian->GetProperty, SHOW_EXECUTION_UI=init_val oMedian->SetProperty, SHOW_EXECUTION_UI=0 success = oTool->DoAction(idMedian) oMedian->SetProperty, SHOW_EXECUTION_UI=init_val
Notice that we retrieve an object reference to the Median operation and use the SetProperty method rather than the DoSetProperty method to set the value of the SHOW_EXECUTION_UI property. We do this because we do not want the last call to SetProperty to be placed in the undo-redo buffer. Since the call to the DoAction method will place all outstanding changes into the undo-redo buffer, all of the changes except for the very last are undoable. But since the last line simply sets the value of the SHOW_EXECUTION_UI property back to its initial value, there is no need to place this change in the undo-redo buffer as a separate item — in fact we would rather it not be placed in the buffer at all.
If we used DoSetProperty for the final change, the change would be placed in the undo-redo buffer the next time actions were committed, either by a call to DoAction or by a call to CommitActions.
Note
We could have used the GetPropertyByIdentifer and SetPropertyByIdentifier methods rather than the GetProperty and SetProperty methods. This would not affect the outcome of the series of statements shown, and since the name of the property whose value we are getting and setting is fixed, using GetProperty and SetProperty works just as well.