Execute callback between different GUIs

1 次查看(过去 30 天)
Hello everybody!
Easy question (I think)
I have two GUIs with its own buttons:
GUI_A GUI_B
I want to execute a callback in B and at then, execute the other callback in A.
Code example in GUI_B:
%
button_GUIB_callback(hObject, eventdata, handles)
code
guidata(hObject, handles);
if GUI_A still open
???execution of button_GUIA_callback
close(GUI_B)
else
msgbox('you closed the other window dude!' )
end
I was looking for the answer but I can not find exactly what I want or if is possible.
Thanks in advance

采纳的回答

fjnb86
fjnb86 2012-3-16
Hi David,
I solved going to the properties in the GUI that I have in the background (A), clicking in the properties of this button that I want to execute.
There is a code which appears in the field Callback
Finally I put this code in the button of GUI B, and works!
GUI_A('pushbutton1_Callback',gcbo,[],guidata(gcbo))
close %close GUI_B
Of course I must use "getappdata" and "setappdata2 to move the data between GUIs
:D

更多回答(2 个)

David
David 2012-1-12
Pass the handle to gui A into the init of gui B and then check the status of A in B.
e.g.
h = guiA;
guiB(h);
in the guiB init code you can add h to your handles -> Robert is your mothers brother.
N.B. ensure that GUIA is written such that it returns the relevant handle.
  2 个评论
fjnb86
fjnb86 2012-1-12
Hi David, thanks
If I follow your instructions when I pass the handle A to my B, A "restarts" and I am no interested in that because loads some code that I put there.
Is it the only way?
David
David 2012-1-12
Sorry I didn't really answer your question there (I was looking at the checking of GUI being open bit, rather than the question you were asking about the visibility of GUIA callback). See my next attempt for providing your answer.

请先登录,再进行评论。


David
David 2012-1-12
Sorry misread what you want. Try making the callback function a separate function in its own m-script and then ensure that you pass the correct data into your callback. e.g. have guiA.m, guiB.m and guiBtnCallBack.m which contains a fcn
function guiBtnCallBack(hObj, evtData, handles)
Ensuring that gui B has sufficient data passed into it for calling this callback, then both A and B can call it.

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by