function varargout = GUI_Practice(varargin)
%animal_name = GUI_Practice
%Requires user to enter animal name and check box that power is on before GUI closes
%and returns the animal's name. Caution this has not been seriously vetted for bugs.
%
%Example of GUI that passes output, complements post about the topic:
%http://neurochannels.blogspot.com/2013/12/getting-output-from-matlab-gui.html
%Made with the help of the following:
%http://blogs.mathworks.com/videos/2010/02/12/advanced-getting-an-output-from-a-guide-gui/
%
%If you are having trouble getting it to work, let me know what you have tried and I'll
%try to help.
%
%Eric Thomson
%thomson.eric (at gmail)
%
%
% GUI_PRACTICE M-file for GUI_Practice.fig
%      GUI_PRACTICE, by itself, creates a new GUI_PRACTICE or raises the existing
%      singleton*.
%
%      H = GUI_PRACTICE returns the handle to a new GUI_PRACTICE or the handle to
%      the existing singleton*.
%
%      GUI_PRACTICE('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in GUI_PRACTICE.M with the given input arguments.
%
%      GUI_PRACTICE('Property','Value',...) creates a new GUI_PRACTICE or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before GUI_Practice_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to GUI_Practice_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help GUI_Practice

% Last Modified by GUIDE v2.5 02-Dec-2013 14:24:07
%


% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @GUI_Practice_OpeningFcn, ...
                   'gui_OutputFcn',  @GUI_Practice_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
% End initialization code - DO NOT EDIT


% --- Executes just before GUI_Practice is made visible.
function GUI_Practice_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to GUI_Practice (see VARARGIN)

% Choose default command line output for GUI_Practice
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes GUI_Practice wait for user response (see UIRESUME)
%so it doesn't return values right away, makes GUI wait, halting execution until
%the figure is closed or uiresume is called
uiwait(hObject);  


% --- Outputs from this function are returned to the command line.
function varargout = GUI_Practice_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with hanadles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.animal_name;  %defined in start_program_button_Callback

% The figure can be deleted now
delete(hObject);
     
% --- Executes on button press in power_check.
function power_check_Callback(hObject, eventdata, handles)
% hObject    handle to power_check (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of power_check


% --- Executes on button press in commutator_check.
function commutator_check_Callback(hObject, eventdata, handles)
% hObject    handle to commutator_check (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of commutator_check


% --- Executes on button press in video_check.
function video_check_Callback(hObject, eventdata, handles)
% hObject    handle to video_check (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of video_check


% --- Executes on button press in lights_check.
function lights_check_Callback(hObject, eventdata, handles)
% hObject    handle to lights_check (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of lights_check


% --- Executes on button press in start_program_button.
function start_program_button_Callback(hObject, eventdata, handles)
% hObject    handle to start_program_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%If data is not there, do not let them close.
pow_check=get(handles.power_check, 'Value');
animal_name=get(handles.name_static,'String');
if pow_check && ~isempty(animal_name) 
     handles.animal_name=animal_name;
     % IMPORTANT:
     % Remember to save the "handles" structure to the GUI figure
     % by calling GUIDATA every time you make modifications to it.
     % Otherwise, the changes made to "handles" is lost after the callback
     % function returns.
     guidata(hObject, handles);
     close(handles.figure1);
else
    display('Not ready to start...');
end


function name_edit_Callback(hObject, eventdata, handles)
% hObject    handle to name_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
name_val= get(handles.name_edit,'String');
set(handles.name_static,'String',name_val);
% Hints: get(hObject,'String') returns contents of name_edit as text
%        str2double(get(hObject,'String')) returns contents of name_edit as a double


% --- Executes during object creation, after setting all properties.
function name_edit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to name_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in name_button.
function name_button_Callback(hObject, eventdata, handles)
% hObject    handle to name_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes when user attempts to close figure1.
function figure1_CloseRequestFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: delete(hObject) closes the figure
% delete(hObject);

if isequal(get(hObject, 'waitstatus'), 'waiting')
    % The GUI is still in UIWAIT, call UIRESUME
    uiresume(hObject);
else
    % The GUI is no longer waiting, just close it
    delete(hObject);
end

