uiprogressdlg does not broadcast PostSet
5 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
回答 (1 件)
Adam Danz
2023 年 4 月 12 日
編集済み: Adam Danz
2023 年 4 月 12 日
> 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
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Interactive Control and Callbacks についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!