How do I Interact with a GUIDE GUI via Command Line?
20 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello!
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 = [
handles.generate_init_fits_button,
handles.review_init_fits_button,
handles.gen_final_fits_button,
handles.review_final_fits_button,
handles.scatter_plot_button,
handles.deletedLog_button,
handles.analyze_button];
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.pause_button,
handles.stop_button,
handles.prev_button,
handles.next_button];
handles.edit_handles = [
handles.delete_button,
handles.undo_delete_button,
handles.manual_fit_button];
handles.jump_handles = [
handles.jump_button,
handles.jump_value,
handles.jump_text];
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!
2 Commenti
Valentino Tomasic
il 3 Ago 2017
Modificato: Valentino Tomasic
il 3 Ago 2017
Hi Tanner
Where Steven Lord says that only the first function of a script with multiple functions is "visible" to outer functions or command line (in your case).
So unfortunately you won't be able to call the opening_fcn or your controlls_callbacks. The only function you can call from command line is the first function of your gui script called "varargout = gui(varargin)"
Walter Roberson
il 3 Ago 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
Risposte (2)
Akhilesh Thakur
il 3 Ago 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.
Akhilesh
0 Commenti
Walter Roberson
il 4 Ago 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.
0 Commenti
Vedere anche
Categorie
Scopri di più su Migrate GUIDE Apps 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!