Path: news.mathworks.com!not-for-mail
From: "per isakson" <poi.nospam@bimDOTkthDOT.se>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Tempoarily Disable a GUI while a function is running
Date: Thu, 13 Sep 2007 19:37:50 +0000 (UTC)
Organization: KTH
Lines: 60
Message-ID: <fcc3ie$ctl$1@fred.mathworks.com>
References: <fc71me$ouq$1@fred.mathworks.com>
Reply-To: "per isakson" <poi.nospam@bimDOTkthDOT.se>
NNTP-Posting-Host: webapp-06-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1189712270 13237 172.30.248.36 (13 Sep 2007 19:37:50 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 13 Sep 2007 19:37:50 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1670
Xref: news.mathworks.com comp.soft-sys.matlab:428436


"Adam " <not.my.email@mathworks.com> wrote in message 
<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!!!
> 
> I'm pretty sure the following code will work:
>     set(hObject, 'Enable', 'off')
>     
>     set(handles.lblWait, 'String', 'Thinking ...')
>     pause(0.01)
>     fcnTestPlot(fVal, handles);   % <-- this is "long" fcn
> 
>     pause(0.01)
>     set(handles.lblWait, 'String', '')
>     set(hObject, 'Enable', 'on')
> 
>  It seems like a bit of a hack; i.e. is there a better 
way?

Yes, this is bizarre. I don't understand what is going on, 
but I don't think fcnRun is called multiple times. 

I tried this variant, which I think works

   function y = fcnRun( hObject, eventdata ) %#ok<INUSD>
        ii  = ii + 1;  % ii=1; in the outer function
        fprintf( '%i', ii )
        
        set( hSld, 'Enable', 'off' )
        set( hFig, 'Pointer', 'watch' )
        drawnow
        
        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) )

        set( hSld, 'Enable', 'on' )
        set( hFig, 'Pointer', 'arrow' )

    end