changeset 12522:33bbae85769a

Add uimenu, uigetdir, uigetfile, and uiputfile to documentation.
author Rik <octave@nomad.inbox5.com>
date Fri, 18 Mar 2011 22:47:33 -0700
parents 02e48856e486
children 33f7d8f95f5b
files doc/ChangeLog doc/interpreter/doccheck/aspell-octave.en.pws doc/interpreter/io.txi doc/interpreter/octave.texi doc/interpreter/plot.txi scripts/ChangeLog scripts/plot/uigetdir.m scripts/plot/uigetfile.m scripts/plot/uimenu.m scripts/plot/uiputfile.m
diffstat 10 files changed, 189 insertions(+), 154 deletions(-) [+]
line wrap: on
line diff
--- a/doc/ChangeLog	Fri Mar 18 21:25:08 2011 -0700
+++ b/doc/ChangeLog	Fri Mar 18 22:47:33 2011 -0700
@@ -1,3 +1,9 @@
+2010-03-18  Rik  <octave@nomad.inbox5.com>
+
+	* interpreter/doccheck/aspell-octave.en.pws, interpreter/io.txi,
+	interpreter/octave.texi, interpreter/plot.txi: Add uimenu, uigetdir,
+	uigetfile, and uiputfile to documentation.
+
 2010-03-18  Rik  <octave@nomad.inbox5.com>
 
 	* interpreter/nonlin.txi, interpreter/octave.texi: Add fminbnd,
--- a/doc/interpreter/doccheck/aspell-octave.en.pws	Fri Mar 18 21:25:08 2011 -0700
+++ b/doc/interpreter/doccheck/aspell-octave.en.pws	Fri Mar 18 22:47:33 2011 -0700
@@ -20,6 +20,7 @@
 Anymap
 API
 approximant
+arg
 ARMA
 arpack
 ascii
@@ -151,6 +152,7 @@
 CreateFcn
 csymamd
 ctranspose
+CTRL
 CTS
 cURL
 Cuthill
@@ -273,6 +275,7 @@
 fontconfig
 fontname
 forall
+foregroundcolor
 formfeed
 Fortran
 fpdf
@@ -535,8 +538,10 @@
 multi
 multibyte
 multiline
+MultiSelect
 mxArray
 myclass
+myfun
 nabla
 NaN
 NaNs
@@ -794,6 +799,7 @@
 Sublicensing
 submatrices
 submatrix
+submenu
 subprocess
 subprocesses
 Subprocesses
@@ -863,7 +869,9 @@
 UB
 uchar
 UID
+uimenu
 uint
+uiputfile
 ulong
 Ultrix
 umfpack
--- a/doc/interpreter/io.txi	Fri Mar 18 21:25:08 2011 -0700
+++ b/doc/interpreter/io.txi	Fri Mar 18 22:47:33 2011 -0700
@@ -28,6 +28,7 @@
 @menu
 * Basic Input and Output::      
 * C-Style I/O Functions::       
+* GUI Dialogs for I/O::       
 @end menu
 
 @node Basic Input and Output
@@ -1060,3 +1061,16 @@
 @end group
 @end example
 
+@node GUI Dialogs for I/O
+@section GUI Dialogs for I/O
+
+Simple dialog menus are available for choosing directories or files.  They
+return a string variable which can then be used when calling any command
+requiring a file name.
+
+@DOCSTRING(uigetdir)
+
+@DOCSTRING(uigetfile)
+
+@DOCSTRING(uiputfile)
+
--- a/doc/interpreter/octave.texi	Fri Mar 18 21:25:08 2011 -0700
+++ b/doc/interpreter/octave.texi	Fri Mar 18 22:47:33 2011 -0700
@@ -461,6 +461,7 @@
 
 * Basic Input and Output::      
 * C-Style I/O Functions::       
+* GUI Dialogs for I/O::       
 
 Basic Input and Output
 
--- a/doc/interpreter/plot.txi	Fri Mar 18 21:25:08 2011 -0700
+++ b/doc/interpreter/plot.txi	Fri Mar 18 22:47:33 2011 -0700
@@ -823,7 +823,8 @@
 
 The user can select points on a plot with the @code{ginput} function or
 selection the position at which to place text on the plot with the
-@code{gtext} function using the mouse.
+@code{gtext} function using the mouse.  Menus may also be created
+and populated with specific user commands via the @code{uimenu} function.
 
 @DOCSTRING(ginput)
 
