Cancel Button of waitbar doesn't work
조회 수: 7 (최근 30일)
이전 댓글 표시
Hello.
After some researches on internet, and no solution found yet, I come here hoping you will be able to help me.
In my GUI, I have some calculations launched after the opening of a file. In order to see the progression, I created a waitbar in which I add a cancel button (to cancel the calculation if the operator want it). In this way, I created the waitbar like this:
barre = waitbar(0, 'Récupération des données', ...
'Name', 'Treatment', ...
'CreateCancelBtn', 'setappdata(gcbf, ''canceling'', 1)');
and when I want to see if the operator clicked on the cancel button, I do:
flag_cancel = getappdata(barre, 'canceling');
if flag_cancel
return
else
do some code
end
But, each time I tried to retrieve the canceling value, I have an empty value like this my click on the cancel button was never taken into account.
I tried several methods, as replace gcbf by the handle of a figure, but always not working. Besides, I tried to add a function to replace the setappdata:
barre = waitbar(0, 'Récupération des données', ...
'Name', 'Treatment', ...
'CreateCancelBtn', {@toto});
creating a function toto in another .m file
function toto(obj, event)
disp('hi!')
end
But here my program never go into this function when I click on the cancel button. The most surprising is that I never go into this toto function.
Any ideas?
I thank you in advance.
댓글 수: 0
채택된 답변
Walter Roberson
2015년 10월 12일
In my test in R2014a it calls the anonymous function I created.
barre = waitbar(0, 'Récupération des données', ...
'Name', 'Treatment', ...
'CreateCancelBtn', @(obj, event) disp('hi') );
댓글 수: 3
Walter Roberson
2015년 10월 12일
The above code works for me in R2014a exactly as-is.
I do not have R2015a to test with.
추가 답변 (1개)
Jan
2015년 10월 12일
Using strings as callbacks is kept for backward compatibility since Matlab R6.5. Better use the "modern" method of function handles in every case.
setappdata(gcbf, ''canceling'', 1)
This sets the ApplicationData of the waitbar's figure. What is the value of the variable barre? Is this the handle of the GUI or the waitbar?
It should work, if the cancel button changes the Applicationdata of the GUI, but givt the GUI a chance to update by adding a drawnow in the function, whose function handle is stored in the canceling function of the waitbar.
댓글 수: 2
참고 항목
카테고리
Help Center 및 File Exchange에서 Dialog Boxes에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!