Path: news.mathworks.com!not-for-mail
From: "Adam " <not.my.email@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Tempoarily Disable a GUI while a function is running
Date: Wed, 12 Sep 2007 16:03:23 +0000 (UTC)
Organization: Atlantic Inertial Systems
Lines: 87
Message-ID: <fc92kb$le3$1@fred.mathworks.com>
References: <fc71me$ouq$1@fred.mathworks.com> <fc7qds$6pt$1@fred.mathworks.com>
Reply-To: "Adam " <not.my.email@mathworks.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1189613003 21955 172.30.248.38 (12 Sep 2007 16:03:23 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 12 Sep 2007 16:03:23 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1091020
Xref: news.mathworks.com comp.soft-sys.matlab:428108


"Steven Lord" <slord@mathworks.com> wrote in message
<fc7qds$6pt$1@fred.mathworks.com>...
> 
> "Adam " <not.my.email@mathworks.com> wrote in message 
> news:fc71me$ouq$1@fred.mathworks.com...
> >I have a complicated function that take awhile to run.  I
> > have set up a GUI using GUIDE to handle different variables.
> > The problem I have is the user can click the run button, or
> > a slider control multiple times.  This calls multiple
> > instances of the function, with bizarre results.  In a
> > couple cases enough functions are called to crash Matlab.
> >
> > I tried making the waitbar() modal.  However, you can still
> > sneak in 2-3 button presses.  Even worse, if you click a
> > slider control it locks and then proceeds to repeatedly push
> > the slider button (calling a function instance every time)
> > until it reaches the max limit!!!
> 
> *snip*
> 
> Read this section from the documentation that discusses
Callback 
> Interruption:
> 
>
http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/creating_guis/bq61qtj-1.html
> 
> Note this is from the MATLAB 7.5 (R2007b) documentation,
but I don't believe 
> there was any change in this functionality from MATLAB 7.4
(R2007a) to 7.5.
> 
> -- 
> Steve Lord
> slord@mathworks.com 

so a dialog box doesn't automatically set Interruptible to
'off' and BusyAction to 'cancel'.  However, setting these
properties has no effect.  Please run this code, and click
on the left, slider button.  

What am I missing?

Also, callback_interrupt.m didn't come with my matlab
installation.

% --- begin code -------------------------------------------
function testCallback()
    cellName = {'BusyAction', 'Interruptible'};
    cellValue = {   'cancel', 'off'};

    hFig = figure('Position', [100 100 320 240], ...
                  cellName, cellValue);
    
    hSld = uicontrol(hFig, 'Style', 'slider', ...
                    'Position', [10 10 300 20], ...
                    'BackgroundColor', [0.9 0.9 0.9], ...
                    'Callback', @fcnRun, ...
                    'Value', 0.1, ...
                    cellName, cellValue);
                
    hTxt = uicontrol(hFig, 'Style', 'edit', ...
                    'Position', [100 100 120 20], ...
                    'BackgroundColor', 'white', ...
                    cellName, cellValue);
                
    function y = fcnRun(hObject, eventdata)
        hBox = msgbox('Please Wait', 'WindowStyle', 'modal');
        set(hBox, cellName, cellValue);

        y = zeros(1, 1e6);
        
        % do something that takes time
        for idx = 1: length(y)
            y(idx) = sin(idx * 2 * pi / 100) + randn(1, 1);
        end
        
        set(hTxt, 'String', sum(y))

        close(hBox)
    end

end
% --- end code --------------------------------

Yair, thanks for the link, but I can't use functionality
that is undocumented and unsupported.