How to change waitbar message during cancel button callback?

조회 수: 15 (최근 30일)
Tobyn VanVeghten
Tobyn VanVeghten 2013년 6월 25일
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...');

답변 (0개)

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by