uiprogressdlg does not broadcast PostSet

4 vues (au cours des 30 derniers jours)
Jack Ambler
Jack Ambler le 12 Avr 2023
Modifié(e) : Adam Danz le 12 Avr 2023
Hello,
I'm new to object oriented programming in MATLAB so please excuse my wonky terminology.
I have a uiprogressdlg called wb and I want to check it's CancelRequested property after every iteration of a for loop to know whether the for loop should continue or stop.
For the sake of efficiency I don't want to actually check the property myself with wb.CancelRequested. Instead I would rather use events and listeners.
Before my for loop I add a listener for setting the property with the following
addlistener(wb,"CancelRequested","PostSet",@(src,event) wbCancel);
However my callback never triggers when the cancel button is pressed. Updating the property manually with wb.CancelRequested = true; however does trigger the callback.
My workaround has been to copy DialogHelper, ProgressDialog, ProgressDialogController and uiprogressdlg to my own path so that I can sandwich this code at line 54 in ProgressDialogController:
if model.CancelRequested
model.CancelRequested = model.CancelRequested;
end
Now the callback does execute roughly when the cancel button is pressed (actually when any other property happens to get updated).
Of course this is not exactly an ideal fix.
Is this a bug or did I just do something wrong?
Thanks,
Jack.

Réponses (1)

Adam Danz
Adam Danz le 12 Avr 2023
Modifié(e) : Adam Danz le 12 Avr 2023
> Is this a bug or did I just do something wrong?
You aren't doing anything wrong. There's a difference in how the CancelRequested property is set when the button sets it and when it is set manually.
> For the sake of efficiency I don't want to actually check the property myself
Assuming your progress dialog is running in a loop, I would argue that it's more efficient to check it yourself than creating a listener. Progress dialogs are usually used when loops are already slow enough to justify using the dialog. Checking the condition below is nearly instantaneous. On my machine, it took 0.1 seconds to check the condition 100,000 times.
if wb.CancelRequested
wbCancel
end

Catégories

En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by