Code covered by the BSD License  

Highlights from
inputsdlg: Enhanced Input Dialog Box (v2.1)

4.72727

4.7 | 12 ratings Rate this file 127 Downloads (last 30 days) File Size: 33.9 KB File ID: #25862
image thumbnail

inputsdlg: Enhanced Input Dialog Box (v2.1)

by

 

16 Nov 2009 (Updated )

Predefined dialog box function to accept user inputs of several forms

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information
Description

This function is an enhanced version of the standard INPUTDLG function with many additional features:
- 8 control types: text, edit, check, list, range, color, table, button
(**color, table, and button were added in v2.0**)
- Text Type is a static text (e.g., to place an instruction)
- Check Type displays a checkbox with a label, returns one of two values
- Edit Type can be configured to accept:
  * plain text (single- or multi-line mode)
  * date (following date formats as defined in DATESTR)
  * numeric value (integer or float with range specification)
  * file or directory name (with UIGETFILE, UIPUTFILE, or UIGETDIR functions, supports UIGETFILE multi-sel
ect mode)
  * vector of floats (can specify the length of the vector)
- List Type returns index(es) of the selected item and can have 4 different appearances:
  * Popupmenu
  * Listbox (can be made to multi-select)
  * Radiobutton (button placements can be customized)
  * Togglebutton (button placements can be customized)
- INPUTSDLG can automatically size controls and dialog box for an optimal appearance, and control's size can be made to auto-adjust if dialog is made resizable.

- INPUTSDLG supports user callbacks to all UI controls as well as dialog's CreateFcn and DeleteFcn callbacks. The callback function takes additional input arguments to standard MATLAB callback arguments.

- INPUTSDLG returns the user entries in a cell or in a structure

- INPUTSDLG is backward compatible with INPUTDLG except for its returned values when canceled. With default answers given, INPUTDLG returns an empty cell while INPUTSDLG returns the default answers. INPUTSDLG returns the second parameter, CANCELED(a logical flag) to indicate how the dialog box is terminated.

ACKNOWLEDGMENT:
- Luke Reisner prepared v1.3 and kindly shared his modification/bug fixes.
- Florian Hatz initiated the development of v2.0 with his ideas of adding table, color, and tiling option

MATLAB release MATLAB 8.3 (R2014a)
Other requirements Reported not compatible with MATLAB R14 and earlier
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (46)
21 Feb 2014 David

Hello Kesh,
great tool...
something went wrong with my last submission...
I think there is an error with the tooltips on line 1070: changed Prompt(:,3) to Prompt(:,4)
I also added the following line (2293) to have tooltips for all elements:
% style-dependent configuration
set(hc,'TooltipString',TooltipStrings{m});

David

21 Feb 2014 David

Sorry
I added the following in line 2293:
% style-dependent configuration
set(hc,'TooltipString',TooltipStrings{m}); % added

David

02 Jan 2014 Jonathan Lister

Enables quick scripting of non standard dialogs. I used to have to do these by hand. Thanks for the tool.

02 Jan 2014 Dan

Cool, got it working now! Thanks for your help and for making a great program.
-Dan

01 Jan 2014 Kesh Ikuma

@Dan - Yeah, that error message is awfully cryptic and so ESL, isn't it? Sorry about that (it'll be improved in the next upload). It's telling you that the number of Formats elements do not match the number of Prompt rows. Here is how I modified your inputsdlg line to make it run:

[Answer,Cancelled] = inputsdlg(Prompt,Title,Formats(1:3),rmfield(DefAns,'DataFolder'),Options);

The dimensions of Prompt, Formats, and DefAns inputs are critical for this function to run. If you are creating a "dense" dialog (i.e., w/o any empty prompt cell), the number of rows of Prompt must match the number of elements of Formats, and DefAns' fields must exactly account for all the second column of Prompt array.

Good luck! -Kesh

01 Jan 2014 Dan

Dear Kesh,
This looks like an awesome tool. However, I can't seem to get it to work in my program. I am getting the following error message:

Error using inputsdlg (line 397)
Not enough FORMATS size for the display.

I don't understand what this error means and would be grateful for your advice. Here's my code (modeled on the demo file you provided):

