From: <car...@us...> - 2010-04-23 20:30:38
|
Revision: 7233 http://octave.svn.sourceforge.net/octave/?rev=7233&view=rev Author: carandraug Date: 2010-04-23 20:30:27 +0000 (Fri, 23 Apr 2010) Log Message: ----------- New option for zenity list named 'numeric output' and bug fix that returned string when array or matrix was expected. Modified Paths: -------------- trunk/octave-forge/main/zenity/inst/_zenity_options_.m trunk/octave-forge/main/zenity/inst/zenity_list.m Modified: trunk/octave-forge/main/zenity/inst/_zenity_options_.m =================================================================== --- trunk/octave-forge/main/zenity/inst/_zenity_options_.m 2010-04-23 14:19:17 UTC (rev 7232) +++ trunk/octave-forge/main/zenity/inst/_zenity_options_.m 2010-04-23 20:30:27 UTC (rev 7233) @@ -69,7 +69,7 @@ op.separator = op.text = op.hide = op.print_col = ""; op.multiple = op.radio = op.check = op.editable = ""; op.hide_max = op.hide_min = op.print_max = op.print_min = ""; - op.print_numel = ""; + op.print_numel = op.num_out = ""; elseif (strcmpi(dialog, "message")) op.type = op.wrap = ""; elseif (strcmpi(dialog, "notification")) @@ -202,7 +202,6 @@ endif ## Process options for ZENITY_LIST - ## TODO should an option to change the separator be set for list? elseif ( strcmpi(dialog, "list") ) if (strcmpi(param,"text")) # List - text narg = sanity_checks ("char", param, value, op.text, narg); @@ -219,6 +218,9 @@ elseif (strcmpi(param,"checklist")) # List - checklist narg = sanity_checks ("indie", param, value, op.check, narg); op.check = "--checklist"; + elseif (strcmpi(param,"numeric output")) # List - numeric output + narg = sanity_checks ("char", param, value, op.num_out, narg); + op.num_out = value; elseif (strcmpi(param,"hide column")) # List - hide column narg = sanity_checks ("num", param, value, op.hide, narg); op.hide_min = min(value(:)); Modified: trunk/octave-forge/main/zenity/inst/zenity_list.m =================================================================== --- trunk/octave-forge/main/zenity/inst/zenity_list.m 2010-04-23 14:19:17 UTC (rev 7232) +++ trunk/octave-forge/main/zenity/inst/zenity_list.m 2010-04-23 20:30:27 UTC (rev 7233) @@ -107,6 +107,18 @@ ## together with parameter @code{radiolist}. and it is automatically set when ## parameter @code{checklist} is set. ## +## @item numeric output +## Returns @var{selected} as a matrix and numeric values (double precision type) +## instead of cell array of strings. It uses the function str2double for the +## conversion. Requires a string as value. Possible values are: +## +## @table @samp +## @item error +## Abort the function and return an error if unable to covert into numeric form. +## @item nan +## Returns NaN for the values it is unable to convert. +## @end table +## ## @item print column ## The numbers of the columns whose values should be returned. Requires a numeric ## data type as value. Multiple columns can be selected with ranges or matrixes, @@ -142,7 +154,7 @@ ## zenity_notification} ## @end deftypefn -function [val, status] = zenity_list(col, data, varargin) +function [val, status, tmp] = zenity_list(col, data, varargin) ## List of things that cannot be done: ## * editable cannot be set at the same time of checklist or radiolist @@ -272,7 +284,15 @@ # functions to close the dialog # Exit code 5 = The dialog has been closed because the timeout has been reached - if ( options.print_min == 0 && (!isempty(options.check) || !isempty(options.radio)) ) + # If it would be possible for the function to return more than one value + if ( !isempty(options.check) || !isempty(options.multiple) || options.print_numel > 1) + multi = 1; + else + multi = 0; + endif + + # Calculate the number of expected columns + if ( options.print_min == 0 && (options.check || options.radio) ) expec_col = numel(col) -1; elseif (options.print_min == 0) expec_col = numel(col); @@ -285,7 +305,7 @@ if (status == 0) ## User can press OK without selecting anything which returns empty string if (isempty(output) || (numel(output) == 1 && output(end) == "\n") ) - if (expec_col > 1) + if (multi) val = cell(1,expec_col); else val = ""; @@ -296,9 +316,9 @@ if (output(end) == "\n") output = output(1:end-1); endif - ## When 'multiple' values are expected, always place the output in a cell - ##array, even if only one file is selected. - if (expec_col > 1) + ## When 'multiple' values are expected, always place the output in a cell + ## array, even if only one file is selected. + if (multi) idx = strfind(output, '/\|/\'); if (idx) tmp_val = cell(length(idx)+1, 1); @@ -320,17 +340,26 @@ else val = output; endif - elseif (status == 1 && expec_col > 1) + elseif (multi && (status == 1 || status == 5)) val = cell(1, expec_col); - elseif (status == 1) + elseif (status == 1 || status ==5) val = ""; - elseif (status == 5 && expec_col > 1) - val = cell(1, expec_col); - elseif (status == 5) - val = ""; else error("An unexpected error occurred with exit code '%i' and output '%s'.",... status, output); endif + if (options.num_out) + [val, sta] = str2double(val); + if (strcmpi(options.num_out, "error")) + if ( any(sta(:)) ) + error("Conversion of output to numeric form was unsucessful") + endif + elseif (strcmpi(options.num_out, "nan")) + ## Do nothing + else + error("Unknow value '%s' for the parameter 'numeric output'", option) + endif + endif + endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |