Creating large gui, setting callbacks
9 views (last 30 days)
Show older comments
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
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 :)
Accepted Answer
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
More Answers (2)
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
Sean de Wolski
on 1 Jun 2011
3 Ideas
- 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.
- Spend the time and do it programatically, you'll have a better result.
- Redesign it so that you don't need 700 edit boxes. That's a ton of 'em.
2 Comments
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?
See Also
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!