@@ -831,6 +832,8 @@
 
 @DOCSTRING(gtext)
 
+@DOCSTRING(uimenu)
+
 @node Test Plotting Functions
 @subsection Test Plotting Functions
 
--- a/scripts/ChangeLog	Fri Mar 18 21:25:08 2011 -0700
+++ b/scripts/ChangeLog	Fri Mar 18 22:47:33 2011 -0700
@@ -1,3 +1,9 @@
+2010-03-18  Rik  <octave@nomad.inbox5.com>
+
+	* plot/uigetdir.m, plot/uigetfile.m, plot/uimenu.m, plot/uiputfile.m:
+	Improve docstrings.  Check for error conditions (missing FLTK, wrong
+	number of arguments) at top of code.
+
 2010-03-18  Rik  <octave@nomad.inbox5.com>
 
 	* general/curl.m, general/divergence.m, linear-algebra/cross.m:
--- a/scripts/plot/uigetdir.m	Fri Mar 18 21:25:08 2011 -0700
+++ b/scripts/plot/uigetdir.m	Fri Mar 18 22:47:33 2011 -0700
@@ -20,15 +20,20 @@
 ## @deftypefn  {Function File} {@var{dirname} =} uigetdir ()
 ## @deftypefnx {Function File} {@var{dirname} =} uigetdir (@var{init_path})
 ## @deftypefnx {Function File} {@var{dirname} =} uigetdir (@var{init_path}, @var{dialog_name})
-## Open a GUI dialog to select a directory.  If @var{init_path} is not given
-## the current working directory is used.  @var{dialog_name} optionally be
+## Open a GUI dialog for selecting a directory.  If @var{init_path} is not 
+## given the current working directory is used.  @var{dialog_name} may be
 ## used to customize the dialog title.
+## @seealso{uigetfile}
 ## @end deftypefn
 
 ## Author: Kai Habel
 
 function dirname = uigetdir (init_path = pwd, dialog_name = "Choose directory?")
 
+  if (exist("__fltk_uigetfile__") != 3)
+    error ("uigetfile: fltk graphics toolkit required");
+  endif
+
   if (nargin > 2)
     print_usage ();
   endif
@@ -37,14 +42,10 @@
     error ("uigetdir: INIT_PATH and DIALOG_NAME must be string arguments");
   endif
 
-  if (exist ("__fltk_uigetfile__") == 3)
-      if (!isdir (init_path))
-        init_path = fileparts (init_path);
-      endif
-      dirname = __fltk_uigetfile__ ("", dialog_name, init_path, [240, 120], "dir");
-  else
-    error ("uigetdir: fltk graphics toolkit required");
+  if (!isdir (init_path))
+    init_path = fileparts (init_path);
   endif
+  dirname = __fltk_uigetfile__ ("", dialog_name, init_path, [240, 120], "dir");
 
 endfunction
 
--- a/scripts/plot/uigetfile.m	Fri Mar 18 21:25:08 2011 -0700
+++ b/scripts/plot/uigetfile.m	Fri Mar 18 22:47:33 2011 -0700
@@ -17,29 +17,29 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn  {Function File} {[@var{fname}, @var{fpath}, @var{fltidx}] =} uigetfile (@var{flt})
+## @deftypefn  {Function File} {[@var{fname}, @var{fpath}, @var{fltidx}] =} uigetfile ()
+## @deftypefnx {Function File} {[@dots{}] =} uigetfile (@var{flt})
+## @deftypefnx {Function File} {[@dots{}] =} uigetfile (@var{flt}, @var{dialog_name})
 ## @deftypefnx {Function File} {[@dots{}] =} uigetfile (@var{flt}, @var{dialog_name}, @var{default_file})
-## @deftypefnx {Function File} {[@dots{}] =} uigetfile (@var{flt}, @var{dialog_name})
 ## @deftypefnx {Function File} {[@dots{}] =} uigetfile (@dots{}, "Position", [@var{px}, @var{py}])
-## @deftypefnx {Function File} {[@dots{}] =} uigetfile (@dots{}, "Multiselect", @var{mode})
+## @deftypefnx {Function File} {[@dots{}] =} uigetfile (@dots{}, "MultiSelect", @var{mode})
 ##
