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.
sName, bOK = CFileDlg:Open( sTitle=nil )
ThesTitle argument is an optional title for the dialog. If omitted, the default dialog title is "Open".
If[Open] is clicked on the dialog, the function returns the file name in sName, and sets bOK=true.
If the dialog is canceled, "",false is returned.
ThebOK return value is optional.
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 file names |
|
-- setup an index counter |
|
-- initialize the file name iteration |
|
-- loop until a nil file name is returned |
|
-- save the next file name |
|
-- exit the loop when a nil file name is returned |
|
-- save the file name in the table |
|
-- increment the table index |
|
|
-- next statement following the loop |
|
CFileDlg class, Save, Start, Next, SetFlipFITS, GetFolder, GetFileName
Mira Pro x64 Script User's Guide, Copyright Ⓒ 2023 Mirametrics,
Inc. All Rights Reserved.