Disable app while calculating

50 ビュー (過去 30 日間)
Alejandro Fernández
Alejandro Fernández 2020 年 9 月 24 日
コメント済み: Adam Danz 2020 年 9 月 28 日
Hi, I would like to know if there is an option to disable all buttons in the app while is calculating something made with a changed callback, I mean, what I would like is that if I make a change in some numeric box for example, until all the associated code has been executed, do not let me do anything without disabling all the buttons individually.

回答 (2 件)

Adam Danz
Adam Danz 2020 年 9 月 24 日
編集済み: Adam Danz 2020 年 9 月 25 日
How to disable app components while app is busy
  1. List all components you'd like to disable/enable in a vector of handles. Importantly, each component must have an "Enable" properrty. If there are sections with many components that you'd like to control, place them in a uipanel. Enabling and disabling uipanels controls everything within the panel.
  2. Create a function within the app that contains a logical input which will disable all components when the input is False and enable them when it's tTrue.
  3. In callback functions that are expected to consume significant time, set the Enable propery of all selected components to Off at the top of the callback function and then set them to On at the end, or wherever you'd like the changes to occur.
The full demo app is attached but here are the two critical functions.
% Example of step 1 & 2
function toggleComponents(app, enableFlag)
% enableFlag is either true (Enable=on) or false (enable=off).
components = [app.Button, app.Button2, app.ButtonGroup, app.Panel];
if enableFlag
flag = 'On';
else
flag = 'Off';
end
set(components, 'Enable', flag)
end
% Example of step 3
function ButtonPushed(app, event)
toggleComponents(app, false)
pause(3) % <-- do something interesting
toggleComponents(app, true)
end

Mario Malic
Mario Malic 2020 年 9 月 25 日
uiprogressdlg is also a good option, as it "overlays" an uifigure and makes anything behind it unable to be pressed (I did not personally test it, but it should work)
  1 件のコメント
Adam Danz
Adam Danz 2020 年 9 月 28 日
Yes, this is a good approach to disabling the entire app during a process.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by