Code covered by the BSD License  

Highlights from
CO2gui - lab control and automation

CO2gui - lab control and automation

by

 

06 Jan 2010 (Updated )

Software used for controlling and data logging lab equipment.

linktogui(varargin)
function varargout = linktogui(varargin)
% LINKTOGUI M-file for linktogui.fig
%      LINKTOGUI, by itself, creates a new LINKTOGUI or raises the existing
%      singleton*.
%
%      H = LINKTOGUI returns the handle to a new LINKTOGUI or the handle to
%      the existing singleton*.
%
%      LINKTOGUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in LINKTOGUI.M with the given input arguments.
%
%      LINKTOGUI('Property','Value',...) creates a new LINKTOGUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before linktogui_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to linktogui_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 linktogui

% Last Modified by GUIDE v2.5 06-Jul-2009 14:24:52

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @linktogui_OpeningFcn, ...
                   'gui_OutputFcn',  @linktogui_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 linktogui is made visible.
function linktogui_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 linktogui (see VARARGIN)

% error handling
if ~(nargin == 6)
    error('Incorrect number of input arguments')
else
    handles.callingButton = varargin{1};
    handles.optimiseGUIHandles = varargin{3};
end

% defines the parent
handles.parent = get(handles.callingButton, 'Parent');

% fetches the tag of the handle (the actual handle is a horribly unreadable
% number like 27.0023)
callingHandleString = get(handles.callingButton, 'Tag');

% extracts the numeric parts of the handle name (this 'number' is actually
% a string)
numberString = callingHandleString(isstrprop(callingHandleString, 'digit'));
% turns that into a number for convenience
handles.number = str2double(numberString);

% pre-allocates matrix for loop
enableValue = zeros(9, 1);
names=cell(9,1);

% fetches the values and names from the optimise GUI
for m = 1:9
    enableValue(m) = get(handles.optimiseGUIHandles.(sprintf('checkbox%d' ,m)), 'Value');
    names{m} = get(handles.optimiseGUIHandles.(sprintf('name%d',m)),'String');
end

%get which objects this object has already been linked to (if any)
linkedto = getappdata(handles.parent,sprintf('link%d', handles.number));

%change the name of the GUI
set(hObject,'Name',sprintf('Linked to Object %d',handles.number));

%loop through each object
for obj = 1:9
    textbox = sprintf('text%d',obj); %string for tectbox handle
    checkbox = sprintf('checkbox%d',obj); %string for checkbox handle
    
    set(handles.(textbox),'String',names{obj}) %set the name of the object
    
    if enableValue(obj) %is this object enabled in the optimise GUI
        if linkedto(obj) %if this object has been set previously as a linked object then tick box
            set(handles.(checkbox),'Value',1)
        else
            set(handles.(checkbox),'Value',0)
        end
    else
        set(handles.(checkbox),'Enable','Off','Value',0)
        %don't allow this object to be selected and make certain that the box is not ticked
    end

    if obj==handles.number %so if this is the calling object can't link to it hence;
        set(handles.(checkbox),'Enable','Off','Value',0)
        %turn button off, not ticked

        set(handles.(textbox),'ForegroundColor',[1 0 0],'TooltipString','Can''t Select Link To Self')
        %change textbox to red text and give a mouse over box (tooltip)
    end
end

setappdata(handles.optimiseGUIHandles.MainGUI,'linktoHandle',handles.linktogui); %pass handle to the mainGUI
setappdata(handles.optimiseGUIHandles.optimisegui,'linktoHandle',handles.linktogui); %pass handle to optimisegui

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

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes linktogui wait for user response (see UIRESUME)
% uiwait(handles.linktogui);


% --- Outputs from this function are returned to the command line.
function varargout = linktogui_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 handles and user data (see GUIDATA)

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


% --- Executes on button press in checkbox1.
function checkbox1_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox1 (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 checkbox1


% --- Executes on button press in checkbox2.
function checkbox2_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox2 (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 checkbox2


% --- Executes on button press in checkbox3.
function checkbox3_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox3 (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 checkbox3


% --- Executes on button press in checkbox4.
function checkbox4_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox4 (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 checkbox4


% --- Executes on button press in checkbox5.
function checkbox5_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox5 (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 checkbox5


% --- Executes on button press in checkbox6.
function checkbox6_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox6 (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 checkbox6


% --- Executes on button press in checkbox7.
function checkbox7_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox7 (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 checkbox7


% --- Executes on button press in checkbox8.
function checkbox8_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox8 (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 checkbox8


% --- Executes on button press in checkbox9.
function checkbox9_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox9 (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 checkbox9


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

%pre allocate the new linked to matrix
linked = zeros(1,9);

%loop through each object
for obj = 1:9
    checkbox = sprintf('checkbox%d',obj); %string for checkbox handle
    linked(obj) = get(handles.(checkbox),'Value'); %get the link value
    fieldname = sprintf('link%d', obj); %field name in appdata
    objlink = getappdata(handles.parent,fieldname); %get which objects this object is already linked to
    if linked(obj)==1 %so if this object is linked then must be the case that it works the other way around
        objlink(handles.number) = 1;
    else
        objlink(handles.number) = 0;
    end
    setappdata(handles.parent,fieldname,objlink); %update the objects linkdata
end

fieldname = sprintf('link%d', handles.number); %string for field to save to
setappdata(handles.parent,fieldname,linked); %save the new linked values to the appdata of the optmise GUI
linktogui_CloseRequestFcn(hObject, eventdata, handles) %close the GUI    


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

%don't change anything just close the GUI
linktogui_CloseRequestFcn(hObject, eventdata, handles) 


% --- Executes when user attempts to close linktogui.
function linktogui_CloseRequestFcn(callingObject, eventdata, handles)
% callingObject    handle to what ever try to close the linktogui
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% run the enable function to recalc the number of dims
optimisegui('enableCallback',handles.callingButton, eventdata, handles.optimiseGUIHandles)

linktogui = get(callingObject,'Parent');

%if the actual close button is pressed than the calling object is the GUI
%itself which means the parent is the main system which can't be closed
if linktogui == 0 
    delete(callingObject) %thus close the current figure using this handle
else %another button in the GUI hence the parent is the GUi
    delete(linktogui) %clse the current figure
end


Contact us