Guidance on Closing a "GUIDE" Gui

13 visualizaciones (últimos 30 días)
Douglas Anderson
Douglas Anderson el 13 de Oct. de 2015
Comentada: Douglas Anderson el 13 de Oct. de 2015
Hello!
I have been trying to cleanly exit a GUIDE gui, and am a bit confused as to the proper sequence. The OpeningFcn is straighforward, but I don't know about a couple of things:
  1. If you have to close the gui right away (like a security check put in the OpeningFcn isn't met), how do you exit? return()? or call the close function? The close has a modal dialog to see if you want to close, but we don't want to do that if security doesn't pass.
  2. What is the proper sequence to (a) close any open windows that have been created during the session and (b) if you have called uiwait, when do you do the delete(handles.figure1) and the uiresume(handles.figure1)? Or other proper close functions?
Thanks.
Doug

Respuesta aceptada

Adam
Adam el 13 de Oct. de 2015
I would recommend putting any checks in a function that itself opens the GUI then you simply don't even attempt to open the GUI if the checks fail. I have been caught out myself with bailing out on a GUI in the OpeningFcn and ending up with a ghost GUI that is in some hidden state.
closereq
should do the job though to close the window although not if you have put things in the CloseRequest function that you do not want to happen in this case.
As far as closing windows that have been opened during a session goes it is entirely down to your application really. As far as I know Matlab does not allow figures to be parented by other figures so I programmed a GUI Manager class that deals with launching GUIs and closes them all down automatically when the manager is deleted (which happens when the 'parent' window closes). Generally though you can just close them yourself in the DeleteFcn or CloseRequestFcn of your main window.
If you call uiwait with a figure handle you don't need an explicit uiresume so long as the figure is closed at some point as this will cause it to resume anyway. You can do a uiresume explicitly though to pair up with a uiwait that was not given a figure handle. Then you can delete the figure whenever you deem appropriate.
  3 comentarios
Adam
Adam el 13 de Oct. de 2015
I'm not aware of a video or help section on this aspect of GUIDE Guis. The help section does include some pages on e.g. 'Create a Simple UI Using GUIDE', but that is generally very basic aspects which you seem to be beyond anyway given what you are asking.
If your GUI is throwing that kind of message on closing then it must be coming from something triggered by the either the CloseRequestFcn or the DeleteFcn or your own callback if they are closing your GUI using a pushbutton of yours so that information would be useful to understand what you are doing.
Unfortunately error messages often point to that gui_mainfcn line which is not especially helpful. You need to follow logically through the chain of what happens and what functions will get called after the user's action - i.e. callbacks. These are the only ones that could be triggering an error message in general.
Douglas Anderson
Douglas Anderson el 13 de Oct. de 2015
OK, Thank you! I'll check out both of those. I think I'll make a note to MathWorks Support about the lack of simple understandable help on the basic functions for GUIDE guis.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by