I am trying to detect if a GUI created from AppDesigner is open
40 views (last 30 days)
Show older comments
I am trying to detect if a GUI created from AppDesigner is open. Does anyone know how to do this with AppDesigner GUI's?
I have tried and looked around a few posts such as these:
but i havnt had any luck it making it work.
Essentially I have an app which creates parameters for the rest of the script such as variables. I don't want the rest of the script to run till the mlapp GUI has a button pressed. My take was to set up a wait loop checking that the GUI is still open and when its closed the loop will continue. Is this a good way about it / how do i make this work?
0 Comments
Answers (1)
Benjamin Kraus
on 1 Apr 2022
You said: "My take was to set up a wait loop checking that the GUI is still open and when its closed the loop will continue. Is this a good way about it / how do i make this work?"
It sounds like you are looking for the waitfor command, which will block your code execution until the corresponding figure has closed. For example:
f = uifigure;
disp("Waiting")
waitfor(f)
disp("Figure Closed")
1 Comment
Benjamin Kraus
on 1 Apr 2022
There might be a second part to your question, which is "how do I get the handle to the figure".
- If you are using App Designer, the handle the figure is stored in a property on the App. By default that property is named "UIFigure". You can pass that value into waitfor.
- The preferred approach would be to use an existing figure handle (which is stored when the figure or uifigure command was called), but if you don't have that for some reason, you can use findall on groot to find all open figures, then check the Name to make sure you have the correct figure.
uifigure('Name','My App'); % Forgot to store the output handle.
uifigure(); % Another unrelated figure that happens to be open.
% Use findall to find the handle for the figure with the name "My App".
f = findall(groot,'Type','figure','Name','My App');
waitfor(f)
disp("Figure Closed")
See Also
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!