CFileDlg:Open
The Open method opens the Windows Open dialog to browse for file names. After clicking[Open] , this method returns the selected file names and Mira-specific options such as "Open as Image Set" and Flip FITS Images". Several aspects of this dialog can be configured by setting class variables; see Remarks below. The picture shows the default dialog opened with no variables specified.
sName, bOK = CFileDlg:Open( sTitle=nil )
Two values are returned: If one file is selected, the first value is the full path name of the selected file. If more than 1 file is selected, this is the full path name of the selected files but does not include any file names. The second value defines how the dialog was closed. If the dialog was canceled, false is returned as the second argument. You do not have to specify the second argument in the script, but it it useful for determining that the user canceled the Open dialog.
The "Flip FITS Images" flag in the dialog options list controls whether FITS images are flipped with row number increasing downward. This global flag is updated after you click[Open] . It can also be configured before this dialog opens by using the CImageView:SetFlipFITS method.
In Windows, the Open and Save dialogs use a list of file type filters that follows a very specific format. The filter list is a single character string broken into parts by | characters, with two parts making a single file filter. Thus, if there were 3 filters specified in the string, there would be 6 parts. For each filter, the first part gives a filter description and the second part specifies the file filter that appears in the File Name: box of the dialog. For example, Text files (*.txt) would be a description for text files and *.txt would be the actual file filter used to select files in the Open or Save dialog.
This example sets up the Open dialog to select a text file.
|
-- enable using a custom list of file types |
|
|
-- the custom list of file types |
|
|
-- notice using the concatenation operator |
|
|
|
|
|
-- enable choosing the filter index |
|
|
-- index 2 chooses text files (*.txt) |
|
|
-- open the Open dialog with a title |
|
The window shown above was created using the following script:
|
-- create a CFileDlg object, F |
|
-- Return file name and status from the Open dialog |
|
-- exit the script of user canceled the dialog |
The following example creates an Open dialog to select up to 100 files and stores the returned file names in a table:
|
-- create a CFileDlg object, F
|
|
-- set the flag for selecting more than 1 file |
|
-- allow selecting up to 100 files |
|
-- get a file name |
-- create a table to hold the names of the selected files |
|
|
-- create the table |
|
-- setup an index counters |
|
-- initialize the file name iteration |
|
-- loop through the selected files: |
|
-- put file name into table |
|
-- increment the table index |
|
|