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!