octave: I/O Dialogs
35.1 I/O Dialogs
================
Simple dialog menus are available for choosing directories or files.
They return a string variable which can then be used with any command
requiring a filename.
-- : DIRNAME = uigetdir ()
-- : DIRNAME = uigetdir (INIT_PATH)
-- : DIRNAME = uigetdir (INIT_PATH, DIALOG_NAME)
Open a GUI dialog for selecting a directory.
If INIT_PATH is not given the current working directory is used.
DIALOG_NAME may be used to customize the dialog title.
DONTPRINTYET See also: uigetfile XREFuigetfile, *noteuiputfile:
DONTPRINTYET See also: uigetfile XREFuigetfile, uiputfile
XREFuiputfile.
-- : [FNAME, FPATH, FLTIDX] = uigetfile ()
-- : [...] = uigetfile (FLT)
-- : [...] = uigetfile (FLT, DIALOG_NAME)
-- : [...] = uigetfile (FLT, DIALOG_NAME, DEFAULT_FILE)
-- : [...] = uigetfile (..., "Position", [PX PY])
-- : [...] = uigetfile (..., "MultiSelect", MODE)
Open a GUI dialog for selecting a file and return the filename
FNAME, the path to this file FPATH, and the filter index FLTIDX.
FLT contains a (list of) file filter string(s) in one of the
following formats:
"/path/to/filename.ext"
If a filename is given then the file extension is extracted
and used as filter. In addition, the path is selected as
current path and the filename is selected as default file.
Example: ‘uigetfile ("myfun.m")’
A single file extension "*.ext"
Example: ‘uigetfile ("*.ext")’
A 2-column cell array
containing a file extension in the first column and a brief
description in the second column. Example: ‘uigetfile
({"*.ext", "My Description";"*.xyz", "XYZ-Format"})’
The filter string can also contain a semicolon separated list
of filter extensions. Example: ‘uigetfile
({"*.gif;*.png;*.jpg", "Supported Picture Formats"})’
A directory name or path name
If the folder name of path name contains a trailing file
separator, the contents of that folder will be displayed. If
no trailing file separator is present the parent directory is
listed. The substring to the right of the rightmost file
separator (if any) will be interpreted as a file or directory
name and if that file or directory exists it will be
highlighted. If the path name or directory name is wholly or
partly nonexistent, the current working directory will be
displayed. No filter will be active.
DIALOG_NAME can be used to customize the dialog title.
If DEFAULT_FILE is given then it will be selected in the GUI
dialog. If, in addition, a path is given it is also used as
current path.
The screen position of the GUI dialog can be set using the
"Position" key and a 2-element vector containing the pixel
coordinates. Two or more files can be selected when setting the
"MultiSelect" key to "on". In that case FNAME is a cell array
containing the files.
DONTPRINTYET See also: uiputfile XREFuiputfile, *noteuigetdir:
DONTPRINTYET See also: uiputfile XREFuiputfile, uigetdir
XREFuigetdir.
-- : [FNAME, FPATH, FLTIDX] = uiputfile ()
-- : [FNAME, FPATH, FLTIDX] = uiputfile (FLT)
-- : [FNAME, FPATH, FLTIDX] = uiputfile (FLT, DIALOG_NAME)
-- : [FNAME, FPATH, FLTIDX] = uiputfile (FLT, DIALOG_NAME,
DEFAULT_FILE)
Open a GUI dialog for selecting a file.
FLT contains a (list of) file filter string(s) in one of the
following formats:
"/path/to/filename.ext"
If a filename is given the file extension is extracted and
used as filter. In addition the path is selected as current
path and the filename is selected as default file. Example:
‘uiputfile ("myfun.m")’
"*.ext"
A single file extension. Example: ‘uiputfile ("*.ext")’
‘{"*.ext", "My Description"}’
A 2-column cell array containing the file extension in the 1st
column and a brief description in the 2nd column. Example:
‘uiputfile ({"*.ext","My Description";"*.xyz", "XYZ-Format"})’
The filter string can also contain a semicolon separated list of
filter extensions. Example: ‘uiputfile ({"*.gif;*.png;*.jpg",
"Supported Picture Formats"})’
DIALOG_NAME can be used to customize the dialog title. If
DEFAULT_FILE is given it is preselected in the GUI dialog. If, in
addition, a path is given it is also used as current path.
DONTPRINTYET See also: uigetfile XREFuigetfile, *noteuigetdir:
DONTPRINTYET See also: uigetfile XREFuigetfile, uigetdir
XREFuigetdir.
Additionally, there are dialog boxes for printing further help,
warnings or errors and to get textual input from the user.
-- : H = errordlg ()
-- : H = errordlg (MSG)
-- : H = errordlg (MSG, TITLE)
-- : H = errordlg (MSG, TITLE, CREATEMODE)
Display an error dialog box with error message MSG and caption
TITLE.
The default error message is "This is the default error string."
and the default caption is "Error Dialog".
The error message may have multiple lines separated by newline
characters ("\n"), or it may be a cellstr array with one element
for each line.
The return value H is always 1.
Compatibility Note: The optional argument CREATEMODE is accepted
for MATLAB compatibility, but is not implemented. See ‘msgbox’ for
details.
Examples:
errordlg ("Some fancy error occurred.");
errordlg ("Some fancy error\nwith two lines.");
errordlg ({"Some fancy error", "with two lines."});
errordlg ("Some fancy error occurred.", "Fancy caption");
See also: helpdlg XREFhelpdlg, inputdlg XREFinputdlg,
DONTPRINTYET listdlg XREFlistdlg, msgbox XREFmsgbox, *noteDONTPRINTYET listdlg XREFlistdlg, msgbox XREFmsgbox,
questdlg XREFquestdlg, warndlg XREFwarndlg.
-- : H = helpdlg ()
-- : H = helpdlg (MSG)
-- : H = helpdlg (MSG, TITLE)
Display a help dialog box with help message MSG and caption TITLE.
The default help message is "This is the default help string." and
the default caption is "Help Dialog".
The help message may have multiple lines separated by newline
characters ("\n"), or it may be a cellstr array with one element
for each line.
The return value H is always 1.
Examples:
helpdlg ("Some helpful text for the user.");
helpdlg ("Some helpful text\nwith two lines.");
helpdlg ({"Some helpful text", "with two lines."});
helpdlg ("Some helpful text for the user.", "Fancy caption");
DONTPRINTYET See also: errordlg XREFerrordlg, *noteinputdlg:
DONTPRINTYET See also: errordlg XREFerrordlg, inputdlg
XREFinputdlg, listdlg XREFlistdlg, msgbox XREFmsgbox,
questdlg XREFquestdlg, warndlg XREFwarndlg.
-- : CSTR = inputdlg (PROMPT)
-- : CSTR = inputdlg (PROMPT, TITLE)
-- : CSTR = inputdlg (PROMPT, TITLE, ROWSCOLS)
-- : CSTR = inputdlg (PROMPT, TITLE, ROWSCOLS, DEFAULTS)
-- : CSTR = inputdlg (PROMPT, TITLE, ROWSCOLS, DEFAULTS, OPTIONS)
Return user input from a multi-textfield dialog box in a cell array
of strings, or an empty cell array if the dialog is closed by the
Cancel button.
Inputs:
PROMPT
A cell array with strings labeling each text field. This
input is required.
TITLE
String to use for the caption of the dialog. The default is
"Input Dialog".
ROWSCOLS
Specifies the size of the text fields and can take three
forms:
1. a scalar value which defines the number of rows used for
each text field.
2. a vector which defines the individual number of rows used
for each text field.
3. a matrix which defines the individual number of rows and
columns used for each text field. In the matrix each row
describes a single text field. The first column
specifies the number of input rows to use and the second
column specifies the text field width.
DEFAULTS
A list of default values to place in each text fields. It
must be a cell array of strings with the same size as PROMPT.
OPTIONS
Not supported, only for MATLAB compatibility.
Example:
prompt = {"Width", "Height", "Depth"};
defaults = {"1.10", "2.20", "3.30"};
rowscols = [1,10; 2,20; 3,30];
dims = inputdlg (prompt, "Enter Box Dimensions", rowscols, defaults);
See also: errordlg XREFerrordlg, helpdlg XREFhelpdlg,
DONTPRINTYET listdlg XREFlistdlg, msgbox XREFmsgbox, *noteDONTPRINTYET listdlg XREFlistdlg, msgbox XREFmsgbox,
questdlg XREFquestdlg, warndlg XREFwarndlg.
-- : [SEL, OK] = listdlg (KEY, VALUE, ...)
Return user inputs from a list dialog box in a vector of selection
indices (SEL) and a flag indicating how the user closed the dialog
box (OK).
The indices in SEL are 1-based.
The value of OK is 1 if the user closed the box with the OK button,
otherwise it is 0 and SEL is empty.
Input arguments are specified in form of KEY, VALUE pairs. The
"ListString" argument pair must be specified.
Valid KEY and VALUE pairs are:
"ListString"
a cell array of strings with the contents of the list.
"SelectionMode"
can be either "Single" or "Multiple" (default).
"ListSize"
a vector with two elements WIDTH and HEIGHT defining the size
of the list field in pixels. Default is [160 300].
"InitialValue"
a vector containing 1-based indices of preselected elements.
Default is 1 (first item).
"Name"
a string to be used as the dialog caption. Default is "".
"PromptString"
a cell array of strings to be displayed above the list field.
Default is {}.
"OKString"
a string used to label the OK button. Default is "OK".
"CancelString"
a string used to label the Cancel button. Default is
"Cancel".
Example:
my_options = {"An item", "another", "yet another"};
[sel, ok] = listdlg ("ListString", my_options,
"SelectionMode", "Multiple");
if (ok == 1)
disp ("You selected:");
for i = 1:numel (sel)
disp (sprintf ("\t%s", my_options{sel(i)}));
endfor
else
disp ("You cancelled.");
endif
DONTPRINTYET See also: menu XREFmenu, errordlg XREFerrordlg, *noteDONTPRINTYET DONTPRINTYET See also: menu XREFmenu, errordlg XREFerrordlg,
helpdlg XREFhelpdlg, inputdlg XREFinputdlg, *notemsgbox:
DONTPRINTYET DONTPRINTYET DONTPRINTYET See also: menu XREFmenu, errordlg XREFerrordlg,
helpdlg XREFhelpdlg, inputdlg XREFinputdlg, msgbox
XREFmsgbox, questdlg XREFquestdlg, *notewarndlg:
DONTPRINTYET DONTPRINTYET DONTPRINTYET See also: menu XREFmenu, errordlg XREFerrordlg,
helpdlg XREFhelpdlg, inputdlg XREFinputdlg, msgbox
XREFmsgbox, questdlg XREFquestdlg, warndlg
XREFwarndlg.
-- : H = msgbox (MSG)
-- : H = msgbox (MSG, TITLE)
-- : H = msgbox (MSG, TITLE, ICON)
-- : H = msgbox (..., CREATEMODE)
Display MSG using a message dialog box.
The message may have multiple lines separated by newline characters
("\n"), or it may be a cellstr array with one element for each
line.
The optional input TITLE (character string) can be used to decorate
the dialog caption.
The optional argument ICON selects a dialog icon. It can be one of
"none" (default), "error", "help", or "warn".
The return value is always 1.
Compatibility Note: The optional argument CREATEMODE is accepted
for MATLAB compatibility, but is not implemented. A valid
CREATEMODE is either one of the character strings "nonmodal",
"modal", or "replace", or a structure containing a field
"WindowStyle" with one of the three character strings.
Examples:
msgbox ("Some message for the user.");
msgbox ("Some message\nwith two lines.");
msgbox ({"Some message", "with two lines."});
msgbox ("Some message for the user.", "Fancy caption");
% A message dialog box with error icon
msgbox ("Some message for the user.", "Fancy caption", "error");
See also: errordlg XREFerrordlg, helpdlg XREFhelpdlg,
DONTPRINTYET inputdlg XREFinputdlg, listdlg XREFlistdlg, *noteDONTPRINTYET inputdlg XREFinputdlg, listdlg XREFlistdlg,
questdlg XREFquestdlg, warndlg XREFwarndlg.
-- : BTN = questdlg (MSG)
-- : BTN = questdlg (MSG, TITLE)
-- : BTN = questdlg (MSG, TITLE, DEFAULT)
-- : BTN = questdlg (MSG, TITLE, BTN1, BTN2, DEFAULT)
-- : BTN = questdlg (MSG, TITLE, BTN1, BTN2, BTN3, DEFAULT)
Display MSG using a question dialog box and return the caption of
the activated button.
The message may have multiple lines separated by newline characters
("\n"), or it may be a cellstr array with one element for each
line.
The optional TITLE (character string) can be used to specify the
dialog caption. It defaults to "Question Dialog".
The dialog may contain two or three buttons which will all close
the dialog.
The string DEFAULT identifies the default button, which is
activated by pressing the <ENTER> key. It must match one of the
strings given in BTN1, BTN2, or BTN3.
If only MSG and TITLE are specified, three buttons with the default
captions "Yes", "No", and "Cancel" are used.
If only two button captions, BTN1 and BTN2, are specified the
dialog will have only these two buttons.
Examples:
btn = questdlg ("Close Octave?", "Some fancy title", "Yes", "No", "No");
if (strcmp (btn, "Yes"))
exit ();
endif
See also: errordlg XREFerrordlg, helpdlg XREFhelpdlg,
DONTPRINTYET inputdlg XREFinputdlg, listdlg XREFlistdlg, *noteDONTPRINTYET inputdlg XREFinputdlg, listdlg XREFlistdlg,
msgbox XREFmsgbox, warndlg XREFwarndlg.
-- : H = warndlg ()
-- : H = warndlg (MSG)
-- : H = warndlg (MSG, TITLE)
-- : H = warndlg (MSG, TITLE, CREATEMODE)
Display a warning dialog box with warning message MSG and caption
TITLE.
The default warning message is "This is the default warning
string." and the default caption is "Warning Dialog".
The warning message may have multiple lines separated by newline
characters ("\n"), or it may be a cellstr array with one element
for each line.
The return value H is always 1.
Compatibility Note: The optional argument CREATEMODE is accepted
for MATLAB compatibility, but is not implemented. See ‘msgbox’ for
details.
Examples:
warndlg ("Some warning text for the user.");
warndlg ("Some warning text\nwith two lines.");
warndlg ({"Some warning text", "with two lines."});
warndlg ("Some warning text for the user.", "Fancy caption");
See also: errordlg XREFerrordlg, helpdlg XREFhelpdlg,
DONTPRINTYET inputdlg XREFinputdlg, listdlg XREFlistdlg, *noteDONTPRINTYET inputdlg XREFinputdlg, listdlg XREFlistdlg,
msgbox XREFmsgbox, questdlg XREFquestdlg.
For creating new dialog types, there is a dialog function.
-- : H = dialog (..., "PROPERTY", VALUE, ...)
Create an empty modal dialog window that other uicontrols can be
added to.
The dialog box is a figure object with properties as recommended
for a dialog box.
The default properties differing from a figure are:
buttondownfcn
‘if isempty(allchild(gcbf)), close(gcbf), end’
colormap
[]
color
defaultuicontrolbackgroundcolor
dockcontrols
off
handlevisibility
callback
integerhandle
off
inverthardcopy
off
menubar
none
numbertitle
off
paperpositionmode
auto
resize
off
visible
on
windowstyle
modal
Multiple property-value pairs may be specified for the dialog
object, but they must appear in pairs.
The return value H is a graphics handle to the created figure.
object.
Examples:
% create an empty dialog window titled 'Dialog Example'
h = dialog ("name", "Dialog Example");
% create a button (default style)
b = uicontrol (h, "string", "OK", "position",[10 10 150 40], "callback","delete(gcf)");
% wait for dialog to resume or close
uiwait (h);
See also: figure XREFfigure, uiwait XREFuiwait.