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 below. The picture shows the default dialog opened with no variables specified.

Syntax

sName, bSuccess = CFileDlg:Open()

sName, bSuccess = CFileDlg:Open( sTitle )

where

    ThesTitle argument is an optional title for the dialog. If omitted, the default dialog title is "Open".

    If[Open] is clicked, the function returns the file name in sName, and sets bSuccess=true.

    If the dialog is canceled, "", false is returned.

    ThebSuccess 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.

Using File Filter Lists

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.

F.bSetFilterList = true

-- enable using a custom list of file types

 

F.sFilterList = "All files (*.*) |*.*|" ..

-- the custom list of file types

 

    "Text Files (*.txt)|*.txt|" ..

-- notice using the concatenation operator

 

    "|\0"

 

 

F.bSetFilterIndex = true

-- enable choosing the filter index

 

F.nFilterIndex = 2

-- index 2 chooses text files (*.txt)

 

F:Open( "Select a Text File" )

-- open the Open dialog with a title

 

Examples

The window shown above was created using the following script:

F = CFileDlg:new()

-- create a CFileDlg object, F

sName, bSuccess = F:Open()

-- Return file name and status from the Open dialog

Assert(bSuccess)

-- 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:

F = CFileDlg:new()

-- create a CFileDlg object, F 

F.bSetMaxFiles = true

-- set the flag for selecting more than 1 file

F.nMaxFiles = 100

-- allow selecting up to 100 files

sName, bSuccess = F:Open()

-- get a file name

                       -- create a table to hold the names of the selected files

FileName = {}

-- create the table

n = 1

-- setup an index counter

F:Start()

-- initialize the file name iteration

while true do

-- loop through the selected files:

  FileName[n] = F:Next()

-- put file name into table

  n = n + 1

-- increment the table index

end

 

Related Topics

CFileDlg class

Save

Start

Next

SetFlipFITS

GetFolder

GetFileNameOpen