%%%% Options Dialog Box using inputsdlg
Title = 'Program Options';
Options.Resize = 'on';
Options.Interpreter = 'tex';
Options.CancelButton = 'on';
Options.ApplyButton = 'on';
Options.ButtonNames = {'Continue','Cancel'}; %<- default names, included here just for illustration
Option.Dim = 1; % Horizontal dimension in fields
Prompt = {};
Formats = {};
DefAns = struct([]);

Prompt(1,:) = {'Choose program options',[]};
Formats(1).type = 'text';

Prompt(2,:) = {'Process traces with Chung-Kennedy filter prior to counting steps?','CKfilt'};
Formats(2).type = 'check';
DefAns(1).CKfilt = true;

Prompt(3,:) = {'Apply intensity filter to discard small steps?','IntFilt'};
Formats(3).type = 'check';
DefAns.IntFilt = true;

Prompts(4,:) = {'Select folder containig data to analyze','DataFolder'};
Formats(4).type = 'edit';
Formats(4).format = 'dir';
Formats(4).required = 'on';
DefAns.DataFolder = [];

[Answer,Cancelled] = inputsdlg(Prompt,Title,Formats,DefAns,Options);
%%%% End of dialog box

15 Aug 2013 Kesh Ikuma

@John - I'm glad it's working for you now. Now, re: enable/disable other control, here is how I would do it.

First, create an m-function:

function toggleEnable(hctl,htgt)

if get(hctl,'Value')
set(htgt,'Enable','on');
else
set(htgt,'Enable','off');
end

and set the callback of the controlling checkbox (located at (2,4)) as

Formats(2,4).callback = @(hobj,~,h,k)toggleEnable(hobj,h(k+1,1));

The above assumes that the checkbox controls the enable state of h(k+1,1) control, i.e., the control immediately after the checkbox. Note that one checkbox can en/disable multiple controls if you desire.

14 Aug 2013 John

Nvm, I was able to get a solution (it might not be the prettiest, but it works :-) ).

For other's future reference I will explain what I did. In Kesh's inputsdlg_demo.m file I added the following lines of code after prompt 5:

%---------

EnableCheck = {'on','off'};

x=1;

Formats(2,4).callback = @(~,~,h,k)set(h(k+1), 'enable', EnableCheck{EnableDisable(x)});

%---------

And I called I simple function that I wrote (titled EnableDisable). I have included that code below:

%---------
% enable/disable controls associated with (some) % checkboxes
function x = EnableDisable(x)

global x

a=1;
b=2;
x = (a+b)-x;

end

%---------

I know that this is probably not the best way to go about it, but it does work if anyone is interested.

14 Aug 2013 John

@Kesh, Thanks again for this awesome function! Your updates are working great!

I am actually interested in doing what I think your "Enable enhanced mode" checkbox is supposed to be doing. I am assuming that what you were thinking about doing here is creating a callback function that then Enables/Disables a different Prompt. However, it appears that you haven't included your callback function. So, right now it is just a checkbox.

I am currently working to add this callback to my current dialog box. But, I thought if you already had it completed then it could save me some work if you wouldn't mind sharing it. :-)

09 Aug 2013 Erasmo Morales

@Ikuma: Thank you sir, you are a good person. This new version works on Windows now. :) I will experiment with it this weekend. I will send you and email if I have more troubles.

Thanks again!

07 Aug 2013 Kesh Ikuma

@Erasmo - The reported compatibility bug for pre-R2013a has been fixed in v2.0.2, which I just uploaded.

07 Aug 2013 Kesh Ikuma

@Erasmo - Your issue has been confirmed on R2012b. I will look into it in a next couple days. Please keep your eyes for the next update.

Re: slider. Only way for you to customize the v1.3 slider behavior is to hack the code. The slider callback is set on Line 1245 to an anonymous function. You need to replace the function with a custom callback to modify the unit label. The handle of the unit label is given in handles struct, in the main inputsdlg scopes. Recommend using a nested function.

07 Aug 2013 Erasmo Morales

@Ikuma, thanks for replying. I am using Matlab on Windows. I've just tried v2.0.1 and it does the same.

About the slider:
For now, on a project I am using the older version of inputsdlg v1.3. Is what you suggested available in this version?

06 Aug 2013 Kesh Ikuma

@Erasmo - I will see if I can reproduce those errors that you reported. These demo scripts work fine on my system. Are you running Matlab on Mac or Linux?

As for showing the value of the slider, you can use the slider callback to modify either its TooltipString or the "unit" label. If you aren't sure how to do this, shoot me an email.

06 Aug 2013 Erasmo Morales

