Addlistener in uiprogressDlg for CancelRequested
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Arthi Sathyamurthi
le 25 Oct 2021
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 commentaires
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!