Mercurial > octave
comparison scripts/gui/inputdlg.m @ 21637:59ebef9680ef
More cleanup associated with removing Java dialog boxes (cset b5d9b95d1e1a).
* NEWS: List errordlg only once in list of Java functions removed.
* errordlg.m: Use a single sentence description of function for first
documentation paragraph. Correct misspelling of "occurred".
Match variable names in code to those in docstring.
* helpdlg.m, warndlg.m: Use a single sentence description of function for first
documentation paragraph. Match variable names in code to those in docstring.
* inputdlg.m: Match variable names in code to those in docstring. Use
function name as prefix to all error messages. Use spaces and line wrapping
to make %!demos more readable.
* listdlg.m: Re-order and rephrase some of docstring. Add more input
validation. Add new BIST tests for input validation.
* questdlg.m: Re-order some of docstring. Use function name as prefix to all
error messages. Eliminate unreachable otherwise statement in switch block.
Add new BIST tests for input validation.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 20 Apr 2016 15:54:37 -0700 |
parents | b5d9b95d1e1a |
children | 1c4cd12987f5 |
comparison
equal
deleted
inserted
replaced
21636:a3a412dee704 | 21637:59ebef9680ef |
---|---|
73 ## Silently extract only char elements | 73 ## Silently extract only char elements |
74 prompt = prompt(cellfun ("isclass", prompt, "char")); | 74 prompt = prompt(cellfun ("isclass", prompt, "char")); |
75 elseif (ischar (prompt)) | 75 elseif (ischar (prompt)) |
76 prompt = {prompt}; | 76 prompt = {prompt}; |
77 else | 77 else |
78 error ("PROMPT must be a character string or cellstr array"); | 78 error ("inputdlg: PROMPT must be a character string or cellstr array"); |
79 endif | 79 endif |
80 | 80 |
81 dlg_title = "Input Dialog"; | 81 title = "Input Dialog"; |
82 if (nargin > 1) | 82 if (nargin > 1) |
83 dlg_title = varargin{1}; | 83 if (! ischar (varargin{1})) |
84 if (! ischar (dlg_title)) | 84 error ("inputdlg: TITLE must be a character string"); |
85 error ("TITLE must be a character string"); | |
86 endif | 85 endif |
86 title = varargin{1}; | |
87 endif | 87 endif |
88 | 88 |
89 linespec = 1; | 89 linespec = 1; |
90 if (nargin > 2) | 90 if (nargin > 2) |
91 linespec = varargin{2}; | 91 linespec = varargin{2}; |
102 ## c1 c2 | 102 ## c1 c2 |
103 ## r1 1 10 first text field is 1x10 | 103 ## r1 1 10 first text field is 1x10 |
104 ## r2 2 20 second text field is 2x20 | 104 ## r2 2 20 second text field is 2x20 |
105 ## r3 3 30 third text field is 3x30 | 105 ## r3 3 30 third text field is 3x30 |
106 if (! isnumeric (linespec)) | 106 if (! isnumeric (linespec)) |
107 error ("ROWSCOLS must be numeric"); | 107 error ("inputdlg: ROWSCOLS must be numeric"); |
108 endif | 108 endif |
109 | 109 |
110 if (isscalar (linespec)) | 110 if (isscalar (linespec)) |
111 ## only scalar value in lineTo, copy from linespec and add defaults | 111 ## only scalar value in lineTo, copy from linespec and add defaults |
112 rowscols = zeros (numel (prompt), 2); | 112 rowscols = zeros (numel (prompt), 2); |
119 rowscols = zeros (numel (prompt), 2); | 119 rowscols = zeros (numel (prompt), 2); |
120 ## rows from colum vector linespec, columns are set to default | 120 ## rows from colum vector linespec, columns are set to default |
121 rowscols(:,2) = 25; | 121 rowscols(:,2) = 25; |
122 rowscols(:,1) = linespec(:); | 122 rowscols(:,1) = linespec(:); |
123 else | 123 else |
124 error ("ROWSCOLS vector does not match size of PROMPT"); | 124 error ("inputdlg: ROWSCOLS vector does not match size of PROMPT"); |
125 endif | 125 endif |
126 elseif (ismatrix (linespec)) | 126 elseif (ismatrix (linespec)) |
127 if (rows (linespec) == columns (prompt) && columns (linespec) == 2) | 127 if (rows (linespec) == columns (prompt) && columns (linespec) == 2) |
128 ## (rows x columns) match, copy array linespec | 128 ## (rows x columns) match, copy array linespec |
129 rowscols = linespec; | 129 rowscols = linespec; |
130 else | 130 else |
131 error ("ROWSCOLS matrix does not match size of PROMPT"); | 131 error ("inputdlg: ROWSCOLS matrix does not match size of PROMPT"); |
132 endif | 132 endif |
133 else | 133 else |
134 ## dunno | 134 ## dunno |
135 error ("unknown form of ROWSCOLS argument"); | 135 error ("inputdlg: unknown form of ROWSCOLS argument"); |
136 endif | 136 endif |
137 rowscols = ceil (rowscols); | 137 rowscols = ceil (rowscols); |
138 | 138 |
139 ## convert numeric values in defaults cell array to strings | 139 ## convert numeric values in defaults cell array to strings |
140 defs = cellfun (@num2str, defaults, "UniformOutput", false); | 140 defs = cellfun (@num2str, defaults, "UniformOutput", false); |
141 | 141 |
142 if (__octave_link_enabled__ ()) | 142 if (__octave_link_enabled__ ()) |
143 cstr = __octave_link_input_dialog__ (prompt, dlg_title, rowscols, defs); | 143 cstr = __octave_link_input_dialog__ (prompt, title, rowscols, defs); |
144 else | 144 else |
145 error ("inputdlg is not available in this version of Octave"); | 145 error ("inputdlg is not available in this version of Octave"); |
146 endif | 146 endif |
147 | 147 |
148 endfunction | 148 endfunction |
149 | 149 |
150 | 150 |
151 %!demo | 151 %!demo |
152 %! disp ('- test inputdlg with prompt and caption only.'); | 152 %! disp ('- test inputdlg with prompt and caption only.'); |
153 %! prompt = {'Width','Height','Depth'}; | 153 %! prompt = {'Width', 'Height', 'Depth'}; |
154 %! dims = inputdlg (prompt, 'Enter Box Dimensions'); | 154 %! dims = inputdlg (prompt, 'Enter Box Dimensions'); |
155 %! if (isempty (dims)) | 155 %! if (isempty (dims)) |
156 %! helpdlg ('Canceled by user', 'Information'); | 156 %! helpdlg ('Canceled by user', 'Information'); |
157 %! else | 157 %! else |
158 %! volume = str2num (dims{1}) * str2num (dims{2}) * str2num (dims{3}); | 158 %! volume = str2num (dims{1}) * str2num (dims{2}) * str2num (dims{3}); |
159 %! surface = 2 * (str2num (dims{1}) * str2num (dims{2}) + ... | 159 %! surface = 2 * (str2num (dims{1}) * str2num (dims{2}) + ... |
160 %! str2num (dims{2}) * str2num (dims{3}) + ... | 160 %! str2num (dims{2}) * str2num (dims{3}) + ... |
161 %! str2num (dims{1}) * str2num (dims{3})); | 161 %! str2num (dims{1}) * str2num (dims{3})); |
162 %! helpdlg (sprintf ('Results:\nVolume = %.3f\nSurface = %.3f', volume, surface), 'Box Dimensions'); | 162 %! helpdlg (sprintf ('Results:\nVolume = %.3f\nSurface = %.3f', ... |
163 %! volume, surface), 'Box Dimensions'); | |
163 %! end | 164 %! end |
164 | 165 |
165 %!demo | 166 %!demo |
166 %! disp ('- test inputdlg with prescribed scalar (2 lines per text field) and defaults.'); | 167 %! disp ('- test inputdlg with prescribed scalar (2 lines per text field) and defaults.'); |
167 %! prompt = {'Width','Height','Depth'}; | 168 %! prompt = {'Width', 'Height', 'Depth'}; |
168 %! default = {'1.1','2.2','3.3'}; | 169 %! default = {'1.1', '2.2', '3.3'}; |
169 %! rc = 2; | 170 %! rc = 2; |
170 %! dims = inputdlg (prompt, 'Enter Box Dimensions',rc,default); | 171 %! dims = inputdlg (prompt, 'Enter Box Dimensions', rc, default); |
171 %! if (isempty (dims)) | 172 %! if (isempty (dims)) |
172 %! helpdlg ('Canceled by user', 'Information'); | 173 %! helpdlg ('Canceled by user', 'Information'); |
173 %! else | 174 %! else |
174 %! volume = str2num (dims{1}) * str2num (dims{2}) * str2num (dims{3}); | 175 %! volume = str2num (dims{1}) * str2num (dims{2}) * str2num (dims{3}); |
175 %! surface = 2 * (str2num (dims{1}) * str2num (dims{2}) + ... | 176 %! surface = 2 * (str2num (dims{1}) * str2num (dims{2}) + ... |
176 %! str2num (dims{2}) * str2num (dims{3}) + ... | 177 %! str2num (dims{2}) * str2num (dims{3}) + ... |
177 %! str2num (dims{1}) * str2num (dims{3})); | 178 %! str2num (dims{1}) * str2num (dims{3})); |
178 %! helpdlg (sprintf ('Results:\nVolume = %.3f\nSurface = %.3f', volume, surface), 'Box Dimensions'); | 179 %! helpdlg (sprintf ('Results:\nVolume = %.3f\nSurface = %.3f', ... |
180 %! volume, surface), 'Box Dimensions'); | |
179 %! end | 181 %! end |
180 | 182 |
181 %!demo | 183 %!demo |
182 %! disp ('- test inputdlg with prescribed vector [1,2,3] for # of lines per text field and defaults.'); | 184 %! disp ('- test inputdlg with prescribed vector [1,2,3] for # of lines per text field and defaults.'); |
183 %! prompt = {'Width','Height','Depth'}; | 185 %! prompt = {'Width', 'Height', 'Depth'}; |
184 %! default = {'1.10', '2.10', '3.10'}; | 186 %! default = {'1.10', '2.10', '3.10'}; |
185 %! rc = [1,2,3]; % NOTE: must be an array | 187 %! rc = [1,2,3]; % NOTE: must be an array |
186 %! dims = inputdlg (prompt, 'Enter Box Dimensions',rc,default); | 188 %! dims = inputdlg (prompt, 'Enter Box Dimensions', rc, default); |
187 %! if (isempty (dims)) | 189 %! if (isempty (dims)) |
188 %! helpdlg ('Canceled by user', 'Information'); | 190 %! helpdlg ('Canceled by user', 'Information'); |
189 %! else | 191 %! else |
190 %! volume = str2num (dims{1}) * str2num (dims{2}) * str2num (dims{3}); | 192 %! volume = str2num (dims{1}) * str2num (dims{2}) * str2num (dims{3}); |
191 %! surface = 2 * (str2num (dims{1}) * str2num (dims{2}) + ... | 193 %! surface = 2 * (str2num (dims{1}) * str2num (dims{2}) + ... |
192 %! str2num (dims{2}) * str2num (dims{3}) + ... | 194 %! str2num (dims{2}) * str2num (dims{3}) + ... |
193 %! str2num (dims{1}) * str2num (dims{3})); | 195 %! str2num (dims{1}) * str2num (dims{3})); |
194 %! helpdlg (sprintf ('Results:\nVolume = %.3f\nSurface = %.3f', volume, surface), 'Box Dimensions'); | 196 %! helpdlg (sprintf ('Results:\nVolume = %.3f\nSurface = %.3f', ... |
197 %! volume, surface), 'Box Dimensions'); | |
195 %! end | 198 %! end |
196 | 199 |
197 %!demo | 200 %!demo |
198 %! disp ('- test inputdlg with prescribed row by column sizes and defaults.'); | 201 %! disp ('- test inputdlg with prescribed row by column sizes and defaults.'); |
199 %! prompt = {'Width','Height','Depth'}; | 202 %! prompt = {'Width', 'Height', 'Depth'}; |
200 %! default = {'1.10', '2.20', '3.30'}; | 203 %! default = {'1.10', '2.20', '3.30'}; |
201 %! rc = [1,10; 2,20; 3,30]; % NOTE: must be an array | 204 %! rc = [1,10; 2,20; 3,30]; % NOTE: must be an array |
202 %! dims = inputdlg (prompt, 'Enter Box Dimensions',rc,default); | 205 %! dims = inputdlg (prompt, 'Enter Box Dimensions', rc, default); |
203 %! if (isempty (dims)) | 206 %! if (isempty (dims)) |
204 %! helpdlg ('Canceled by user', 'Information'); | 207 %! helpdlg ('Canceled by user', 'Information'); |
205 %! else | 208 %! else |
206 %! volume = str2num (dims{1}) * str2num (dims{2}) * str2num (dims{3}); | 209 %! volume = str2num (dims{1}) * str2num (dims{2}) * str2num (dims{3}); |
207 %! surface = 2 * (str2num (dims{1}) * str2num (dims{2}) + ... | 210 %! surface = 2 * (str2num (dims{1}) * str2num (dims{2}) + ... |
208 %! str2num (dims{2}) * str2num (dims{3}) + ... | 211 %! str2num (dims{2}) * str2num (dims{3}) + ... |
209 %! str2num (dims{1}) * str2num (dims{3})); | 212 %! str2num (dims{1}) * str2num (dims{3})); |
210 %! helpdlg (sprintf ('Results:\nVolume = %.3f\nSurface = %.3f', volume, surface), 'Box Dimensions'); | 213 %! helpdlg (sprintf ('Results:\nVolume = %.3f\nSurface = %.3f', ... |
211 %! end | 214 %! volume, surface), 'Box Dimensions'); |
212 | 215 %! end |
213 %!error<narginchk> inputdlg (1, 2, 3, 4, 5) | 216 |
214 %!error<PROMPT must be a character string> inputdlg (1) | 217 %!error inputdlg (1, 2, 3, 4, 5) |
215 %!error<TITLE must be a character string> inputdlg ("msg", 1) | 218 %!error <PROMPT must be a character string> inputdlg (1) |
216 %!error<ROWSCOLS must be numeric> inputdlg ("msg", "title", "1") | 219 %!error <TITLE must be a character string> inputdlg ("msg", 1) |
217 %!error<ROWSCOLS vector does not match size> | 220 %!error <ROWSCOLS must be numeric> inputdlg ("msg", "title", "1") |
218 %! inputdlg ({"a1", "a2"}, "title", [1, 2, 3]) | 221 %!error <ROWSCOLS vector does not match size> |
222 %! inputdlg ({"a1", "a2"}, "title", [1, 2, 3]); | |
223 |