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

4 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

David (degtusmc)
David (degtusmc) il 18 Lug 2013
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.

Più risposte (1)

Evan
Evan il 18 Lug 2013
Modificato: Evan il 18 Lug 2013
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 Commenti
David (degtusmc)
David (degtusmc) il 18 Lug 2013
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 il 18 Lug 2013
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.

Accedi per commentare.

Categorie

Scopri di più su Environment and Settings in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by