How do I Interact with a GUIDE GUI via Command Line?

20 views (last 30 days)
I have a GUI made with GUIDE that runs some analysis that I am working on. I want to automate the process of analyzing by running it without user interaction as a sequence of commands. The problem is, the GUI has some initialization code that would normally run when the GUI is opened. Therefore, trying to execute a callback in the GUI from the command line with something like
gui('load_button_Callback', handles.load_button, [], handles);
doesn't work, because the callback depends on handles and values set at initialization. Specifically, I have a function that executes when the GUI opens to initialize things (see below). Other callbacks try to set values for "handles.jump_handles" for instance, but that generates the error "Reference to non-existent field 'jump_handles'." when calling the function as shown above. Is there a way for me to open the GUI and directly call its various callback functions, behaving as it would if I opened the GUI like normal and clicked on a button?
function gui_OpeningFcn(hObject, eventdata, handles, varargin)
global frames params config
global direction split
function_handles = [
set(function_handles, 'Enable','off')
set([handles.deleteUnconverged_button handles.deleteOutliers_button],'Visible','off');
frames = struct();
frames.deleted.all = [];
frames.deleted.manual = [];
frames.deleted.outliers = [];
frames.deleted.unconverged = [];
frames.bad.outliers = [];
frames.bad.unconverged = [];
direction = 'leftright';
split = 0;
params = get_params();
N = params.config.N;
config.N = N;
write({'Follow steps in order:',
'- Load .Tif File',
'- Generate Initial Fits',
'- Perform Steepest Descent',
'- Analyze Modes'
'- Save Data'},handles)
handles.nav_handles = [
handles.edit_handles = [
handles.jump_handles = [
set([handles.nav_handles; handles.edit_handles], 'Enable','off')
% Choose default command line output for gui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
Thanks in advance!
Walter Roberson
Walter Roberson on 3 Aug 2017
Although this is generally true, GUIDE created guis have a built-in interface that allows any routine to be called from outside.
I am on my phone at the moment so I will explain later

Sign in to comment.

Answers (2)

Akhilesh Thakur
Akhilesh Thakur on 3 Aug 2017
Hi Tanner, I have been working on same kindoff automation. The thing is you want to do is kick off the GUI and apply all your commands automatically. I would suggest write a function for GUI_Start(main_handle,arg). The main_handle will be your GUI name and args is the list of the data you want to pass in that. So define that function in another file and also define and initialise the arguments and what all you want to do with them. This all can be operated from command window.
Hope this helps.

Walter Roberson
Walter Roberson on 4 Aug 2017
Suppose your main GUIDE GUI is named MyGUI . Suppose it has a function pushbutton1_Callback . Then GUIDE does not exactly set the properties of pusbutton1 as
... 'Callback', @pushbutton1_Callback, ...
Instead it does
... 'Callback', @(hObject,eventdata) MyGUI('pushbutton1_Callback', hObject, eventdata, guidata(hObject)), ...
That is, GUIDE creates the main function (MyGUI in this case) so that if it is called with arguments, then the first argument is expected to be the name of a function to call. It makes that call from within MyGUI.m, so if the routine is defined inside MyGUI.m then it can still be reached.
Therefore if you want to call into MyGUI.m from outside of it, you can use the same technique> call MyGUI and pass in as the first argument the name of the function you wish to call, and pass the object and event data and handles structure.


Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by