Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Aborting GUIDE guis

Subject: Aborting GUIDE guis

From: Matt J

Date: 25 Jun, 2011 12:00:20

Message: 1 of 9

I'm starting to get my feet wet with gui design via GUIDE. A difficulty that I'm having is that there are conditions -- determined during the initialization of the gui in the OpeningFcn (see code segment below) -- where I may want execution of the gui to abort completely, without ever even displaying its figure window.

The problem seems to be, though, that while I can abort from the OpeningFcn via RETURN, control will then return to the GUImain function which then automatically (via gui_mainfcn?) makes the figure window visible (and also the OutputFcn is executed). There doesn't seem to be an obvious mechanism to trigger an abort of the entire GUI.

Any recommendations?



function varargout = GUImain(varargin)

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
                   'gui_Singleton', gui_Singleton, ...
                   'gui_OpeningFcn', @GUImain_OpeningFcn, ...
                   'gui_OutputFcn', @GUImain_OutputFcn, ...
                   'gui_LayoutFcn', [], ...
                   'gui_Callback', []);
if nargin && ischar(varargin{1})
   gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before GUI is made visible.
function GUI_OpeningFcn(hObject, eventdata, handles, varargin)

 ....

 if abortCondition
    return
 end

 .....

Subject: Aborting GUIDE guis

From: vedenev

Date: 25 Jun, 2011 13:55:23

Message: 2 of 9

In OpeningFcn it draw the window. You have controls. Say you have
pushbatton "start calculation". In callback of this button you make
the calulations and make be animation update in axes in GUI for
example, say you have also stop button, in loop you need to check if
stop button was pushed. It is need to make global variable
istop=false. In call back of stop function you make istop=true; in
callback of start button there is a stop loop condition:
if istop
break;
end


-----------------------------------------
Maxim Vedenev, MATLAB Custom Programming
vedenev@ngs.ru
http://simulations.narod.ru/

Subject: Aborting GUIDE guis

From: Matt J

Date: 25 Jun, 2011 15:27:02

Message: 3 of 9

vedenev <vedenev.maxim@gmail.com> wrote in message <bf83df01-398b-4a3f-8fe2-12e104e3d48e@m18g2000vbl.googlegroups.com>...
> In OpeningFcn it draw the window. You have controls. Say you have
> pushbatton "start calculation". In callback of this button you make
> the calulations and make be animation update in axes in GUI for
> example, say you have also stop button, in loop you need to check if
> stop button was pushed. It is need to make global variable
> istop=false. In call back of stop function you make istop=true; in
> callback of start button there is a stop loop condition:
> if istop
> break;
> end
====================

Sorry, vedenev, I don't see the relevance of that to my question.

In case I wasn't clear, the abort condition occurs the very first time the OpeningFcn is called, during GUI initialization. When it occurs, I want the gui mfile to quit completely without ever drawing the window.

Subject: Aborting GUIDE guis

From: matt dash

Date: 26 Jun, 2011 03:21:04

Message: 4 of 9

"Matt J" wrote in message <iu4ikk$n6f$1@newscl01ah.mathworks.com>...
> I'm starting to get my feet wet with gui design via GUIDE. A difficulty that I'm having is that there are conditions -- determined during the initialization of the gui in the OpeningFcn (see code segment below) -- where I may want execution of the gui to abort completely, without ever even displaying its figure window.
>
> The problem seems to be, though, that while I can abort from the OpeningFcn via RETURN, control will then return to the GUImain function which then automatically (via gui_mainfcn?) makes the figure window visible (and also the OutputFcn is executed). There doesn't seem to be an obvious mechanism to trigger an abort of the entire GUI.
>
> Any recommendations?
>
>
>
> function varargout = GUImain(varargin)
>
> % Begin initialization code - DO NOT EDIT
> gui_Singleton = 1;
> gui_State = struct('gui_Name', mfilename, ...
> 'gui_Singleton', gui_Singleton, ...
> 'gui_OpeningFcn', @GUImain_OpeningFcn, ...
> 'gui_OutputFcn', @GUImain_OutputFcn, ...
> 'gui_LayoutFcn', [], ...
> 'gui_Callback', []);
> if nargin && ischar(varargin{1})
> gui_State.gui_Callback = str2func(varargin{1});
> end
>
> if nargout
> [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
> else
> gui_mainfcn(gui_State, varargin{:});
> end
> % End initialization code - DO NOT EDIT
>
>
> % --- Executes just before GUI is made visible.
> function GUI_OpeningFcn(hObject, eventdata, handles, varargin)
>
> ....
>
> if abortCondition
> return
> end
>
> .....


This seems like the wrong way to accomplish what you want... the opening function is meant to run code related to opening the gui.... if you dont want it to open, that should be taken care of in a higher level function, the one that is calling the gui.

It's possible that what you're describing can't be done. GUIDE is kind of clumsy and if you need that kind of control you might need to make the gui without using guide (which I would highly recommend anyway, especially if you're trying to learn how these things work). But you might be able to accomplish it by adding a gui_layout_fcn, which as you can see in your code above is empty by default, but you can add one using the same format as the opening_fcn. Making your own layout function should override any of GUIDE's figure handling, so your function will have to either display the gui (using openfig) or not display it (return)

