chain together GUIs in MATLAB
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am trying to create a program in matlab that chains together several tested, functioning GUIs but I am having some trouble.
In one function I have:
global Status;
global value1;
Status = 'setup';
switch Status
case 'setup'
ADone = ASetup; %Calls setup function which should return a value when done
if strcmp(ADone, 'yes')==1
Status = 'Pos1';
end
case 'Pos1'
value1 = OHMgui1;
Status = 'Pos2';
case 'Pos2'
%Still work in progress
end
And in my Asetup function I have:
function done = ASetup
AStatus = GUI1;
BStatus = GUI2();
CStatus = GUI3();
DStatus = GUI4();
%Up until here everything goes as intended
Refstatus = RefGUI();
done = 'yes'; %Returns value when finished
disp (done) %Check statement, does not execute, error happens somewhere before here
end
GUIs 1-4 basically just display reference images with an OK button to close them, and I control them by using uiwait() and having them set a return value when the OK button is pushed (to make sure one doesn't trigger until the previous one is closed). This functions exactly as I would like.
However for RefGUI, I created it with a continue and a close button. I want the user to be able to click continue and have the program continue while RefGUI stays open. Ideally this would result in a call OHMGUI1, but it doesn't even seem to display the check statement.
I suspect the error is in RefGUI, which opens at the correct time, but I cannot get anything to happen after the continue or close buttons are pressed (with the exception of closing the GUI without the program continuing). Its code is:
function varargout = RefGUI(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ClampRef_OpeningFcn, ...
'gui_OutputFcn', @ClampRef_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function RefGUI_OpeningFcn(hObject, eventdata, handles, varargin)
matlabImage = imread('C:...reference.jpg');
image(matlabImage)
axis off
axis image
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
set(handles.pushbutton2,'enable','off') %Disable close button until continue is pressed
function varargout = RefGUI_OutputFcn(hObject, eventdata, handles)
uiwait();
global valueout;
varargout{1} = valueout;
%I have also tried disabling the above 3 lines with no difference.
function pushbutton1_Callback(hObject, eventdata, handles)
global valueout;
valueout = 'Finished';
set(handles.pushbutton2,'enable','on') %enable close button
set(handles.pushbutton1,'enable','off') %disable continue button
return
function pushbutton2_Callback(hObject, eventdata, handles)
closereq(); %close button closes GUI window
What can I do to make the program continue as intended?
0 commentaires
Réponses (1)
Andrew McReynolds
le 21 Mar 2020
3 commentaires
Rik
le 23 Mar 2020
You can use the handles to the different GUIs to retrieve their guidata just before they close. I would suggest moveing away from GUIDE. It is probably holding you back in understanding how it works (although I can see from your edited down code in your question you seem to at least get the basics). If you want some helpful advice I would encourage you to check out this thread.
You could even consider a class-based GUI like my example in that thread if you want to preserve the input after the GUI has been closed.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!