-## Open a GUI dialog to select a file.  It returns the filename @var{fname},
+## Open a GUI dialog for selecting a file.  It returns the filename @var{fname},
 ## the path to this file @var{fpath}, and the filter index @var{fltidx}.
 ## @var{flt} contains a (list of) file filter string(s) in one of the following
 ## formats:
 ##
 ## @table @asis
 ## @item "/path/to/filename.ext"
-## If a filename is given the file extension is extracted and used as filter.
-## In addtion the path is selected as current path and the filname is selected
-## as default file.
-## Example: @code{uigetfile ("myfun.m")}
+## 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: @code{uigetfile ("myfun.m")}
 ##
 ## @item A single file extension "*.ext"
 ## Example: @code{uigetfile ("*.ext")}
 ##
 ## @item A 2-column cell array
-## containing the file extension in the first column and a brief description
+## containing a file extension in the first column and a brief description
 ## in the second column.
 ## Example: @code{uigetfile (@{"*.ext", "My Description";"*.xyz",
 ## "XYZ-Format"@})}
@@ -51,12 +51,12 @@
 ## @end table
 ##
 ## @var{dialog_name} can be used to customize the dialog title.
-## If @var{default_file} is given it is selected in the GUI dialog.
-## If in addtion a path is given it is also used as current path.
+## If @var{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".
+## Two or more files can be selected when setting the "MultiSelect" key to "on".
 ## In that case @var{fname} is a cell array containing the files.
 ## @end deftypefn
 
@@ -64,98 +64,97 @@
 
 function [retfile, retpath, retindex] = uigetfile (varargin)
 
-  if (nargin <= 7)
-
-    defaultvals = {"All Files(*)", #FLTK File Filter
-                   "Open File?",   #Dialog Title
-                   pwd,            #FLTK default file name
-                   [240, 120],     #Dialog Position (pixel x/y)
-                   "off"};         #Multiselect on/off
-
-    outargs = cell (5, 1);
-    for i = 1 : 5
-      outargs{i} = defaultvals{i};
-    endfor
-
-    idx1 = idx2 = [];
-    if (length (varargin) > 0)
-      for i = 1 : length (varargin)
-        val = varargin{i};
-        if (ischar (val))
-          if (strncmp (tolower (val), "multiselect", 11))
-            idx1 = i;
-          elseif (strncmp(tolower (val), "position", 8))
-            idx2 = i;
-          endif
-        endif
-      endfor
-    endif
-
-    stridx = [idx1, idx2, 0];
-    if (length (stridx) > 1)
-      stridx = min (stridx(1 : end - 1));
-    endif
-
-    args = varargin;
-    if (stridx)
-      args = varargin(1 : stridx - 1);
-    endif
+  if (exist("__fltk_uigetfile__") != 3)
+    error ("uigetfile: fltk graphics toolkit required");
+  endif
 
-    len = length (args);
-    if (len > 0)
-      file_filter = args{1};
-      outargs{1} = __fltk_file_filter__ (file_filter);
-      if (ischar (file_filter))
-        outargs{3} = file_filter;
-      endif
-    endif
-
-    if (len > 1)
-      outargs{2} = args{2};
-    endif
-
-    if (len > 2)
-      outargs{3} = args{3};
-    endif
-
-    if (stridx)
-      ## we have string arguments ("position" or "multiselect")
-
-      ## check for even number of remaining arguments, prop/value pair(s)
-      if (rem (nargin - stridx + 1, 2))
-        error ("uigetfile: expecting property/value pairs");
-      endif
-
-      for i = stridx : 2 : nargin
-        prop = varargin{i};
-        val = varargin{i + 1};
-        if (strncmp (tolower (prop), "position", 8))
-          if (ismatrix (val) && length(val) == 2)
-            outargs{4} = val;
-          else
-            error ("uigetfile: expecting 2-element vector for position argument");
-          endif
-        elseif (strncmp (tolower (prop), "multiselect", 11))
-          if (ischar (val))
-            outargs{5} = tolower (val);
-          else
-            error ("uigetfile: expecting string argument (on/off) for multiselect");
-          endif
-        else
-          error ("uigetfile: unknown argument");
-        endif
-      endfor
-    endif
-  else
+  if (nargin > 7)
     error ("uigetfile: number of input arguments must be less than eight");
   endif
 
