Creating large gui, setting callbacks

9 views (last 30 days)
Hi all,
I have just used guide to create a GUI with about 700 input text boxes. In hindsight I should have probably done this programatically.
I have the boxes separated into 5 groups and don't need a separate callback for each box, I just need one for each group. Because there are so many boxes I decided to set the callback names using the set command and for loops which works quite well. The only issue I have is that whenever I launch the gui I get a bunch of error due to the default callbacks not existing in the .m file anymore.
Is there a place I can set the callback values before the errors can get generated?
Thanks
  1 Comment
Gary
Gary on 2 Jun 2011
"I have just used guide to create a GUI with about 700 input text boxes. In hindsight I should have probably done this programatically.".
I admire your patience :)

Sign in to comment.

Accepted Answer

Jan
Jan on 1 Jun 2011
Not a direct answer, but "In hindsight I should have probably done this programatically" reminds me to these tools: FEX: Convert Fig to M or FEX: GuideGetter
  3 Comments
Matt Fig
Matt Fig on 1 Jun 2011
Which is faster, matt2fig or fig2matt?
Jess britt
Jess britt on 2 Jun 2011
The fig2m function actually might be a quick fix to my problem right now. After a few tweaks due to it throwing errors I was able to get it to generate the m file without the callbacks. For some reason the text size is different than the text size in the .fig file even though their fontsize property is set to the same.
Thanks

Sign in to comment.

More Answers (2)

Matt Fig
Matt Fig on 1 Jun 2011
I would probably use a muli-line editbox instead of having many editboexes.
For example:
U = uicontrol('style','edit',...
'min',1,'max',10,...
'pos',[10 10 100 200],...
'horiz','left',...
'tooltips','Enter 10 numbers, one per line.');
% Enter several numbers, one on each line...
S = get(U,'string');
for ii = 1:size(S,1)
V(ii) = str2double(S(ii,:));
end
EDIT Just for fun, another idea....
  • The user can either hit return after typing a number or push the pushbutton to enter it into its proper place...
  • Clicking on an item in the listbox brings it to the currently enterable value...
function [] = gui_multiple_inputs()
% Author: Matt Fig
% Date: 6/1/2011
S.fh = figure('units','pixels',...
'position',[500 500 250 300],...
'menubar','none',...
'name','GUI_multiple',...
'numbertitle','off',...
'resize','off');
C = {'water: ';'wine: ';'vinegar: ';'oil: ';'soy sauce: ';'yogurt: ';'dishsoap: '};
S.ls = uicontrol('style','list',...
'unit','pix',...
'position',[10 110 230 180],...
'fontsize',12,...
'string',C,...
'call',@ls_call);
S.tx = uicontrol('style','text',...
'units','pix',...
'pos',[10 60 100 30],...
'string',C{1},...
'fontsize',14,...
'horizontalal','left');
S.ed = uicontrol('style','edit',...
'unit','pix',...
'position',[120 60 120 30],...
'fontsize',14,...
'call',@ed_call,...
'horiz','left');
S.pb = uicontrol('style','push',...
'units','pix',...
'position',[10 10 230 40],...
'fontsize',14,...
'string','Enter Ingredient',...
'callback',@pb_call);
S.CUR = 1;
% This next field holds the values for use in calculations
% once the user has filled them all.
S.VAL = zeros(size(C));
function [] = ed_call(varargin)
% Callback for editbox, adds new string from edit box.
oldstr = get(S.ls,'string'); % The string as it is now.
str = get(S.ed,'string');
str = regexp(str,'\d*(\.){0,1}\d*','match');
if isempty(str) || strcmp(str,'.')
return
end
oldstr{S.CUR} = [C{S.CUR} str{1}];
set(S.ls,'string',oldstr)
S.VAL(S.CUR) = str2double(str{1});
if S.CUR~=size(C,1)
S.CUR = S.CUR + 1;
set(S.tx,'string',C{S.CUR});
set(S.ed,'string','')
set(S.ls,'value',S.CUR)
end
end
function [] = pb_call(varargin)
% Callback for pushbutton, adds new string from edit box.
ed_call(varargin)
end
function [] = ls_call(varargin)
% Callback for listbox, adds new string from edit box.
V = get(S.ls,'value');
S.CUR = V;
set(S.tx,'string',C{V});
set(S.ed,'string',num2str(S.VAL(S.CUR)))
uicontrol(S.ed)
end
end
  6 Comments
Jess britt
Jess britt on 1 Jun 2011
I would have 5 of these boxes with multiple lines, side by side. I'd just have to link them so that the lines of each box line up properly. I'm guessing this could be done using the properties and set / get commands.
thanks for the help
Jess britt
Jess britt on 2 Jun 2011
I really like the look of this, I may look into doing this.
Thanks!

Sign in to comment.


Sean de Wolski
Sean de Wolski on 1 Jun 2011
3 Ideas
  1. In the guide editor, go into each edit box that doesn't have a call back and delete the call back function in the inspector window that shows up after double clicking on it.
  2. Spend the time and do it programatically, you'll have a better result.
  3. Redesign it so that you don't need 700 edit boxes. That's a ton of 'em.
  2 Comments
Jess britt
Jess britt on 1 Jun 2011
I feel like number 2 is the right way to go, but I was just wondering if there was a way I could somehow work around GUIDE. I think it would be quicker to do it programtically than to actually delete the callbacks in GUIDE.
As for #3, I think it may be hard because this panel is being used to configure a significant amount of hardware channels and safety limits.
Thanks for the ideas.
Sean de Wolski
Sean de Wolski on 1 Jun 2011
Perhaps you could open new subGUIs for all of the limits on a specific channel and other similar stuff. Then access it from a push button or a listbox?

Sign in to comment.

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!