Moving between different GUI's (bypassing any intermediate GUI)

4 ビュー (過去 30 日間)
David (degtusmc)
David (degtusmc) 2013 年 7 月 8 日
Hello everyone,
I am trying to send data (i.e. user input inside text field) between two different GUI's, bypassing any intermediate GUI. I created a simple GUI to accomplish this after reading multiple forums and reading the Matlab documentation, but I am still having problems. The GUI I created using GUIDE, has a static text box in the "main" GUI. Then you press a push button to move to an "intermediate" GUI that opens a "third" GUI. Finally, the last GUI has a input text box that would change the value of the static text in the "main" GUI.
From everything I read, I believe the best way to accomplish this is by using setappdata and getappdata.
I am using the following code in the opening function:
% Set waiting flag in appdata
setappdata(handles.figure1,'waiting',1)
% UIWAIT makes GUI wait for user response (see UIRESUME)
uiwait(handles.figure1);
and I am using something like the following to move to the next GUI2:
GUI2('GUI2', handles.figure1);
to move back to previous GUI I use in the close request function:
uiresume(hObject);
%I want to change this line so it goes back to main not the previous GUI
How can I move to the main GUI from the third GUI, skipping the intermediate GUI?
Thank you in advance for any help provided.

採用された回答

David (degtusmc)
David (degtusmc) 2013 年 7 月 18 日
I believe I found a way to accomplish what I was trying to do... After calling the third GUI, I added an If statement to check if data was added to the root. If something was added to the root (data was recorded to be used in the main GUI), then immediately resume back to the main GUI. It looks something like:
Call third GUI:
testGUI3('testGUI3', handles.figure1);
if isappdata(0,'ReturnTestText')
check = getfield(getappdata(0,'ReturnTestText'), 'testText')
uiresume(handles.figure1);
end
The third GUI has two options. Record data (from the input text box) once a button is pushed (i.e. OK) or do nothing (i.e. CANCEL button).
%OK button
layers.testText = get(handles.test_edit1,'String');
setappdata(0,'ReturnTestText',layers);
uiresume(handles.figure1);
%CANCEL button
uiresume(handles.figure1);
This seems to be working. Any suggestions or comments are welcome.
Thank you for the help Evan. It is good to know different ways to accomplish a task.

その他の回答 (1 件)

Evan
Evan 2013 年 7 月 18 日
編集済み: Evan 2013 年 7 月 18 日
Others may be able to comment on the best way to do this using appdata. I have found, however, that simply passing the handles structure from your main to secondary GUIs is a convenient way of accomplishing this. This is how I do it:
In the callback in your main GUI that calls the secondary GUI:
function OpenSecondaryGui(hObject,eventdata,handles)
SG = SecondaryGui(handles);
set(SG,'WindowStyle','modal') %If you want to "freeze" main GUI until secondary is closed.
uiwait(SG) %Wait for user to finish with secondary GUI.
handles = guidata(hObject); %If your secondary GUI updates some handles, you'll need this line.
Then, in the opening function of your secondary GUI, you'd do something like this:
function SecondaryGUI_OpeningFcn(hObject,eventdata,handles,varargin)
handles.mainHandles = varargin{1}; %Get passed-in handles structure and add them to secondary GUI's handles structure
guidata(hObject, handles);
Finally, to pass data out of the GUI (such as through a user created "close" button, you save the portion of you secondary handles that contains the primary structure back to your main figure (this assuming that your opening function of the primary GUI saves the figure handle as "handles.main").
function CloseSecondary_Callback(hObject,eventdata,handles)
guidata(handles.mainHandles.main,handles.mainHandles)
You would just need to apply this another time to pass data through an intermediate to a third GUI.
If this is going away from the way you prefer too much, no worries. I just figured I'd leave it as a suggestion, as I've found it to be the cleanest way to share data between GUIs.
  2 件のコメント
David (degtusmc)
David (degtusmc) 2013 年 7 月 18 日
Thank you for the rapid response. It would change everything I have done so far, but I will definitely look into it and see how hard it would be to implement it.
Thanks again.
Evan
Evan 2013 年 7 月 18 日
No problem. Like I said, I don't want to cause you to have to change too much, but I just figured I'd share it. It was my (slightly defeated feeling) last choice after a fruitless attempt to get things working using setappdata.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by