Opening Function, Close GUI Confirmation, and Reset Button

There are a couple other modifications that must be done to the opening function. In addition, this section will also introduce a “Reset Button” to the GUI.

  1. First, lets deal with the opening function. Here, we are going to add the standard tool bar and the “close GUI confirmation dialog”.

    %%
    function data_processing_tool_OpeningFcn(hObject, eventdata, handles, varargin)
     
    handles.output = hObject;
    set(hObject,'toolbar','figure'); %enables toolbar
     
    %this variable used to prevent users from breaking the GUI
    %the variable is set to 1 once the data has been processed
    handles.processDataCompleted = 0; %
     
    %this command asks the user to confirm closing of GUI
    set(handles.figure1,'CloseRequestFcn','closeGUI');
     
    % Update handles structure
    guidata(hObject, handles);

    For more information on the “Close GUI Confirmation”, you can visit this post.

    function closeGUI
     
    selection = questdlg('Do you want to close the GUI?',...
                         'Close Request Function',...
                         'Yes','No','Yes');
    switch selection,
       case 'Yes',
        delete(gcf)
       case 'No'
         return
    end

    Data Processing GUI

  2. Now, for the reset button. Resetting your GUI to the default state can save the user a lot of time and fustration. Instead of closing and opening the GUI to get to the starting state, the user can simply click on the “reset” button.

    function reset_pushbutton_Callback(hObject, eventdata, handles)
    %resets the GUI by clearing all relevant fields
     
    handles.processDataCompleted = 0;
     
    %clears the axes
    cla(handles.axes1,'reset');
     
    %set the popupmenu to default value
    set(handles.plot_popupmenu,'Value',1);
     
    %clears the contents of the listbox
    set(handles.inputFiles_listbox,'String','');
    set(handles.inputFiles_listbox,'Value',0);
     
    %updates the handles structure
    guidata(hObject, handles);

This is the end of the tutorial.

Pages: 1 2 3 4 5 6 7