-  if (exist("__fltk_uigetfile__") == 3)
-    [retfile, retpath, retindex] = __fltk_uigetfile__ (outargs{:});
-  else
-    error ("uigetfile: fltk graphics toolkit required");
+  defaultvals = {"All Files(*)", #FLTK File Filter
+                 "Open File?",   #Dialog Title
+                 pwd,            #FLTK default file name
+                 [240, 120],     #Dialog Position (pixel x/y)
+                 "off"};         #MultiSelect on/off
+
+  outargs = cell (5, 1);
+  for i = 1 : 5
+    outargs{i} = defaultvals{i};
+  endfor
+
+  idx1 = idx2 = [];
+  if (length (varargin) > 0)
+    for i = 1 : length (varargin)
+      val = varargin{i};
+      if (ischar (val))
+        if (strncmp (tolower (val), "multiselect", 11))
+          idx1 = i;
+        elseif (strncmp(tolower (val), "position", 8))
+          idx2 = i;
+        endif
+      endif
+    endfor
+  endif
+
+  stridx = [idx1, idx2, 0];
+  if (length (stridx) > 1)
+    stridx = min (stridx(1 : end - 1));
+  endif
+
+  args = varargin;
+  if (stridx)
+    args = varargin(1 : stridx - 1);
   endif
 
+  len = length (args);
+  if (len > 0)
+    file_filter = args{1};
+    outargs{1} = __fltk_file_filter__ (file_filter);
+    if (ischar (file_filter))
+      outargs{3} = file_filter;
+    endif
+  endif
+
+  if (len > 1)
+    outargs{2} = args{2};
+  endif
+
+  if (len > 2)
+    outargs{3} = args{3};
+  endif
+
+  if (stridx)
+    ## we have string arguments ("position" or "multiselect")
+
+    ## check for even number of remaining arguments, prop/value pair(s)
+    if (rem (nargin - stridx + 1, 2))
+      error ("uigetfile: expecting property/value pairs");
+    endif
+
+    for i = stridx : 2 : nargin
+      prop = varargin{i};
+      val = varargin{i + 1};
+      if (strncmp (tolower (prop), "position", 8))
+        if (ismatrix (val) && length(val) == 2)
+          outargs{4} = val;
+        else
+          error ("uigetfile: expecting 2-element vector for position argument");
+        endif
+      elseif (strncmp (tolower (prop), "multiselect", 11))
+        if (ischar (val))
+          outargs{5} = tolower (val);
+        else
+          error ("uigetfile: expecting string argument (on/off) for multiselect");
+        endif
+      else
+        error ("uigetfile: unknown argument");
+      endif
+    endfor
+  endif
+
+  [retfile, retpath, retindex] = __fltk_uigetfile__ (outargs{:});
+
 endfunction
 
 %!demo
--- a/scripts/plot/uimenu.m	Fri Mar 18 21:25:08 2011 -0700
+++ b/scripts/plot/uimenu.m	Fri Mar 18 22:47:33 2011 -0700
@@ -19,15 +19,15 @@
 ## -*- texinfo -*-
 ## @deftypefn  {Function File} {} uimenu (@var{property}, @var{value}, @dots{})
 ## @deftypefnx {Function File} {} uimenu (@var{h}, @var{property}, @var{value}, @dots{})
-## Create an uimenu object and return a handle to it.  If @var{h} is ommited
-## then a top level menu entry for the current figure is created.  If @var{h}
+## Create a uimenu object and return a handle to it.  If @var{h} is ommited
+## then a top-level menu for the current figure is created.  If @var{h}
 ## is given then a submenu relative to @var{h} is created.
 ##
-## Uimenu objects have the following specific properties:
+## uimenu objects have the following specific properties:
 ##
 ## @table @asis
 ## @item "accelerator"
-## A string containg the key combination together with CTRL to execute this
+## A string containing the key combination together with CTRL to execute this
 ## menu entry (e.g., "x" for CTRL+x).
 ##
 ## @item "callback"
@@ -48,7 +48,7 @@
 ##
 ## @item "label"
 ## A string containing the label for this menu entry.  A "&"-symbol can be
-## used to mark the "accelerator" character (e.g., "E&xit")
+## used to mark the "accelerator" character (e.g., @nospell{"E&xit"})
 ##
 ## @item "position"
 ## An scalar value containing the relative menu position.  The entry with the
@@ -58,7 +58,6 @@
 ## Can be set "on" or "off".  If enabled it draws a separator line above the
 ## current position.  It is ignored for top level entries.
 ##
-##
 ## @end table
 ##
 ## Examples:
