A Simple Widget Example
The following lines of IDL code create the simple application described in Graphical Interfaces with IDL Widgets.
PRO simple_image_viewer_event, ev WIDGET_CONTROL, ev.TOP, GET_UVALUE=drawid WIDGET_CONTROL, ev.ID, GET_UVALUE=uval CASE uval OF 'get_image' : BEGIN path = !DIR+'/examples/data' file = DIALOG_PICKFILE(PATH=path, /READ, $ FILTER='*.jpg', /FIX_FILTER) image = READ_IMAGE(file) WSET, drawid ERASE IF (SIZE(image, /N_DIMENSIONS) EQ 3) THEN BEGIN TV, image, /TRUE ENDIF ELSE BEGIN TV, image ENDELSE END 'done' : WIDGET_CONTROL, ev.top, /DESTROY ENDCASE END PRO simple_image_viewer main_base = WIDGET_BASE(/ROW, XSIZE=400, YSIZE=255) draw = WIDGET_DRAW(main_base, XSIZE=250, YSIZE=250) button_base = WIDGET_BASE(main_base, /COLUMN) button = WIDGET_BUTTON(button_base, VALUE='Get image', $ UVALUE='get_image') button = widget_button(button_base, VALUE='Done', $ UVALUE='done') WIDGET_CONTROL, main_base, /REALIZE WIDGET_CONTROL, draw, GET_VALUE=drawid WIDGET_CONTROL, main_base, SET_UVALUE=drawid XMANAGER, 'simple_image_viewer', main_base, /NO_BLOCK END
It is beyond the scope of this manual to describe every detail of the simple_image_viewer program. But as you can see, it requires fewer than 40 lines of IDL code to create a program that allows you to quickly select and view the contents of an image file.
If you are interested in trying the simple_image_viewer program, do the following:
- Open the IDL Workbench.
- Select File → New → IDL Source File to create a new editor window.
- Enter the code lines from the previous page in the editor window.
- Select File → Save and then click OK in the Save As dialog that appears, accepting the default filename and location. (This saves your code in a file named
simple_image_viewer.proin your default IDL project directory.) - Select Run → Run simple_image_viewer or press F8. The program is executed and the graphical interface is displayed.
- Click Browse to choose a JPEG image to be displayed. Click Done to dismiss the application.
For more on using the IDL Workbench to create programs, see The IDL Workbench. For more on creating graphical user interfaces using IDL widgets, see Creating Widget Applications.