Addlistener in uiprogressDlg for CancelRequested
조회 수: 5 (최근 30일)
이전 댓글 표시
Hey,
I would like to add a listener to the Variable CancelRequested for uiprogressDlg. This shall be possible outside a loop without polling all the time by hand. Since only get.CancelRequested will be asked, which is not observable, I get no respond. I would appreciate your help, how to solve this.
classdef Untitled
properties
fig
dlg
end
methods
function obj = Untitled()
obj.fig = uifigure;
obj.dlg = uiprogressdlg(obj.fig,'Title','Wait',...
'Message','Starting','Cancelable','on','CancelText','Cancel','Indeterminate','on');
addlistener(obj.dlg,"CancelRequested",'PostSet',@obj.cancelMeasurement);
main(obj)
end
function main(obj)
counter = 50;
for ii = 1:counter %you can put all your other code here
%% outcommented is not a solution ;)
% if isempty(findobj(fig)) == 1
% obj.dlg.CancelRequested = 1;
% end
% if dlg.CancelRequested == 1
% disp('You Hit Cancel or Exited')
% delete(fig)
% return
% end
% obj.dlg.Value = ii/counter;
obj.dlg.Message = sprintf('%12.2f%% complete',ii/counter*100);
pause(0.1)
end
obj.dlg.CancelRequested
close(obj.dlg);
end
function cancelMeasurement(obj,~,~)
close(obj.dlg);
close(obj.fig);
errordlg('Measurement aborted by User','Information');
end
end
end
댓글 수: 0
답변 (1개)
Arthi Sathyamurthi
2021년 10월 25일
Hello Markus,
The code “obj.dlg.CancelRequested” only gets the state of CancelRequested and returns the value. Hence set the state of CancelRequested to a value as
obj.dlg.CancelRequested = 1;
댓글 수: 0
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!