WgFileSelection Procedure
Creates a file selection widget which lets the user display the contents of directories and select files.
Usage
WgFileSelection, path
Input Parameters
path — A named or unnamed variable to be replaced with user input.
Output Parameters
path — A string containing the path and filename of the user's selection. If WgFileSelection is dismissed or canceled before user input is entered, path is set to a null string.
 
note
wgfileselection_output — A common block internal to WgFileSelection containing one variable, which is the file (and path) selected by the user. When WgFileSelection is called stand-alone, it runs in its own event loop. Once the user finishes choosing their file, control is passed back to the calling routine and the user's choice is accessed through the variable path. However, if WgFileSelection is called from an existing widget application, the tool must use this calling widget's event loop. In this case, WgFileSelection is executed and control is passed back immediately to the calling widget application, before the user can make their selection. To allow the widget application that calls WgFileSelection to have access to the most recent entry by the user, include this common block in the calling widget application
Keywords
Dir — A string specifying the directory path to display. The default is to show the contents of the present working directory.
File — A string specifying the default file selected from the directory.
Parent — The widget ID of the parent widget. If no parent is specified, the toolkit is initialized and WgFileSelection runs in its own event loop.
Pattern — A string specifying the search pattern. Used in combination with the directory in determining the files to be displayed. The default is to show all contents of the directory. Pattern can be a glob (for example, "*.pro") but not a regular expression (for example,
"[w][g].*f+[0-9]\{3\}").
Position — (UNIX only) A two element vector containing the position, in pixels, of WgFileSelection's upper-left corner where [0,0] is the upper-left corner of the display.
Shell — (Output) The id of the newly created WgFileSelection widget.
Title — A string containing the title for the widget.
Background — (UNIX only) The background color (passed to all widgets).
Font — The font to use for widget text.
Foreground — (UNIX only) The foreground color (passed to all widgets).
Example 1
WgFileSelection called from the command line.
; Font choice syntax different for Windows or UNIX...
IF STRMATCH(GETPLATFORM(), 'win') THEN fnt = 'Forte, 10' $
   ELSE fnt='-adobe-*-bold-*-*-*'
WgFileSelection, theFile, Pattern='*.txt', Back='Red', Font=fnt
PM, theFile
Example 2
WgFileSelection called from another widget application.
.RUN
PRO BUTTONSCB, wid, which
   COMMON teststuff, workArea
   COMMON wgfileselection_output, theFile
   CASE which OF
      1: WgFileSelection, junk, Parent=workArea, $
         Pattern='*.pro', File='wgfs_test.pro', $
         Title='Have a nice day', Back='darkgreen', $
         Position=[100,600], Shell=shell
      2: BEGIN
         IF N_ELEMENTS(theFile) GT 0 THEN BEGIN
            PM, theFile, Title="You chose the file:"
         ENDIF ELSE BEGIN
            PRINT, STRING(7B)
            PRINT, 'Nothing has been selected yet'
         ENDELSE
         END
   ENDCASE
END
 
COMMON teststuff, workArea
topShell = WwInit('WgFS_test','WgFS_test', workArea, $
   /Vertical, Position=[256,256], Spacing=5, Height=100,$
   Width=350)
buttons = WwButtonBox(workArea, ['Call wgfileselection', $
   'See result'], 'BUTTONSCB')
status=WwSetValue(topShell, /Display)
WwLoop