now I have two GUIs. One is 开发者_开发技巧named Main and the other named Sub.
Sub is called from Main, and in it I want to do some updates of Main's data.
So in Sub, I use
mainGUI = guidata(Main)
set(mainGUI.Button,'Enable','on') %% originally it is off
gudata(Main,mainGUI)
then the Sub is closed and we are back to Main. However the handles of Main has not been changed until you open and close Sub twice.
the idea of the program is
at first you have a Main which only allows you to click one button (open Sub, a file selection interface), then after you have correctly chosen and imported data in Sub, when you go back to Main it automatically activate corresponding buttons(which were off before).
Any comments are welcome. Thank you in advance.
I may not understand fully your question (see my comment) but I did a sample code that works as you seem to expect it.
I think the part you are missing is that you need to pass the main figure handle to your sub gui in order for the data to be reachable. As far as I understand it, the data is stored by guidata in the figure environment and therefore you need to know the handle to a figure to be able to access its stored gui data.
Here it is :
Main GUI
% GUI
function so_multiguiA
% Layout
figure('units','normalized','position',[0.2 0.2 0.3 0.3],'tag','figure');
datamain=guihandles(gcf);
uicontrol('style','pushbutton','string','Click me', ...
'parent',datamain.figure,'units','normalized', ...
'Position',[0.2 0.2 0.6 0.6],'tag','button', ...
'callback',@buttonmain_callback);
datamain=guihandles(gcf);
% Data
guidata(gcf,datamain);
end
% Callback
function buttonmain_callback(obj,event)%#ok
so_multiguiB(gcbf);
end
Sub GUI
% GUI
function so_multiguiB(mainhandle)
% Layout
figure('units','normalized','position',[0.5 0.5 0.3 0.3],'tag','figure');
datasub=guihandles(gcf);
uicontrol('style','pushbutton','string','Disable main button', ...
'parent',datasub.figure,'units','normalized', ...
'Position',[0.2 0.2 0.6 0.6],'tag','button', ...
'callback',@buttonsub_callback);
datasub=guihandles(gcf);
% Data
datasub.mainhandle=mainhandle;
guidata(gcf,datasub);
end
% Callback
function buttonsub_callback(obj,event)%#ok
datasub=guidata(gcbf);
datamain=guidata(datasub.mainhandle);
set(datamain.button,'enable','off');
end
Hope it helps.
精彩评论