Hello, Mr. Ikuma. I am having similar troubles that John is having.

When running inputsdlg_demo.m I get:

Error using inputsdlg (line 394)
Default integer data must integer.

Error in inputsdlg_demo (line 187)
[Answer,Cancelled] = inputsdlg(Prompt,Title,Formats,DefAns,Options)

When running inputsdlg_demo_tile.m I get:

Error using inputsdlg (line 394)
Default dir must be a valid path.

Error in inputsdlg_demo_tile (line 57)
inputsdlg(Prompt,Title,Formats,DefAns,Options)

What do I have to change to get these to run? I am using Matlab 2012b.

Also, is there a way to display what value the slider has(for the range type)?

Ex:
0 100
|---[]------| (40)
^
I would like to display this value (40).

Thank you.
:)

05 Aug 2013 Kesh Ikuma

@John - Thanks for the bug report. I just uploaded the fixed version (v2.0.1) to (re)enable 'inputsdlg' style input arguments.

31 Jul 2013 John

This looks like a great tool!

However, I appear to be unable to run the demos or the examples shown in the "File Exchange Pick of the Week".
I am getting a variety of errors such as:

Error 1 (1st example in "File Exchange Pick of the Week"):

Error using struct
Field names must be strings.

Error in inputsdlg>checkformats (line 1086)
Formats = repmat(struct(fields{:}),NumQuest,1);

Error in inputsdlg (line 388)
[Formats,err] = checkformats(Formats,NumQuest,FormatDefaultFields);

Error 2 (2nd example in "File Exchange Pick of the Week"):

Error using inputsdlg (line 394)
Default text data format must be char.

Error 3 (attempt to run inputsdlg_demo_tile.m)

Error using inputsdlg (line 394)
Default dir must be a valid path.

Error in inputsdlg_demo_tile (line 57)
inputsdlg(Prompt,Title,Formats,DefAns,Options)

Error 4 (attempt to run inputsdlg_demo.m):

Error using inputsdlg (line 394)
Default integer data must integer.

Error in inputsdlg_demo (line 187)
[Answer,Cancelled] = inputsdlg(Prompt,Title,Formats,DefAns,Options)

However, the inputsdlg_demo_contactinfo.m works great! I know that I have included a lot of info here, but I thought that you might be able to investigate this better with more information.

09 Jul 2013 Kesh Ikuma

@Charles - Great idea! I'm working on a new version as of now. I will incorporate your suggestion in the upcoming release.

04 Jul 2013 Charles Collin

This looks like a very useful tool. However, I noted that it has the same issue regarding font size as does inputdlg. That is, it only takes the factory default, making it impossible to change the size of the font using (e.g.) set(0, 'DefaultTextFontSize', 14), as is possible for most of the other "dlg" commands. I modified the script at line 940 to read:
'FontSize' get(0,'DefaultTextFontSize');
This makes it accept the user-definable default, but the size of the text boxes don't scale accordingly. It would be great if an updated version of the function could do this. Thanks for your attention.

27 Jun 2013 Florian

Perfect tool, I like it a lot

08 May 2013 Soren Preus

Invaluable when making large GUI-based applications!

05 Jul 2012 Kesh Ikuma

@kirka - oops, I wrote you a reply before to Troy, but FEX comment section acted up and overwrote my reply to you.

That being said, the only way for this function to return the answers before closing the dialog is for you to modify the code yourself. I modeled this function after the built-in inputdlg function, which is uses a modal window.

05 Jul 2012 kirka

I'm not used to read other ones code so I don't know how to change callbacks in a way that I'm looking for. Like I earlier wrote I want to make apply button to set my answers without closing the dialog (like pressing ok but dialog stays open).

Hopefully someone understood my problem so I can get even some sort of an answer.

04 Jul 2012 Kesh Ikuma

@Troy - I think the answer to your question is 'yes'. The number of field is determined by the size of PROMPT (cell array) argument (and others) so you can programatically modify PROMPT array size during run time. Hope this helps.

03 Jul 2012 Troy Rockwood

This is a lifesaver! Is there a good way to have the number of fields be determined at run-time rather than before? I would like to have fields for n filenames where the user defines n. Thanks.

27 Jun 2012 kirka

Hi

How I can get answers out from inputsdlg without closing the dialog window. I need it to work that way when I want to check things fast.

Is it possible to make apply button work like ok button without closing dialog window by changing callback, for example. Or any other way.

