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!