1 ## Copyright (C) 2006 Søren Hauberg
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 2 of the License, or
6 ## (at your option) any later version.
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ## GNU General Public License for more details.
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; If not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function File} @var{s} = zenity_list(@var{title}, @var{columns}, @var{data}, @var{options1}, ...)
18 ## Displays a graphical list of data.
19 ## The variable @var{title} sets the title of the list. The variable
20 ## @var{columns} must be a cell array of strings of length N containing the headers
21 ## of the list. The variable @var{data} must be cell array of strings of
22 ## length NxM containing the data of the list.
26 ## zenity_list("Age versus Height", @{"Age", "Height"@},
27 ## @{"10", "20"; "120cm", "180cm"@})
29 ## produces a list of the data. The user can select a row in the table, and it's
30 ## first value will be returned by the function when the user closes the window.
32 ## It's possible to alter the behaviour of the list window by passing more than
33 ## three arguments to the funtion. Theese optional string arguments can be
36 ## The first row in the list will be a check box. The first value of each data row
37 ## must be either "TRUE" or "FALSE".
39 ## The first row in the list will be a radio list. The first value of each data row
40 ## must be either "TRUE" or "FALSE".
42 ## The values of the list will be editable by the user.
43 ## @item A numeric value
44 ## The value returned by the function will be the value of this column
45 ## of the user selected row.
47 ## The value returned by the function will be the entire row selected by the user.
50 ## @seealso{zenity_calendar, zenity_progress, zenity_entry, zenity_message,
51 ## zenity_text_info, zenity_file_selection, zenity_notification}
54 function s = zenity_list(title, columns, data, varargin)
55 if (nargin < 3 || !ischar(title) || !iscellstr(columns) || !iscellstr(data))
59 checklist = radiolist = editable = "";
61 for i = 1:length(varargin)
64 if (isc && strcmpi(option, "checklist"))
65 checklist = "--checklist";
66 elseif (isc && strcmpi(option, "radiolist"))
67 radiolist = "--radiolist";
68 elseif (isc && strcmpi(option, "editable"))
69 editable = "--editable";
70 elseif (isc && strcmpi(option, "all"))
72 elseif (isnumeric(option))
73 print_column = num2str(option);
75 error("zenity_list: unsupported option");
79 columns = sprintf('--column="%s" ', columns{:});
80 data = sprintf("%s ", data{:});
82 cmd = sprintf('zenity --list --title="%s" %s %s %s --print-column="%s" --separator=":" %s %s', ...
83 title, checklist, radiolist, editable, print_column, columns, data);
84 [status, output] = system(cmd);
86 if (length(output) > 0 && output(end) == "\n")
87 output = output(1:end-1);
89 idx = strfind(output, ":");
90 idx = [0, idx, length(output)+1];
97 s{i} = output((idx(i)+1):(idx(i+1)-1));
103 error("zenity_list: %s", output);