17 Oct 2010 Felix Goldberg

Hi!

This looks like a great tool and I'm sure i'll use it.

For now, though, I need just a simple thing which appears to be unaddressed: I want to create a dialog box - just like inputdlg - with an arbitrary number of buttons.

Do you know how one does that?

Thanks!

14 Aug 2010 Kesh Ikuma

@Terry - Thanks for reporting the bug. I've confirmed it. Since I'm in a process of making a major update, this bug won't be fixed until v2.0 (there is v1.3 just submitted & pending for MathWorks approval) but here's how to fix it.

Replace the two if-else-end clauses that you posted above with the following:

if isempty(UserOptions) % no option specified, use default
err = {};
return;
elseif ischar(UserOptions) && any(strcmpi(UserOptions,{'on','off'}))
% check if User Resize Option is given as on/off string
UserOptions.Resize = UserOptions;
elseif ~isstruct(UserOptions) && numel(UserOptions)~=1
err{2} = 'Options must be ''on'', ''off'', or a scalar struct.';
return;
end

Let me know if you encounter any other bugs!

14 Aug 2010 Terrance Nearey

Very nice. And thanks for revising.
I'm trying to write some preprocessors for inputsdlg and have been exercises many of its possibilities in testing the front end code.
I think I've come across a bug. in the call to checkcptions() following line 1535:

The first if-then-else group will fail if Options on input is 'on',
so second one will not be reached.
--------
if isempty(UserOptions) % no option specified, use default
err = {};
return;
elseif numel(UserOptions)~=1
err{2} = 'Options struct must be a scalar.';
if errdbg, disp('errdbg: Keyboarding'),sysbeep(2),dbstack, keyboard; end; return;
end

% check if User Resize Option is given as on/off string
if ischar(UserOptions) && strcmpi(UserOptions,{'on','off'})
UserOptions.Resize = UserOptions;
elseif ~isstruct(UserOptions)
err{2} = 'Options must be ''on'', ''off'', or a struct.';
if errdbg, disp('errdbg: Keyboarding'),sysbeep(2),dbstack, keyboard; end; return;
end
---------
If your interested, I'll send you the front-ends when I've finished them
Thanks again,
Terry Nearey

15 Jul 2010 Kesh Ikuma

Jason,

I agree with your take on checkoptions(). I've scrapped the function and rewritten it in more-or-so of what you suggested. Also, this change made the user option field names to be case insensitive.

Hopefully, v1.2.2 just upped would fix all checkoptions() related bugs.

14 Jul 2010 Jason Kaeding

Hi Kesh,

New bug for you. This is related to the last one I posted on 11 Jun. Because you modified the Fields to handle the cellstr correctly, the problem migrated to line 1653. I think this line should be changed to

Options.ButtonNames = Fields{2,6}{1};

Personally, I think that the way that this checkoptions function is coded is a little bit strange. If the user specifies a struct as the input, then the struct is not built until later. I think that the struct should be built at the top regardless (using an else), then only add the fields if the user specifies them. This would reduce the problems that you are having now because you are creating fields if they don't exist, but you already specified all of the default values anyway.

Regards,
Jason

11 Jun 2010 Kesh Ikuma

Jason,

Thanks for the bug report. The fixed version has been uploaded (v.1.2.1).

As for the calender support, I'd like to keep this function completely standalone. So, unless there is a built-in function (either MATLAB or JAVA) for the calender dialog, I'll leave it as the text field. I have an idea to let you interface inputsdlg with external functions, but I'm a little too busy at this time to work on that.

11 Jun 2010 Jason Kaeding

Hi Kesh,

I think there's a bug in v1.2. It seems you modified checkoptions a lot, but if I do not specify an option as input (nargin < 5), then I get the error "Options must be scalar."

This stems from when you call Options = struct(Fields{:}). Because the ButtonNames field is a cell, it deals these to a 1x3 struct. What you need to do is declare ButtonNames as a "double cell": {{'OK','Cancel','Apply'}}. This will put the inner cell into a signle struct element.

09 Jun 2010 Jason Kaeding

Kesh, see UIGETDATE or UICALsubmissions as examples (or even use them directly).

19 May 2010 Kesh Ikuma

@Nick, "active" control is an interesting one, and I think I can incorporate that fairly easily. I'll try to include it in the next version.

