I am trying to detect if a GUI created from AppDesigner is open

44 visualizaciones (últimos 30 días)
Harry Spratt
Harry Spratt el 1 de Abr. de 2022
Comentada: Benjamin Kraus el 1 de Abr. de 2022
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?

Respuestas (1)

Benjamin Kraus
Benjamin Kraus el 1 de Abr. de 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 comentario
Benjamin Kraus
Benjamin Kraus el 1 de Abr. de 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")

Iniciar sesión para comentar.

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by