--- a/scripts/plot/uiputfile.m	Fri Mar 18 21:25:08 2011 -0700
+++ b/scripts/plot/uiputfile.m	Fri Mar 18 22:47:33 2011 -0700
@@ -17,18 +17,18 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn  {Function File} {[@var{fname}, @var{fpath}, @var{fltidx}] =} uiputfile (@var{flt}, @var{dialog_name}, @var{default_file})
-## @deftypefnx {Function File} {[@var{fname}, @var{fpath}, @var{fltidx}] =} uiputfile (@var{flt}, @var{dialog_name})
+## @deftypefn  {Function File} {[@var{fname}, @var{fpath}, @var{fltidx}] =} uiputfile ()
 ## @deftypefnx {Function File} {[@var{fname}, @var{fpath}, @var{fltidx}] =} uiputfile (@var{flt})
-## @deftypefnx {Function File} {[@var{fname}, @var{fpath}, @var{fltidx}] =} uiputfile ())
-## Open a GUI dialog to select a file.  @var{flt} contains a (list of) file
+## @deftypefnx {Function File} {[@var{fname}, @var{fpath}, @var{fltidx}] =} uiputfile (@var{flt}, @var{dialog_name})
+## @deftypefnx {Function File} {[@var{fname}, @var{fpath}, @var{fltidx}] =} uiputfile (@var{flt}, @var{dialog_name}, @var{default_file})
+## Open a GUI dialog for selecting a file.  @var{flt} contains a (list of) file
 ## filter string(s) in one of the following formats:
 ##
 ## @table @code
 ## @item "/path/to/filename.ext"
 ## If a filename is given the file extension is
 ## extracted and used as filter.
-## In addtion the path is selected as current path and the filname is selected
+## In addition the path is selected as current path and the filename is selected
 ## as default file.
 ## Example: uiputfile("myfun.m");
 ##
@@ -48,52 +48,50 @@
 ##
 ## @var{dialog_name} can be used to customize the dialog title.
 ## If @var{default_file} is given it is preselected in the GUI dialog.
-## If in addtion a path is given it is also used as current path.
+## If, in addition, a path is given it is also used as current path.
 ## @end deftypefn
 
 ## Author: Kai Habel
 
 function [retfile, retpath, retindex] = uiputfile (varargin)
 
-  if (nargin <= 3)
-
-    defaultvals = {"All Files(*)", #FLTK File Filter
-                   "Save File?",   #Dialog Title
-                   pwd,            #FLTK default file name
-                   [240, 120],     #Dialog Position (pixel x/y)
-                   "create"};
-
-    outargs = cell(5, 1);
-    for i = 1 : 5
-      outargs{i} = defaultvals{i};
-    endfor
+  if (exist("__fltk_uigetfile__") != 3)
+    error ("uiputfile: fltk graphics toolkit required");
+  endif
 
-    if (nargin > 0)
-      file_filter = varargin{1};
-      outargs{1} = __fltk_file_filter__ (file_filter);
-      if (ischar (file_filter))
-        outargs{3} = file_filter;
-      endif
-    endif
-
-    if (nargin > 1)
-      outargs{2} = varargin{2};
-    endif
-
-    if (nargin > 2)
-      outargs{3} = varargin{3};
-    endif
-
-  else
-    error ("uiputfile: number of input arguments must be less than four");
+  if (nargin > 3)
+    print_usage ();
   endif
 
-  if (exist("__fltk_uigetfile__") == 3)
-    [retfile, retpath, retindex] = __fltk_uigetfile__ (outargs{:});
-  else
-    error ("uiputfile: fltk graphics toolkit required");
+  defaultvals = {"All Files(*)", #FLTK File Filter
+                 "Save File?",   #Dialog Title
+                 pwd,            #FLTK default file name
+                 [240, 120],     #Dialog Position (pixel x/y)
+                 "create"};
+
+  outargs = cell(5, 1);
+  for i = 1 : 5
+    outargs{i} = defaultvals{i};
+  endfor
+
+  if (nargin > 0)
+    file_filter = varargin{1};
+    outargs{1} = __fltk_file_filter__ (file_filter);
+    if (ischar (file_filter))
+      outargs{3} = file_filter;
+    endif
   endif
 
+  if (nargin > 1)
+    outargs{2} = varargin{2};
+  endif
+
+  if (nargin > 2)
+    outargs{3} = varargin{3};
+  endif
+
+  [retfile, retpath, retindex] = __fltk_uigetfile__ (outargs{:});
+
 endfunction
 
 %!demo