@Jason, Thanks for the bug report. I'll fix it in the next version. Also, 'date' format is a good one. ActiveX... not so sure as I've never used it myself. May be one of these days I'll learn.

12 Mar 2010 Jason Kaeding

Hi Kesh,

I found a bug in line 295. You reference handles.Figure, but it appears handles.fig is the correct fieldname.

Regards

07 Mar 2010 Jason Kaeding

Hi Kesh,

First, I wanted to say that this is a great submission. One suggestion: a 'date' format would be nice. Could even use the ActiveX calendar control, but at least a normal date validation option would be enough.

Thanks.

05 Mar 2010 Nick

Awesome, just what I've needed for years. Just one suggestion: would it be possible to include another input argument (perhaps a logical array) that indicates whether each control is active or not. This way some controls could be "greyed out" or turned off on a particular dialog layout rather than having to create a new dialog layout whithout including those controls.

02 Feb 2010 Brett Shoelson

Excellent work!

20 Jan 2010 Aalya

Good work! Could you suggest me some applications of this dialog box. I am new to Matlab and still learning many suffs.

Reards.

06 Jan 2010 Kesh Ikuma

Leon,

The function was developed in r2008a; so, I am not surprised if it is not compatible with r14.

Since I do not have r14, there is no way for me to make inputsdlg compatible with r14 on my own. If you email me the errors that you are encountering, I can help you modifying the code.

06 Jan 2010 Leon

Hello

I am having some troubles to run the package, may it be that I do not have the latest matlab release, I am running r14.

Thanks

23 Nov 2009 Andreas Greuer

This inputsdlg should be standard in matlab like the inputdlg. We will use it. Good job.

22 Nov 2009 Mohammed El-Said

Great work,
it is really useful,
Thanks....

19 Nov 2009 Kesh Ikuma

Andreas,

Thanks for the bug report (and I'm a little embarrassed by such blatant bugs in my very demo...).

I fixed the bugs, added a couple more features, and uploaded the updated files.

19 Nov 2009 Andreas Greuer

The concept looks nice and quiet flexible.

But there are still some bugs in.
The Cancel is not indicated and gives just the default values back.
For an edit field comes not the text entered in the field, but a crazy structure (in the example the field "Name")
The answer gives back default instead of the new changed values. (in the example the field "SSN")

Updates
19 Nov 2009

v1.1 (Nov. 19, 2009)
* Several bug fixes (thanks Andreas!)
* Apply button feature added
* Unit label (to the right of control) feature added

20 Nov 2009

v1.11
More bug fixes (again thanks Andreas!)

20 Nov 2009

(v.1.12) More bug fixes

20 May 2010

* Fixed a couple bugs
* Added edit::date format
* Added formats.enable support
* Added options.CancelButton support
* Added options.ButtonNames support

11 Jun 2010

Bug Fix: Default Options bug reported by Jason

15 Jul 2010

v.1.2.2 (July 15, 2010)
* Rewritten checkoptions() (to correct issues reported by Jason)
* Bug Fix: file & dir control enable config were interpreted backwards

19 Jul 2010

v1.2.3
* Yet another checkoptions() bug fixes...

13 Aug 2010

v1.3 (by Luke Reisner)
* Several bug fixes
* Improved dialog UI layout
* Other small modifications

18 Jul 2013

v.2.0 (T. Ikuma & F. Hatz)
* Major update with majority of innards rewritten. See version history in the m-file
* Supports 3 additional types: color, table, and button
* Supports custom callbacks

06 Aug 2013

Bug fix release

09 Aug 2013

Made compatible with pre-R2013a releases

09 Sep 2013

v2.0.3: bug fix release

25 Nov 2013

Bug fix: parsing empty callback format field (Thanks David!)

28 Mar 2014

* Improved error message on FORMATS-PROMPT size mismatch.
* Fixed several bugs relating to neglected ToolTipString support (thanks David v.B!)
* FORMATS.items for Slider style now sets uicontrol's SliderStep property

28 Mar 2014

updated title

01 Jul 2014

v2.0.6 - bug fixes
* default type
* text control positioning

03 Jul 2014

v.2.1.0 (Jul 03, 2014)
* Added support for 'none' Format type as a placeholder for an empty row or column.
* Removed restriction on Cancel & Apply buttons.
* Bug fixes

03 Jul 2014

v2.1a (same day bug fixes)

03 Jul 2014

v2.1b - same day bug fixes #2

Contact us