CFileDlg:Next CFileDlg:Save

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.

Syntax

sName, bOK = CFileDlg:Open( sTitle=nil )

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

bullet.gif    If[Open] is clicked on the dialog, the function returns the file name in sName, and sets bOK=true.

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

bullet.gif    ThebOK return value is optional.

Remarks

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 = new_filedlg()

-- create a CFileDlg object, F

sName, bOK = F:Open()

-- Return file name and status from the Open dialog

Assert(bOK)

-- 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 = new_filedlg()

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

FileName = {}

-- create a table to hold the file names

n = 1

-- setup an index counter

F:Start()

-- initialize the file name iteration

while true do

-- loop until a nil file name is returned

  str = F:Next()

-- save the next file name

  if str == nil then break end

-- exit the loop when a nil file name is returned

  FileName[n] = str

-- save the file name in the table

  n = n + 1

-- increment the table index

end

 

-- next statement following the loop

 

Related Topics

CFileDlg class, Save, Start, Next, SetFlipFITS, GetFolder, GetFileName


Mira Pro x64 Script User's Guide, v.8.73 Copyright Ⓒ 2024 Mirametrics, Inc. All Rights Reserved.