Code covered by the BSD License  

Highlights from
GUIDE Callback Helper

from GUIDE Callback Helper by Brian Cody
Get access to callback event data in your GUIDE GUIs.

GuideCallbackHelper
% GUIDECALLBACKHELPER
%   GUIDECALLBACKHELPER is a class that gives access to callback event data
%   for GUIs developed using GUIDE.
%
%   GUIDECALLBACKHELPER(@mygui) creates an instance of GuideCallbackHelper
%   attached to mygui, where mygui is a GUI that has been developed using
%   GUIDE.
%
%   To attach callbacks that will receive all callback parameters
%   (including the event data objects), execute
%       SetCallbackFcn(helper, tag, name, fcn)
%   where:
%       - helper is an instance of a GuideCallbackHelper that has been
%         attached to a GUIDE GUI.
%       - tag is the value of the 'Tag' property on the control whose
%         callback is being set (this can be found using the Property
%         Inspector in GUIDE).
%       - name is the name of the callback to be attached.
%       - fcn is a function handle for the function to be executed when the
%         callback fires.
%
%   Example: Given a blank GUIDE GUI saved as gui.fig and gui.m, attach a
%   WindowScrollWheelFcn that displays the event data for that callback.
%      gch = GuideCallbackHelper(@gui);
%      gch.SetCallbackFcn('figure1', 'WindowScrollWheelFcn', ...
%                         @(o,e)disp(e));
%
%   See also GUIDE, FUNCTION_HANDLE

%   Copyright 2008 The MathWorks, Inc.
classdef GuideCallbackHelper
    properties (SetAccess = private)
        GUIFcn
    end

    methods
        % Construct a new instance of the GuideCallbackHelper.
        % @param guifcn A function handle to the GUI created in GUIDE.
        function gch = GuideCallbackHelper(guifcn)
            gch.GUIFcn = guifcn();
        end

        % Sets a callback function on the contained GUI.  This callback
        % function will receive all callback parameters (e.g. the event
        % data).
        % @param gch Instance of a GuideCallbackHelper object.
        % @param controlTag The value of the 'Tag' property on the control
        %        whose callback is being set.
        % @param callbackName The name of the callback property to set.
        % @param callbackFcn Function handle to the callback function.
        function SetCallbackFcn(gch, controlTag, callbackName, callbackFcn)
            control = findobj(gch.GUIFcn, 'Tag', controlTag);
            set(control, callbackName, callbackFcn);
        end

    end
    
end

Contact us at files@mathworks.com