Subject: Aborting GUIDE guis

From: Matt J

Date: 26 Jun, 2011 05:20:20

Message: 5 of 9

"matt dash" wrote in message <iu68j0$19s$1@newscl01ah.mathworks.com>...
>
>
> This seems like the wrong way to accomplish what you want... the opening function is meant to run code related to opening the gui.... if you dont want it to open, that should be taken care of in a higher level function, the one that is calling the gui.
==============

Thanks, that is what I ended up doing. I'm still kind of curious about what the layout_fcn let you do, but can't find any documentation on it in the GUIDE manual. It should be in Ch 8 "Programming a GUIDE GUI", but I can't see anything about it there.

Subject: Aborting GUIDE guis

From: matt dash

Date: 26 Jun, 2011 16:39:02

Message: 6 of 9

"Matt J" wrote in message <iu6fik$h6s$1@newscl01ah.mathworks.com>...
> "matt dash" wrote in message <iu68j0$19s$1@newscl01ah.mathworks.com>...
> >
> >
> > This seems like the wrong way to accomplish what you want... the opening function is meant to run code related to opening the gui.... if you dont want it to open, that should be taken care of in a higher level function, the one that is calling the gui.
> ==============
>
> Thanks, that is what I ended up doing. I'm still kind of curious about what the layout_fcn let you do, but can't find any documentation on it in the GUIDE manual. It should be in Ch 8 "Programming a GUIDE GUI", but I can't see anything about it there.

Yeah I dont think it's documented anywhere. You have to view the code for gui_mainfcn and try to figure it out from there. I think it runs the layout function before the opening function, and then it checks if there was a layout function, and if not it turns the figure visibility on, which will override whatever you do in the opening function.

Subject: Aborting GUIDE guis

From: vedenev

Date: 28 Jun, 2011 03:34:32

Message: 7 of 9


> Sorry, vedenev, I don't see the relevance of that to my question.
>
> In case I wasn't clear, the abort condition occurs the very first time the OpeningFcn is called, during GUI initialization. >When it occurs, I want the gui mfile to quit completely without ever drawing the window.

If your GUI name for example mygui.m then you can do function where
will be placed it:

if .... % open condition
 mygui;
else
  % do nothing
end

Subject: Aborting GUIDE guis

From: Krishna Kumar

Date: 28 Jun, 2011 04:43:05

Message: 8 of 9

"Matt J" wrote in message <iu4ikk$n6f$1@newscl01ah.mathworks.com>...
> I'm starting to get my feet wet with gui design via GUIDE. A difficulty that I'm having is that there are conditions -- determined during the initialization of the gui in the OpeningFcn (see code segment below) -- where I may want execution of the gui to abort completely, without ever even displaying its figure window.
>
> The problem seems to be, though, that while I can abort from the OpeningFcn via RETURN, control will then return to the GUImain function which then automatically (via gui_mainfcn?) makes the figure window visible (and also the OutputFcn is executed). There doesn't seem to be an obvious mechanism to trigger an abort of the entire GUI.
>
> Any recommendations?
>
>
>
> function varargout = GUImain(varargin)
>
> % Begin initialization code - DO NOT EDIT
> gui_Singleton = 1;
> gui_State = struct('gui_Name', mfilename, ...
> 'gui_Singleton', gui_Singleton, ...
> 'gui_OpeningFcn', @GUImain_OpeningFcn, ...
> 'gui_OutputFcn', @GUImain_OutputFcn, ...
> 'gui_LayoutFcn', [], ...
> 'gui_Callback', []);
> if nargin && ischar(varargin{1})
> gui_State.gui_Callback = str2func(varargin{1});
> end
>
> if nargout
> [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
> else
> gui_mainfcn(gui_State, varargin{:});
> end
> % End initialization code - DO NOT EDIT
>
>
> % --- Executes just before GUI is made visible.
> function GUI_OpeningFcn(hObject, eventdata, handles, varargin)
>
> ....
>
> if abortCondition
> return
> end
>
> .....
Hi
try using close function. This would close the figure too, if displayed.

Krishna

Subject: Aborting GUIDE guis

From: Matt J

Date: 28 Jun, 2011 14:25:04

Message: 9 of 9

vedenev <vedenev.maxim@gmail.com> wrote in message <7cfbee06-12a3-473b-9c83-479a85afc37b@gc3g2000vbb.googlegroups.com>...
>
> If your GUI name for example mygui.m then you can do function where
> will be placed it:
>
> if .... % open condition
> mygui;
> else
> % do nothing
> end
====================

Yes, that was matt dash's suggestion as well, and as I said, I did end up going with that. I still find it a little strange that GUIDE guis don't offer an abort mechanism, but I guess I'm still learning what's considered good practices in GUI programming...


>try using close function. This would close the figure too, if displayed.

 @Krishna,

Yes the close function will close the figure, but it won't prevent it from being openend :-)

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us