4.66667

4.7 | 9 ratings Rate this file 78 Downloads (last 30 days) File Size: 33 KB File ID: #25862

inputsdlg: Enhanced Input Dialog Box (v2.0)

by Kesh Ikuma

 

16 Nov 2009 (Updated 18 Jul 2013)

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.1 (R2013a)
Other requirements Reported not compatible with MATLAB R14 and earlier
Tags for This File  
Everyone's Tags
dialog(4), gui, inputdlg(2), pick of the week, potw, predefined dialog box, uigetdir, uigetfile, uiputfile, utility
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (30)
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 Søren 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

Contact us