changeset 6966:620cfd0c98c4 octave-forge

New options to control size of window message. New option to block text wrapping. New option to set a timeout. New option to set the title of the message window. Options are no longer case-sensitive. Improved documentation.
author carandraug
date Sun, 04 Apr 2010 06:56:52 +0000
parents a491fb6de829
children 7b5c55db4399
files main/zenity/inst/zenity_message.m
diffstat 1 files changed, 88 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/main/zenity/inst/zenity_message.m	Sat Apr 03 03:48:04 2010 +0000
+++ b/main/zenity/inst/zenity_message.m	Sun Apr 04 06:56:52 2010 +0000
@@ -1,4 +1,5 @@
 ## Copyright (C) 2006  Søren Hauberg
+## Copyright (C) 2010  Carnë Draug
 ## 
 ## This program is free software; you can redistribute it and/or modify
 ## it under the terms of the GNU General Public License as published by
@@ -14,30 +15,100 @@
 ## along with this program; If not, see <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn  {Function File} zenity_message(@var{text}, @var{type})
-## Displays a graphical message dialog.
-## The variable @var{text} sets the message of the dialog, and the
-## optional variable @var{type} sets the type of the message.
-## @var{type} must be one of the following strings @code{error},
-## @code{info}, @code{question}, and @code{warning}. The default
-## value of @var{type} is @code{info}. Retuns the value @code{status}
-## which is 0 for 'Ok' and 1 for 'Cancel' button selection; a value 
-## of -1 indicates a failure of dialog box.
+## @deftypefn  {Function File} @var{status} = zenity_message(@var{text}, @var{type}, @var{option1}, ...)
+## Displays a graphical message dialog using Zenity.
+##
+## Returns 0 if `OK' is pressed; 1 if `close' is pressed or the window
+## functions are used to close it; or 5 if timeout has been reached.
+##
+## The variable @var{text} sets the message of the dialog. The @var{type} of
+## message can be:
+## @table @samp
+## @item error
+## Creates an error dialog.
+## @item info
+## Creates an information dialog (default).
+## @item question
+## Creates a question dialog.
+## @item warning
+## Creates a warning dialog.
+## @end table
+##
+## The @var{option} string arguments can be:
+## @table @samp
+## @item title=@var{title}
+## Sets the title of the message window. If no title is specified, defaults to
+## the type of message.
+## @item no-wrap
+## Do not enable text wrapping.
+## @item width=@var{width}
+## Sets the message window width.
+## @item height=@var{height}
+## Sets the message window heigth.
+## @item timeout=@var{time}
+## Specifies @var{time} in seconds after which the dialog is closed.
+## @end table
 ##
 ## @seealso{zenity_calendar, zenity_list, zenity_progress, zenity_entry,
 ## zenity_text_info, zenity_file_selection, zenity_notification}
 ## @end deftypefn
 
-function status=zenity_message(text, type)
-  if (nargin == 0 || !ischar(text)), print_usage(); endif
-  if (nargin < 2), type = "info"; endif
-  if !(ischar(type) && any(strcmp(type, {"error", "info", "question", "warning"})))
-    error("zenity_message: unsupported message type: %s", type);
+function status=zenity_message(text, type, varargin)
+
+  title = timeout = wrap = width = height= "";
+  if (nargin == 0 || !ischar(text))
+    print_usage();
+    return
+  elseif (nargin == 1)
+    type = "info";
+  elseif (nargin >= 2)
+    if (strcmpi(type,"error"))
+      type = "error";
+    elseif (strcmpi(type,"info"))
+      type = "info";
+    elseif (strcmpi(type,"question"))
+      type = "question";
+    elseif (strcmpi(type,"warning"))
+      type = "warning";
+    else
+      error("zenity_message: unsupported message type: %s", type);
+    endif
   endif
-  
-  cmd = sprintf('zenity --%s --text="%s"', type, text);
+
+  if (nargin > 2)
+    for i = 1:length(varargin)
+      option  = varargin{i};
+      isc     = ischar(option);
+      if (isc && regexpi(option, "^title=") )
+        title = ["--title=", option(7:end)];
+      elseif (isc && strcmpi(option, "no-wrap") )
+        wrap = "--no-wrap";
+      elseif (isc && regexpi(option, "^width=") )
+        width = ["--width=", option(7:end)];
+      elseif (isc && regexpi(option, "^height=") )
+        height = ["--height=", option(8:end)];
+      elseif (isc && regexpi(option, "^timeout=") )
+        timeout = ["--timeout=", option(9:end)];
+      else
+        error ("zenity_message: unsupported option");
+      endif
+    endfor
+  endif
+
+  cmd = sprintf('zenity --%s --text="%s" %s %s %s %s %s', ...
+                  type, text, title, timeout, wrap, width, height)
   [status, output] = system(cmd);
-  if (status == -1)
+
+# Exit code -1 = An unexpected error has occurred
+# Exit code  0 = The user has pressed either OK or Close. 
+# Exit code  1 = The user has either pressed Cancel, or used the window
+# functions to close the dialog
+# Exit code  5 = The dialog has been closed because the timeout has been reached
+  if (status == 0 || 1 || 5)
+    return
+  elseif (status == -1)
+    error("An unexpected error occurred: %s", output);
+  else
     error("zenity_message: %s", output);
   endif
 endfunction