How to change waitbar message during cancel button callback?

15 visualizzazioni (ultimi 30 giorni)
I have created a simple waitbar as a progress indicator and have added a cancel button to the waitbar. This is to be used in a much larger application, where I want quick user feedback but the code can't stop that quickly. I would like a positive indication to the user that their button press has been received. When the cancel button is pressed, I would like to have the waitbar cancel button disappear and the waitbar message changed. The waitbar cancel function also sets a flag, which the main application can check when it gets around to it.
Below is what I've tried. It seems to me calling the waitbar function from within the cancel button callback should do the trick, but I cannot figure out how to reference the waitbar object from within the waitbar cancel button callback. Am I on the right track? Or is there a better way to do this?
Thanks, Tobyn VanVeghten
Code:
% --- Executes on button press in test.
function test_Callback(hObject, eventdata, handles)
% hObject handle to test (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%added cancel button to progress bar. when pressed, it sets cancelling to
%1. need to periodically check this variable.
progress_bar = waitbar(0,'Analyzing data. Please wait...', ...
'CreateCancelBtn', @myfcn);
%make sure cancelling flag is cleared
setappdata(progress_bar,'cancelling',0);
for i = 1:120;
pause(0.5);
disp('Hello');
if getappdata(progress_bar, 'cancelling')
disp('bye');
close(progress_bar);
delete(progress_bar);
break;
end
end
function myfcn(hObject, eventdata, handles)
setappdata(gcbf,'cancelling',1);
waitbar(1, hObject, 'Cancelling. Please wait...');

Risposte (0)

Categorie

Scopri di più su App Building in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by