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

  The output dirname is a character string with the name of the selected directory. However, if the ‘`Cancel`’ button is clicked the output is of type double with the value `0`.

  See also: uigetfile, uiputfile.

`[fname, fpath, fltidx] =` uigetfile `()` ¶
`[…] =` uigetfile `(flt)` ¶
`[…] =` uigetfile `(flt, dialog_name)` ¶
`[…] =` uigetfile `(flt, dialog_name, default_file)` ¶
`[…] =` 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 in the dialog and the filename is selected as default file. Example: `uigetfile ("myfcn.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 entirely 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.

  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.

  The outputs fname and fpath are strings returning the chosen name and path, respectively. However, if the ‘`Cancel`’ button is clicked the outputs are of type double with a value of `0`. fltidx is the index in the list of filter extensions flt that was selected.

  See also: uiputfile, uigetdir.

`[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 in the dialog and the filename is selected as default file. Example: `uiputfile ("myfcn.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.

  fname and fpath return the chosen name and path, respectively. fltidx is the index in the list of filter extensions flt that was selected.

  See also: uigetfile, uigetdir.

Additionally, there are dialog boxes for displaying help messages, warnings, or errors, and for getting text input from the user.

errordlg `()` ¶
errordlg `(msg)` ¶
errordlg `(msg, title)` ¶
errordlg `(msg, title, opt)` ¶
`h =` errordlg `(…)` ¶

  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 third optional argument opt controls the behavior of the dialog. For details, see `msgbox`.

  The return value h is a handle to the figure object used for building the dialog.

  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, warndlg, msgbox, inputdlg, listdlg, questdlg.

helpdlg `()` ¶
helpdlg `(msg)` ¶
helpdlg `(msg, title)` ¶
`h =` helpdlg `(…)` ¶

  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 a handle to the figure object used for building the dialog.

  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");

  See also: errordlg, warndlg, msgbox, inputdlg, listdlg, questdlg.

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

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

    1. a scalar value which defines the number of rows used for each text field.
    2. a row or column vector with the number of elements matching the number of prompts. Each element defines the number of rows used for the corresponding text field.
    3. a 1x2 row vector which defines the number of rows and the number of columns used for all text fields.
    4. an Mx2 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 field. It must be a cell array of strings with the same size as prompt.

  options

    Not supported, only for MATLAB compatibility.

  Output: The output is a cell array of strings with each element being the text that was entered by the user. An empty cell array is returned if the dialog was closed by the Cancel button.

  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, helpdlg, listdlg, msgbox, questdlg, warndlg.

`[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 specifying the items to list in the dialog.

  `"SelectionMode"`

    can be either `"Single"` (only one item may be selected at a time) or `"Multiple"` (default).

  `"ListSize"`

    a two-element vector `[width, height]` specifying the size of the list field in pixels. The default is [160, 300].

  `"InitialValue"`

    a vector containing 1-based indices of elements which will be pre-selected when the list dialog is first displayed. The 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 of items. 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

  See also: menu, errordlg, helpdlg, inputdlg, msgbox, questdlg, warndlg.

`h =` msgbox `(msg)` ¶
`h =` msgbox `(msg, title)` ¶
`h =` msgbox `(msg, title, icon)` ¶
`h =` msgbox `(msg, title, "custom", cdata)` ¶
`h =` msgbox `(msg, title, "custom", cdata, colormap)` ¶
`h =` msgbox `(…, opt)` ¶

  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"`, `"warn"`, or `"custom"`. The latter must be followed by an image array cdata, and for indexed images the associated colormap.

  The final optional argument opt controls the behavior of the dialog. If opt is a string, it may be one of

  `"non-modal"` (default)

    The dialog is normal.

  `"modal"`

    If any dialogs already exist with the same title, the most recent is reused and all others are closed. The dialog is displayed `"modal"` which means it prevents users from interacting with any other GUI element until the dialog has been closed.

  `"replace"`

    If any dialogs already exist with the same title, the most recent is reused and all others are closed. The resulting dialog is set `"non-modal"`.

  If opt is a structure, it must contain fields `"WindowStyle"` and `"Interpreter"`:

  `"WindowStyle"`

    The value must be `"non-modal"`, `"modal"`, or `"replace"`. See above.

  `"Interpreter"`

    Controls the `"interpreter"` property of the text object used for displaying the message. The value must be `"tex"` (default), `"none"`, or `"latex"`.

  The return value h is a handle to the figure object used for building the dialog.

  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, helpdlg, inputdlg, listdlg, questdlg, warndlg.

`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, helpdlg, inputdlg, listdlg, msgbox, warndlg.

warndlg `()` ¶
warndlg `(msg)` ¶
warndlg `(msg, title)` ¶
warndlg `(msg, title, opt)` ¶
`h =` warndlg `(…)` ¶

  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 third optional argument opt controls the behavior of the dialog. For details, see `msgbox`.

  The return value h is a handle to the figure object used for building the dialog.

  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, helpdlg, msgbox, inputdlg, listdlg, questdlg.

uisetfont `()` ¶
uisetfont `(h)` ¶
uisetfont `(fontstruct)` ¶
uisetfont `(…, title)` ¶
`fontstruct =` uisetfont `(…)` ¶

  Open a font selection dialog.

  If the first argument is a handle to a text, axes, or uicontrol object, pressing the OK button will change the font properties of the object.

  The first argument may also be a structure with fields `FontName`, `FontWeight`, `FontAngle`, `FontUnits`, and `FontSize`, indicating the initially selected font.

  The title of the dialog window can be specified by using the last argument title.

  If an output argument fontstruct is requested, the selected font structure is returned. Otherwise, the font information is displayed onscreen.

  Programming Note: On systems that don’t use FontConfig natively (all but Linux), the font cache is built when Octave is installed. You will need to run `system ("fc-cache -fv")` manually after installing new fonts.

  See also: listfonts, text, axes, uicontrol.

For creating new dialog types, there is a dialog function.

`h =` dialog `()` ¶
`h =` dialog `("property", value, …)` ¶

  Create an empty modal dialog window to which other uicontrols can be added.

  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), endif`

  colormap

    []

  color

    defaultuicontrolbackgroundcolor

  dockcontrols

    off

  handlevisibility

    callback

  integerhandle

    off

  inverthardcopy

    off

  menubar

    none

  numbertitle

    off

  paperpositionmode

    auto

  resize

    off

  windowstyle

    modal

  Multiple property-value pairs may be specified for the dialog object, but they must appear in pairs. The full list of properties is documented at Figure Properties.

  The return value h is a graphics handle to the created figure.

  Example:

      ## 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: errordlg, msgbox, questdlg, warndlg, figure, uiwait.