|
6 | 6 | % function must declare its arguments via arg_define. In addition, only a Subset of the function's |
7 | 7 | % specified arguments can be displayed. |
8 | 8 | % |
| 9 | +% If this function is called with no arguments from within a function that uses arg_define it brings |
| 10 | +% up a dialog for the function's defined arguments, with values assigned based on the function's |
| 11 | +% inputs (contents of in varargin) and returns an argument struct if the dialog was confirmed with a |
| 12 | +% click on OK, and an empty value otherwise. The calling function can exit on empty, or otherwise |
| 13 | +% resume with entered parameters. |
| 14 | +% |
9 | 15 | % In: |
10 | 16 | % Function : the function for which to display arguments |
11 | 17 | % |
|
22 | 28 | % |
23 | 29 | % 'Invoke' : whether to invoke the function directly; in this case, the output |
24 | 30 | % arguments are those of the function (default: true, unless called in |
25 | | -% the form g = arg_guidialog; e.g., from within some function) |
| 31 | +% the form g = arg_guidialog; from within some function) |
| 32 | +% |
| 33 | +% 'ShowGuru' : whether to show parameters marked as guru-level. (default: according |
| 34 | +% to env_startup setting) |
26 | 35 | % |
27 | 36 | % Out: |
28 | | -% Parameters : either a struct that is a valid input to the Function or the outputs of the function |
29 | | -% when Invoke is set to true (possibly multiple outputs) |
| 37 | +% Parameters : If Invoke was set to true, this is either the results of the function call or empty |
| 38 | +% (if the dialog was cancelled). If Invoke was set to false, this is either a struct |
| 39 | +% that is a valid input to the Function, or an empty value if cancel was clicked. |
30 | 40 | % |
31 | 41 | % Examples: |
32 | 42 | % % bring up a configuration dialog for the given function |
|
41 | 51 | % % bring up a dialog, and invoke the function with the selected settings after the user clicks OK |
42 | 52 | % settings = arg_guidialog(@myfunction,'Invoke',true) |
43 | 53 | % |
| 54 | +% % from within a function |
| 55 | +% args = arg_define(varargin, ...); |
| 56 | +% if nargin < 1 |
| 57 | +% % optionally allow the user to enter arguments via a GUI |
| 58 | +% args = arg_guidialog; |
| 59 | +% % user clicked cancel? |
| 60 | +% if isempty(args), return; end |
| 61 | +% end |
| 62 | +% |
44 | 63 | % See also: |
45 | 64 | % arg_guidialog_ex, arg_guipanel, arg_define |
46 | 65 | % |
|
61 | 80 | % write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
62 | 81 | % USA |
63 | 82 |
|
| 83 | +global tracking; |
| 84 | + |
64 | 85 | if ~exist('func','var') |
65 | | - % called with no arguments, from inside a function: open function dialog |
| 86 | + % called with no arguments, from inside a function: open function dialog |
66 | 87 | func = hlp_getcaller; |
67 | 88 | varargin = {'Parameters',evalin('caller','varargin'),'Invoke',nargout==0}; |
68 | 89 | end |
69 | 90 |
|
70 | 91 | % parse arguments... |
71 | | -hlp_varargin2struct(varargin,{'params','Parameters','parameters'},{}, {'subset','Subset'},{}, {'dialogtitle','title','Title'}, [char(func) '()'], {'buttons','Buttons'},[],{'invoke','Invoke'},true); |
| 92 | +hlp_varargin2struct(varargin, ... |
| 93 | + {'params','Parameters','parameters'},{}, ... |
| 94 | + {'subset','Subset'},{}, ... |
| 95 | + {'dialogtitle','title','Title'}, [char(func) '()'], ... |
| 96 | + {'buttons','Buttons'},[], ... |
| 97 | + {'invoke','Invoke'},true, ... |
| 98 | + {'show_guru','ShowGuru'},tracking.gui.show_guru); |
72 | 99 | oldparams = params; |
73 | 100 |
|
74 | 101 | % obtain the argument specification for the function |
|
83 | 110 | subset(1) = []; |
84 | 111 | subset = allnames(~ismember(allnames,[subset 'arg_direct'])); |
85 | 112 | end |
86 | | -[spec,subset] = obtain_items(rawspec,subset); |
| 113 | +[spec,subset] = obtain_items(rawspec,subset,'',show_guru); |
87 | 114 |
|
88 | 115 | % create an inputgui() dialog... |
89 | 116 | geometry = repmat({[0.6 0.35]},1,length(spec)+length(buttons)/2); |
|
95 | 122 | s = spec{k}; |
96 | 123 | if isempty(s) |
97 | 124 | uilist(end+1:end+2) = {{} {}}; |
98 | | - else |
| 125 | + else |
99 | 126 | if isempty(s.help) |
100 | 127 | error(['Cannot display the argument ' subset{k} ' because it contains no description.']); |
101 | 128 | else |
|
138 | 165 | end |
139 | 166 | end |
140 | 167 |
|
| 168 | + |
141 | 169 | % invoke the GUI, obtaining a list of output values... |
142 | 170 | helptopic = char(func); |
143 | 171 | try |
|
149 | 177 | catch |
150 | 178 | disp('Cannot deduce help topic.'); |
151 | 179 | end |
| 180 | + |
| 181 | +% % strip geometry for guru arguments |
| 182 | +% if ~show_guru |
| 183 | +% tmpspec = [spec{:}]; |
| 184 | +% geometry([tmpspec.guru]) = []; |
| 185 | +% geomvert([tmpspec.guru]) = []; |
| 186 | +% end |
| 187 | + |
152 | 188 | [outs,dummy,okpressed] = inputgui('geometry',geometry, 'uilist',uilist,'helpcom',['env_doc ' helptopic], 'title',dialogtitle,'geomvert',geomvert); %#ok<ASGLU> |
153 | 189 |
|
154 | 190 | if ~isempty(okpressed) |
|
204 | 240 | end |
205 | 241 |
|
206 | 242 | % obtain a cell array of spec entries by name from the given specification |
207 | | -function [items,ids] = obtain_items(rawspec,requested,prefix) |
| 243 | +function [items,ids] = obtain_items(rawspec,requested,prefix,show_guru) |
208 | 244 | if ~exist('prefix','var') |
209 | 245 | prefix = ''; end |
210 | 246 | items = {}; |
|
241 | 277 | % special case: switch arguments are not spliced, but instead the argument that defines the |
242 | 278 | % option popupmenu will be retained |
243 | 279 | if ~isempty(items{k}) && ~isempty(items{k}.children) && (~iscellstr(items{k}.range) || isempty(requested)) |
244 | | - [subitems, subids] = obtain_items(items{k}.children,{},[ids{k} '.']); |
| 280 | + [subitems, subids] = obtain_items(items{k}.children,{},[ids{k} '.'],show_guru); |
245 | 281 | if ~isempty(subitems) |
246 | 282 | % and introduce blank rows around them |
247 | 283 | items = [items(1:k-1) {{}} subitems {{}} items(k+1:end)]; |
|
251 | 287 | end |
252 | 288 |
|
253 | 289 | % remove items that cannot be displayed |
254 | | -retain = cellfun(@(x)isempty(x)||x.displayable,items); |
| 290 | +retain = cellfun(@(x)isempty(x)||x.displayable&&(show_guru||~x.guru),items); |
255 | 291 | items = items(retain); |
256 | 292 | ids = ids(retain); |
257 | 293 |
|
|
0 commit comments