Cancel Button of waitbar doesn't work
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Walter Roberson
le 12 Oct 2015
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 commentaires
Walter Roberson
le 12 Oct 2015
The above code works for me in R2014a exactly as-is.
I do not have R2015a to test with.
Plus de réponses (1)
Jan
le 12 Oct 2015
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 commentaires
Voir également
Catégories
En savoir plus sur Dialog Boxes dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!