From: myrt salt on
Arun Sreekantham wrote:
> sub-gui. You just have to remember that the 'handles' structure is
> kept in each gui's own and separate workspace. So if you would
> like
> access to any of one gui's variables in another gui, you need to
> save
> it to a structure and pass the structure, or have the information
> in
> a UIcontrol. Then you can get the information in another gui by
> using the 'findobj' or 'findall' commands. Remember to NEVER pass
> the 'handles' structure to another gui.
>
> arun

Why can't you pass the handles structure?

And, actually, how do you pass anything into a GUI? I tried putting
an input as part of varargin, but it made the GUIDE-generated
initialization code unhappy.

My situation is:

I have one GUI call another. I would like to have the subGUI call a
function to change some properties of the main GUI (i.e.
set(mainguihandles.text1,'String','BUSY') ). I'm having the darndest
time ....
From: Arun Sreekantham on
myrt salt wrote:
>
>
> Arun Sreekantham wrote:
>> sub-gui. You just have to remember that the 'handles'
structure
> is
>> kept in each gui's own and separate workspace. So if you would
>> like
>> access to any of one gui's variables in another gui, you need
to
>> save
>> it to a structure and pass the structure, or have the
information
>> in
>> a UIcontrol. Then you can get the information in another gui
by
>> using the 'findobj' or 'findall' commands. Remember to NEVER
> pass
>> the 'handles' structure to another gui.
>>
>> arun
>
> Why can't you pass the handles structure?
>
> And, actually, how do you pass anything into a GUI? I tried putting
> an input as part of varargin, but it made the GUIDE-generated
> initialization code unhappy.
>
> My situation is:
>
> I have one GUI call another. I would like to have the subGUI call a
> function to change some properties of the main GUI (i.e.
> set(mainguihandles.text1,'String','BUSY') ). I'm having the
> darndest
> time ....

handles are specific to each 'gui figure' so each sub-gui you make
will have it's own handles. let say you have a pushbutton that will
call another gui. then in the callback for that pushbutton you will
write:

sub_gui(input1, input2)

and remember that gui's used varargin so to access these in the
sub-gui they will be varargin{1} and varargin{2} Note that varargin
is a cell array.

you can also find the handles to UIcontrols in other gui figures by
using the 'findobj' and 'findall' functions. for your case you can
try:

hand_text1 = findall('Tag','text1);
set(hand_test1, 'String', 'busy')

hope this helps
From: Steve Simon on
myrt salt wrote:
> Arun Sreekantham wrote:
>
>>sub-gui. You just have to remember that the 'handles' structure is
>>kept in each gui's own and separate workspace. So if you would
>>like
>>access to any of one gui's variables in another gui, you need to
>>save
>>it to a structure and pass the structure, or have the information
>>in
>>a UIcontrol. Then you can get the information in another gui by
>>using the 'findobj' or 'findall' commands. Remember to NEVER pass
>>the 'handles' structure to another gui.
>>
>>arun
>
>
> Why can't you pass the handles structure?
>
> And, actually, how do you pass anything into a GUI? I tried putting
> an input as part of varargin, but it made the GUIDE-generated
> initialization code unhappy.
>
> My situation is:
>
> I have one GUI call another. I would like to have the subGUI call a
> function to change some properties of the main GUI (i.e.
> set(mainguihandles.text1,'String','BUSY') ). I'm having the darndest
> time ....

You can pass the handles structure, but that isn't necessarily the best
idea. If you pass the whole handles structure, and just use it, then
you will miss any changes that may occur later, because you are just
keeping a copy of the values it had at that time. If any changes are
made to it, in the other GUI's code, then you won't see them.

A better idea is to pass only the handle for the other GUI's figure.
The handles structure for each figure is stored in the appdata for that
figure. If you have a figure's handle, you can get the most recently
stored copy of its handles structure by using GUIDATA. So it's a better
idea to store the other figure's handles in the handles structure, and
then use it to get the other figure's structure when it is needed:

% in the OpeningFcn, you should be able to get 'otherFig'
% from the inputs
otherFig = varargin{1};
handles.otherFigure = otherFig;
guidata(hObject,handles)



% whenever you need to access something in the other figure
% get its handles structure by using GUIDATA
otherhandles = guidata(handles.otherFigure);


Examples that might be useful are:

http://www.mathworks.com/support/solutions/data/1-1BAR8.html?solution=1-1BAR8
http://www.mathworks.com/support/solutions/data/1-19YHX.html?solution=1-19YHX

Remember, the handles structure used in a function is just a local copy.
If you modify it, you need to save it with that figure again,
otherwise the changes will be lost. If you are passing it between
functions and there are changes made to it, then you also need to make
sure you pass it back out or save/reload it, otherwise the calling
function won't see the changes that were made. For example if you have
a function A, that passes the handles structure into function B, where
it is modified, then you need to return handles as an output from
function B, or you need to save it in function B, and reload it when you
return to function A:

%----------
% pass handles out as an output
function A(hObject,eventdata,handles)
handles = B(handles);

function handles = B(handles)
handles.newfield = 1;
%----------


%----------
% save/load handles
function A(hObject,eventdata,handles)
B(handles);
handles = guidata(handles.figure1);

function B(handles)
handles.newfield = 1;
guidata(handles.figure1,handles)
%----------


Using FINDOBJ and FINDALL will work too, but you have to make sure you
use the proper constraints to find only the object(s) that you want.
It's usually better to store a handle somewhere (like the handles
structure), than try to search for it later.


-SteveSimon-
From: myrt salt on
Steve Simon wrote:
> A better idea is to pass only the handle for the other GUI's
> figure.
> The handles structure for each figure is stored in the appdata for
> that
> figure.

I'm not sure what appdata is. Does this mean I could do something
like ....

%calling the subgui upon button press....
subgui(handles.figure1) % i think figure1 is the automatic tag of the
figure.
% then use guidata as you demonstrated?

Thanks so much for this help!

m.