This example displays a UI dialog with a button for users to randomly select an input raster from files that are currently open in ENVI. The dialog is created using a simple IDL widget. This is an example of custom UI functionality that can be added to a workflow step.

Follow these steps to run the example:

  1. Copy and paste the code below into the IDL Editor. Save the file as pickrandomraster_ui__define.pro.
  2. Compile pickrandomraster_ui__define.pro.
  3. Start ENVI.
  4. From the ENVI menu bar, select File > Open.
  5. Navigate to the ENVIxx\data\time_series folder of your ENVI installation path and use Ctrl-click to select all of the AirTemp*.dat files. Click Open.
  6. Type the following in the IDL command line:
    IDL> e = ENVI()
    IDL> outputUI = Obj_New('PickRandomRaster_UI')
    IDL> raster = e.UI.CreateFromDialog(outputUI)
  7. In the dialog that appears, click the Pick a Random Raster button. ENVI selects a random raster from the opened files and displays it in the dialog.

Code Example


PRO PickRandomRaster_UI_EventHandler, sEvent
COMPILE_OPT IDL2, HIDDEN
 
Widget_Control, sEvent.id, GET_UVALUE=self
self.HandleEvent, sEvent
END
 
;-----------------------------------------------------
FUNCTION PickRandomRaster_UI::Init, _REF_EXTRA=refExtra
COMPILE_OPT IDL2, HIDDEN
 
self.oRaster = ENVIRaster_UI()
return, self.ENVIParameterUI::Init(_EXTRA=refExtra)
END
 
;-----------------------------------------------------
PRO PickRandomRaster_UI::Cleanup
COMPILE_OPT IDL2, HIDDEN
 
IF (Obj_Valid(self.oRaster)) THEN BEGIN
  Obj_Destroy, self.oRaster
ENDIF
 
self.ENVIParameterUI::Cleanup
END
;-----------------------------------------------------
; Populate the UI with parameters based on the 
; supplied value
PRO PickRandomRaster_UI::SetValue, value
COMPILE_OPT IDL2, HIDDEN
 
self.oRaster.SetValue, value
END
 
;-----------------------------------------------------
; Return the parameter value defined by the user and
; stored by the UI
FUNCTION PickRandomRaster_UI::GetValue, ERROR=error
COMPILE_OPT IDL2, HIDDEN
 
return, self.oRaster.GetValue(ERROR=error)
END
 
;-----------------------------------------------------
PRO PickRandomRaster_UI::HandleEvent, sEvent
COMPILE_OPT IDL2, HIDDEN
CASE Widget_Info(sEvent.id, /UNAME) OF
'randomize': BEGIN
  rasters = envi.data.Get(/RASTER)
  value = !null
  IF (N_Elements(rasters) ne 0) THEN BEGIN
    pos = Sort(Randomu(seed, N_Elements(rasters)))
    value = rasters[pos[0]]
  ENDIF
  self.SetValue, value
  END
  ELSE:
ENDCASE
END
 
;----------------------------------------------------
; Build and display the UI
PRO PickRandomRaster_UI::BuildUI, wBase, xSize
COMPILE_OPT IDL2, HIDDEN
 
wColumn = WIDGET_BASE(wBase, /COLUMN)
self.oRaster.BuildUI, wColumn, xSize
wRow = WIDGET_BASE(wColumn, /ROW)
!null = WIDGET_BUTTON(wRow, $
  VALUE='Pick a Random Raster', $
  UVALUE=self, $
  UNAME='randomize', $
EVENT_PRO='PickRandomRaster_UI_EventHandler')
END
 
; ----------------------------------------------------
PRO PickRandomRaster_UI__Define
COMPILE_OPT IDL2, HIDDEN
 
!null = {PickRandomRaster_UI, $
  inherits  ENVIParameterUI, $
  oRaster: Obj_New() $
  }
END

See Also


Customize Workflows