Execute callback between different GUIs

조회 수: 5 (최근 30일)
fjnb86
fjnb86 2012년 1월 12일
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에서 App Building에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by