GUI: waiting for a checkbox to be checked to carry on in a callback function
조회 수: 1 (최근 30일)
이전 댓글 표시
I am trying to write a GUI in which I visualise some figures and I then have to make an action when and only when the user has made a choice. But my program doesn't seem to respect the order, that means it goes on and back to the beginning without waiting for the answer. Here is a simplified version of my function called in a gui:
function ExFctCallback(src,evt)
set([S.FigInt,S.ExFct],'Visible','Off');
% Get workspace variables
fig = get(S.FigInt,'Value');
I = S.imx;
imshow(I)
pause(2)
I = im2bw(I);
imshow(I)
pause(2)
% Call a function that gives kp as an output
if ~masde2
keeperIndexes = kp(1:2);
else
couleurs = ['r','g','c','m','y','b'];
lkp = length(kp);
couleurs = couleurs(1:lkp);
set([S.CircCh,S.ChooseCirc(1:lkp), S.ChosenCirc],'Visible','on');
if (get(S.ChosenCirc,'Value')==1)
valcol = get(S.ChooseCirc,'val'); % Keep chosen values in a cell
valcol = logical(cell2mat(valcol)); % Transform the cell 2 matrix of logical
if (sum(valcol) ~=2)
set(S.ChosenCirc,'Value',0);
else
keeperIndexes = kp(valcol);
end
end
end
% I just want to carry on when keeperIndexes has been initialised
if exist('keeperIndexes','var')
[estDist,S.dist] = fct2(...);
end
% At the end of the procedure, the execution buttons disappear and
% only the one to load a new fig stays visible.
set([S.CircCh,S.ChooseCirc, S.ChosenCirc],'Visible','Off');
end % ExFctCallback
Now the buttons of interest are the following ones:
% Choice of the colours of the circle
inleft = 150; sepleft = 25;
couleurs = {'red';'green';'cyan';'magenta';'yellow';'blue'};
Tipstr = 'Select the 2 colours corresponding to the correct diameter of the circles';
S.CircCh = uicontrol(S.f,'Style','text','Units','characters',...
'Position',[170 28 38 4],...
'String','Choose the 2 correct circles',...
'TooltipString',Tipstr,...
'Parent',S.botPanel,...
'Visible','Off',...
'FontSize',12);
for k = 1:length(couleurs)
S.ChooseCirc(k) = uicontrol(S.f,'Style','rad','Units','characters',...
'Position',[inleft+sepleft*(k-1) 27 18 2],...
'String',couleurs{k},...
'BackgroundColor',couleurs{k},...
'Parent',S.botPanel,...
'FontSize',12,...
'Visible','Off');
end
S.ChosenCirc = uicontrol(S.f,'Style','check','Units','characters',...
'Position',[190 24 8 4],...
'String','Done',...
'min',0,'max',1,...
'Parent',S.botPanel,...
'Value',0,...
'Visible','Off');
So what I want is first to visualise the original image, then the B&W one and then nothing happens until the user has selected exactly two colours (from the ChooseCirc radiobuttons) and confirmed it with the check button ChosenCirc. But what happens is while the user decides, the original and b&w pictures appear again and again without waiting for the procedure to carry on.
I know it is a bit messy but I have tried to explain it the best I could ;-) I can include some screenshots if it helps. Cheers.
댓글 수: 1
Adam
2014년 9월 26일
What is ExFctCallback responding to? Should it only execute once?
If the user is expected to confirm something and then trigger a calculation would you not be better with a pushbutton than a checkbox? What you report suggests that your ExFctCallback keeps triggering before it is ready which suggests it is reacting to the wrong trigger.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!