Addlistener in uiprogressDlg for CancelRequested

5 Ansichten (letzte 30 Tage)
Markus Weiser
Markus Weiser am 21 Okt. 2021
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

Antworten (1)

Arthi Sathyamurthi
Arthi Sathyamurthi am 25 Okt. 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;
in order to call the addlistener handle.

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by