Python APIs for Contextual Menu Items
The video below is best viewed in Full Screen mode, with maximum resolution (720 HD)
Getting Started
INTViewer allows you to write Python scripts that will add contextual menu items to layers, windows and data nodes.
In order to do this, you will need to put your desired contextual script into a specially named folder in your INTViewer Python directory. The naming pattern for this folder is dependent upon what kind of contextual action you are adding:
Data Folder Names
- Seismic Data: Contextual_Seismic_Data_Node (example)
- Well Data: Contextual_Well_Data_Node (example)
- Log Curve: Contextual_Log_Curve_Node (example)
- Deviation Curve: Contextual_Well_Deviation_Curve_Node (example)
- Marker: Contextual_Well_Marker_Node (example)
- Log Array: Contextual_Well_Log_Array_Node (example)
- Horizon Data: Contextual_Horizon_Data_Node (example)
- PointSet Data: Contextual_PointSet_Data_Node (example)
- Calculator Data: Contextual_Calculator_Data_Node (example)
- Cross-Plot Data: Contextual_Cross_Plot_Data_Node (example)
- Fault Data: Contextual_Fault_Data_Node (example)
- Polyline Data: Contextual_Polyline_Data_Node
- GIS Data: Contextual_GIS_Data_Node (example)
Window Folder Names
- XSection Window: Contextual_XSection_Window (example)
- Map Window: Contextual_Map_Window (example)
- 3D Window: Contextual_3D_Window (example)
- Combined Window: Contextual_Combined_Window (example)
- FK Window: Contextual_F_K_Display_Window (example)
- FT Window: Contextual_F_T_Analysis_Window (example)
- Seismic Histogram Window: Contextual_Histogram_Seismic_Window (example)
- Well Histogram Window: Contextual_Histogram_Well_Window (example)
- Horizon Histogram Window: Contextual_Histogram_Horizon_Window (example)
- PointSet Histogram Window: Contextual_Histogram_PointSet_Window (example)
- Spectrum Analysis Window: Contextual_Spectrum_Analysis_Window (example)
- Spectrum Plot Window: Contexual_Spectrum_Plot_Window (example)
- Well Log Window: Contexual_Well_Log_Window (example)
- Cross-Plot Window: Contextual_Cross_Plot_Window (example)
Layer Folder Names
- 2D Layers
- Seismic Layer: Contextual_XSection_Seismic_Layer (example)
- Time Slice Layer: Contextual_Map_Time_Slice_Layer (example)
- Outline Layer: Contextual_Map_Outline_Layer (example)
- 2D Seismic Line Layer: Contextual_Map_2D_Seismic_Line_Layer (example)
- Cross-Plot Layer: Contextual_Cross_Plot_Cross_Plot_Layer (example)
- Calculator Layer: Contextual_XSection_Calculator_Layer (example)
- Map Calculator Layer: Contextual_Map_Calculator_Layer (example)
- Horizon Layer: Contextual_XSection_Horizon_Layer (example)
- Map Horizon Layer: Contextual_Map_Horizon_Layer (example)
- PointSet Layer: Contextual_XSection_PointSet_Layer (example)
- Map PointSet Layer: Contextual_Map_PointSet_Layer (example)
- Well Layer: Contextual_XSection_Well_Layer (example)
- Map Well Layer: Contextual_Map_Well_Layer (example)
- Well Log Track: Contextual_Well_Log_Track (example)
- FK Layer: Contextual_F_K_Display_FK_Layer (example)
- FT Layer: Contextual_F_T_Analysis_FT_Layer (example)
- Spectrum Layer: Contextual_Spectrum_Analysis_Spectrum_Layer (example)
- Spectrum Plot Layer: Contextual_Spectrum_Plot_Spectrum_Plot_Layer (example)
- Seismic Histogram Layer: Contextual_Histogram_Seismic_Layer (example)
- Well Histogram Layer: Contextual_Histogram_Well_Layer (example)
- Horizon Histogram Layer: Contextual_Histogram_Horizon_Layer (example)
- PointSet Histogram Layer: Contextual_Histogram_PointSet_Layer (example)
- Fault Layer: Contextual_XSection_Fault_Layer (example)
- Map Fault Layer: Contextual_Map_Fault_Layer (example)
- GIS Layer: Contextual_Map_Gis_Layer (example)
- 3D Layers
- Seismic Volume Layer: Contextual_3D_Seismic_Volume_Layer (example)
- 3D Seismic Pre-Stack Layer: Contextual_3D_Seismic_PreStack_Layer (example)
- 3D Seismic Line Layer: Contextual_3D_2D_Seismic_Line_Layer (example)
- 3D Horizon Layer: Contextual_3D_Horizon_Layer (example)
- 3D PointSet Layer: Contextual_3D_PointSet_Layer (example)
- 3D Well Layer: Contextual_3D_Well_Layer (example)
- 3D Fault Layer: Contextual_3D_Fault_Layer (example)
Other Folder Names
- Seismic Layer Processor: Contextual_Layer_Seismic_Processor_Node (example)
- Cross-Plot Trend: Contextual_Layer_Trend_Node (example)
- Layer Point Field Node: Contextual_Layer_Point_Field_Node (example)
- Data Point Field Node: Contextual_Data_Point_Field_Node (example)
- Analysis Rectangle: Contextual_XSection_Analysis_Rectangle (example)
If you want to apply a contextual script to a layer node in the Desktop Explorer, include the script in a directory with the name from the above list that applies, followed by "_Node". For example, adding a contextual
menu to the node of a seismic layer requires putting your script under a folder called Contextual_XSection_Seismic_Layer_Node.
For multiple window and layer nodes, use the "_Nodes" notation. For example, adding a contextual
menu for one or several seismic layer nodes requires putting your script under a folder called Contextual_XSection_Seismic_Layer_Nodes (example).
Defined Variables
INTViewer will define several variables for use in your script, depending on the type of contextual action you are defining:
- window: In window scripts, the window upon which the script is being executed
- data: In data node scripts, the data upon which the script is being executed
- layer: In layer and layer node scripts, the layer upon which the script is being executed
- logCurve: In log curve node scripts, the log curve upon which the script is being executed
- deviationCurve: In deviation curve node scripts, the deviation curve upon which the script is being executed
- keyValues: In layer scripts, the map of key names and their associated values based on the layer's current selection
- keyUnitSymbols: In layer scripts, the map of key names and their associated unit symbols
- traceIndex: In seismic layer scripts, the index of the trace at the coordinates of the mouse when the contextual menu was opened
The following variables are mainly useful for debugging of Java plugins. They indicate various coordinates when the contextual menu was opened.
- deviceX: In layer scripts, the X position of the mouse in device coordinates expressed as an integer
- deviceY: In layer scripts, the Y position of the mouse in device coordinates expressed as an integer
- modelX: In layer scripts, the X position of the mouse in model coordinates expressed as a double
- modelY: In layer scripts, the Y position of the mouse in model coordinates expressed as a double
For a detailed explanation of device vs model coordinates, refer to this article: https://sites.google.com/a/geotoolkit.net/intviewer/intviewer-apis-for-windows/coordinate-system in the web site dedicated to Java plugin development.
Contextual Functions
INTViewer defines several functions which your contextual script can override. Create a separate Python script in the same directory with #Functions appended to the end of the script name. For instance, if the script is named showGisAttributes.py the functions file would be named showGisAttributes#Functions.py. There are four common functions which can be defined:
- isScriptVisible: This function can be used to force your script to be hidden in the contextual menu. This is useful when the contextual menu is not relevant for the specified dataset. By default, scripts are always visible.
- getScriptName: Shows the display name for the script in the contextual menu. By default, contextual menu names are the name of the underlying script.
- isScriptEnabled: Force the script to be enabled or disabled in the contextual menu. By default, scripts are always enabled.
- getIconPath: Adds an icon which will show up in the contextual menu. By default, a Python icon will be shown. Note: This does not work for node contextual scripts. The NetBeans platform that INTViewer is based upon does not allow icons on node actions.
Before implementing the functions file, the contextual menu would look something like this:
The following example shows a script file with the common functions implemented. All contextual variables will be passed to the function. In this example, we are using a GIS layer, and thus the layer variable is available for use.
This functions file would produce the following result:
Scripts that react to point data events have an additional option:
- requirePoints: Optimization flag used to specify whether or not all point values should be calculated then passed to a point data event script. The default is false. See more here.