From: <car...@us...> - 2010-04-25 06:20:18
|
Revision: 7236 http://octave.svn.sourceforge.net/octave/?rev=7236&view=rev Author: carandraug Date: 2010-04-25 06:20:12 +0000 (Sun, 25 Apr 2010) Log Message: ----------- Complete rewrite of the function which now does something completely different. Start the process and creates a pipe instead of a sync process. The pipe can be used to create pop up messages, change the icon and close the icon. Modified Paths: -------------- trunk/octave-forge/main/zenity/inst/_zenity_options_.m trunk/octave-forge/main/zenity/inst/zenity_notification.m Modified: trunk/octave-forge/main/zenity/inst/_zenity_options_.m =================================================================== --- trunk/octave-forge/main/zenity/inst/_zenity_options_.m 2010-04-24 00:17:57 UTC (rev 7235) +++ trunk/octave-forge/main/zenity/inst/_zenity_options_.m 2010-04-25 06:20:12 UTC (rev 7236) @@ -57,7 +57,7 @@ # varargin(end) = []; # By using (end), it actually pulls the value out instead of leaving it empty # endif - op.title = op.width = op.height = op.timeout = op.icon = ""; + op.title = op.width = op.height = op.timeout = ""; if ( !ischar(dialog) ) error ("Type of dialog should be a string"); elseif (strcmpi(dialog, "calendar")) @@ -72,8 +72,10 @@ op.print_numel = op.num_out = ""; elseif (strcmpi(dialog, "message")) op.type = op.wrap = ""; - elseif (strcmpi(dialog, "notification")) - op.text = ""; + elseif (strcmpi(dialog, "new notification")) + op.text = op.icon = ""; + elseif (strcmpi(dialog, "piped notification")) + op.text = op.icon = op.message = ""; elseif (strcmpi(dialog, "progress")) elseif (strcmpi(dialog, "scale")) elseif (strcmpi(dialog, "text info")) @@ -110,35 +112,22 @@ ## Process ALL GENERAL OPTIONS first elseif (strcmpi(param,"title")) # General - title narg = sanity_checks ("char", param, value, op.title, narg); - op.title = sprintf("--title=\"%s\"", value); + op.title = sprintf('--title="%s"', value); elseif (strcmpi(param,"width")) # General - width narg = sanity_checks ("scalar", param, value, op.width, narg); - op.width = sprintf("--width=\"%s\"", num2str(value)); + op.width = sprintf('--width="%s"', num2str(value)); elseif (strcmpi(param,"height")) # General - height narg = sanity_checks ("scalar", param, value, op.height, narg); - op.height = sprintf("--height=\"%s\"", num2str(value)); + op.height = sprintf('--height="%s"', num2str(value)); elseif (strcmpi(param,"timeout")) # General - timeout narg = sanity_checks ("scalar", param, value, op.timeout, narg); - op.timeout = sprintf("--timeout=\"%s\"", num2str(value)); - elseif (strcmpi(param,"icon")) # General - icon - narg = sanity_checks ("char", param, value, op.icon, narg); - if (strcmpi(value, "error")) - op.icon = "--window-icon=\"error\""; - elseif (strcmpi(value, "info")) - op.icon = "--window-icon=\"info\""; - elseif (strcmpi(value, "question")) - op.icon = "--window-icon=\"question\""; - elseif (strcmpi(value, "warning")) - op.icon = "--window-icon=\"warning\""; - else - op.icon = sprintf("--window-icon=\"%s\"", value); - endif + op.timeout = sprintf('--timeout="%s"', num2str(value)); ## Process options for ZENITY_ENTRY elseif ( strcmpi(dialog, "entry") ) if (strcmpi(param,"entry")) # Entry - entry text narg = sanity_checks ("char", param, value, op.entry, narg); - op.entry = sprintf("--entry-text=\"%s\"", value); + op.entry = sprintf('--entry-text="%s"', value); elseif (strcmpi(param,"password")) # Entry - password narg = sanity_checks ("indie", param, value, op.password, narg); op.password = "--hide-text"; @@ -153,10 +142,10 @@ op.directory = "--directory"; elseif (strcmpi(param,"filename")) # File selection - filename narg = sanity_checks ("char", param, value, op.filename, narg); - op.filename = sprintf("--filename=\"%s\"", value); + op.filename = sprintf('--filename="%s"', value); elseif (strcmpi(param,"filter")) # File selection - file filter narg = sanity_checks ("multiple-char", param, value, op.directory, narg); - op.filter = sprintf("%s --file-filter=\"%s\"", op.filter, value); + op.filter = sprintf('%s --file-filter="%s"', op.filter, value); elseif (strcmpi(param,"multiple")) # File selection - multiple narg = sanity_checks ("indie", param, value, op.multiple, narg); op.multiple = "--multiple"; @@ -192,20 +181,59 @@ error ("Parameter '%s' is not supported for '%s' dialog.", param, dialog); endif - ## Process options for ZENITY_NOTIFICATION - elseif ( strcmpi(dialog, "notification") ) + ## Process options for ZENITY_NOTIFICATION (creating new) + elseif ( strcmpi(dialog, "new notification") ) if (strcmpi(param,"text")) # Notification - text narg = sanity_checks ("char", param, value, op.text, narg); - op.text = sprintf("--text=\"%s\"", value); + op.text = sprintf('--text="%s"', value); + elseif (strcmpi(param,"icon")) # Notification - icon + narg = sanity_checks ("char", param, value, op.icon, narg); + if (strcmpi(value, "error")) + op.icon = '--window-icon="error"'; + elseif (strcmpi(value, "info")) + op.icon = '--window-icon="info"'; + elseif (strcmpi(value, "question")) + op.icon = '--window-icon="question"'; + elseif (strcmpi(value, "warning")) + op.icon = '--window-icon="warning"'; + else + op.icon = sprintf('--window-icon="%s"', value); + endif else error ("Parameter '%s' is not supported for '%s' dialog.", param, dialog); endif + ## Process options for ZENITY_NOTIFICATION (pipelining) + elseif ( strcmpi(dialog, "piped notification") ) + if (strcmpi(param,"text")) # Notification - text + narg = sanity_checks ("char", param, value, op.text, narg); + op.text = sprintf('tooltip: %s', value); + elseif (strcmpi(param,"message")) # Notification - message + narg = sanity_checks ("char", param, value, op.message, narg); + op.message = sprintf('message: %s', value); + elseif (strcmpi(param,"icon")) # Notification - icon + narg = sanity_checks ("char", param, value, op.icon, narg); + if (strcmpi(value, "error")) + op.icon = 'icon: error'; + elseif (strcmpi(value, "info")) + op.icon = 'icon: info'; + elseif (strcmpi(value, "question")) + op.icon = 'icon: question'; + elseif (strcmpi(value, "warning")) + op.icon = 'icon: warning'; + else + op.icon = sprintf('icon: %s', value); + endif + else + error ("Parameter '%s' is not supported for '%s' dialog.", param, dialog); + endif + + ## Process options for ZENITY_LIST elseif ( strcmpi(dialog, "list") ) if (strcmpi(param,"text")) # List - text narg = sanity_checks ("char", param, value, op.text, narg); - op.text = sprintf("--text=\"%s\"", value); + op.text = sprintf('--text="%s"', value); elseif (strcmpi(param,"editable")) # List - editable narg = sanity_checks ("indie", param, value, op.editable, narg); op.editable = "--editable"; @@ -228,9 +256,9 @@ tmp = ""; for i = 1:numel(value) str = num2str(value(i)); - tmp = sprintf("%s%s,", tmp, str); + tmp = sprintf('%s%s,', tmp, str); endfor - op.hide = sprintf("--hide-column=\"%s\"", tmp); + op.hide = sprintf('--hide-column="%s"', tmp); elseif (strcmpi(param,"print column")) # List - print column narg = sanity_checks ("num", param, value, op.print_col, narg); op.print_min = min(value(:)); @@ -243,9 +271,9 @@ break endif str = num2str(value(i)); - tmp = sprintf("%s%s,", tmp, str); + tmp = sprintf('%s%s,', tmp, str); endfor - op.print_col = sprintf("--print-column=\"%s\"", tmp); + op.print_col = sprintf('--print-column="%s"', tmp); else error ("Parameter '%s' is not supported for '%s' dialog.", param, dialog); endif @@ -262,9 +290,9 @@ if ( isempty(op.type) ) op.type = "--info"; endif - elseif (strcmpi(dialog,"notification")) # Defaults for notification + elseif (strcmpi(dialog,"new notification")) # Defaults for notification if ( isempty(op.icon) ) - op.icon = "--window-icon=\"warning\""; + op.icon = '--window-icon="warning"'; endif endif Modified: trunk/octave-forge/main/zenity/inst/zenity_notification.m =================================================================== --- trunk/octave-forge/main/zenity/inst/zenity_notification.m 2010-04-24 00:17:57 UTC (rev 7235) +++ trunk/octave-forge/main/zenity/inst/zenity_notification.m 2010-04-25 06:20:12 UTC (rev 7236) @@ -15,20 +15,55 @@ ## along with this program; If not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} status = zenity_notification(@var{param1}, @var{value1}, ...) -## Displays an icon with a text in the notification area using Zenity. +## @deftypefn {Function File} @var{h} = zenity_notification +## @deftypefnx {Function File} @var{h} = zenity_notification (@var{param1}, @var{value1}, ...) +## @deftypefnx {Function File} @var{s} = zenity_notification (@var{h}, @var{param1}, @var{value1}, ...) +## @deftypefnx {Function File} @var{s} = zenity_notification (@var{h}, "close") +## Displays an icon with a text in the notification area, and pop up messages +## using Zenity. ## -## @var{status} is the exit code of the function and has a value of @code{0} if -## it is pressed; @code{1} if @option{Close} is pressed or the window -## functions are used to close it; or @code{5} if timeout has been reached. +## The first and second forms of the @code{zenity_notification} function creates +## a new notification icon with whatever parameters are set, and return the +## handle @var{h} for later interaction with the notification icon. ## -## All variables are optional but if given, may require a corresponding +## The third form of the @code{zenity_notification} function changes the +## parameteres of the existing icon and/or displays popup messages given the +## handle @var{h}. Returns @code{0} on success and @code{1} on error. +## +## The fourth form of the @code{zenity_notification} function closes the +## notification icon given the handle @var{h} followed by the string +## @code{close}. Returns @code{0} on success and @code{1} on error. +## +## The following example, creates a notification info icon in the notification +## panel that shows the text @samp{working} when the mouse is over the +## icon. Then shows a pop up message saying @samp{step 1 started} followed by +## another saying @samp{"error during step 1} all the while changing the icon +## from info to error. It then finnaly closes the icon, removing it from the +## notification panel. Trough all the example, the text stays @samp{working}. +## +## @example +## h = zenity_notification ("text", "working", "icon", "info") +## zenity_notification (h, "message", "step 1 started") +## zenity_notification (h, "message", "error during step 1", "icon", "error") +## zenity_notification (h, "close") +## @end example +## +## All @var{parameters} are optional but if given, may require a corresponding ## @var{value}. All possible parameters are: ## ## @table @samp +## @item message +## Shows a pop up notification. Requires a string as value and Can only be used +## is the notification icon already exists. Newline characters are illegal +## characters and will be replaced by a space from the message. +## +## Note: the duration of the message as well as the time interval between +## consequent messages is defined by the user's system preferences. +## ## @item icon -## Sets the icon of notification. Requires a string as value. It can either be -## the path for an image or one of the four default icons: +## Sets or changes new or existent notification icons. Requires a string as +## value. It can either be the path for an image or one of the four default +## icons: ## ## @table @samp ## @item error @@ -36,34 +71,91 @@ ## @item question ## @item warning (default) ## @end table +## +## Note: The icon will also appear next to any message. +## ## @item text -## Sets the notification text. Requires a string as value. +## Sets the notification text. Requires a string as value. This text appears +## when the mouse is placed over the icon. To show a popup notification, use +## @code{message}. +## ## @item timeout ## Sets the time in seconds after which the dialog is closed. Requires a scalar -## as value. +## as value and can only be set when creating a new icon. ## @end table ## ## @seealso{zenity_progress, zenity_message} ## @end deftypefn -function [output status] = zenity_notification (varargin) +function sta = zenity_notification (varargin) - options = _zenity_options_ ("notification", varargin); + ## If no arguments, open a new notification + if ( nargin == 0 ) + pipelining = 0; + ## If first argument is the fid for an already open notification, remove it + ## from varargin (remove it != empty it) before feeding to _zenity_options_ + elseif (isscalar (varargin{1}) && isnumeric(varargin{1}) ) + pipelining = 1; + handle = varargin{1}; + varargin(1) = []; + elseif ( ischar(varargin{1}) && strcmpi(varargin{1}, "close") ) + error("Argument to close was given, but not the handle.") + else + pipelining = 0; + endif - pre_cmd = sprintf("%s ", ... - options.icon, options.text, options.timeout); - - cmd = sprintf("zenity --notification --listen %s", pre_cmd); - [status, output] = system(cmd); - ## 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 || status == 1 || status == 5) - return + if (pipelining) + ## If the first argument after the handle is the string 'close' say 'bye bye' + if ( ischar(varargin{1}) && strcmpi(varargin{1}, "close") ) + if (nargin > 2) + warning ("There's %g argument(s) after '%s' which will be ignored", (nargin-2), varargin{1}) + endif + try + pclose(handle); + sta = 0; + catch + sta = -1; + end_try_catch +# ## Commented because function should return the exit code +# if (sta != 0) +# error ("Error when closing zenity notification"); +# endif + return + endif + options = _zenity_options_ ("piped notification", varargin); + ## Must add the new line only if they exist or zenity will complain about + ## not being able to parse some of the lines. + ## Atention to whitespace after the command. Example: + ## " icon:question" <-- no error, changes icon for question correctly + ## "icon:question " <-- error, unable to fid the icon + options.icon = add_newline (options.icon); + options.text = add_newline (options.text); + options.message = add_newline (options.message); + ## icon comes first so that if there's a new message it already comes + ## with the new icon (the icon is also present on the messages, not only in + ## the panel) + pre_cmd = sprintf("%s", ... + options.icon, options.text, options.message); + try + fputs(handle, pre_cmd); + sta = 0; + catch + sta = -1; + end_try_catch else - error("An unexpected error occurred with exit code '%i' and output '%s'",... - status, output); + options = _zenity_options_ ("new notification", varargin); + pre_cmd = sprintf("%s ", ... + options.icon, options.text, options.timeout); + cmd = sprintf("zenity --notification --listen %s", pre_cmd); + sta = popen(cmd, "w"); endif + endfunction + +### Add new lines only if the option exist and replace other newlines that may be +function val = add_newline (val) + if(!isempty(val)) + val = strrep (val, "\n", " "); + val = sprintf("%s\n", val); + endif +endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |