


BUSYFIGURE Disable/restore a UI figure. OLDINFO = BUSYFIGURE(FIGUREHANDLE, BUSY) freezes (or unfreezes) the UI figure when it is busy (done) with a task; the BUSY argument is 1 to freeze and 0 to unfreeze. Freezing disables all uicontrols, disables the figure's click callback, and sets the mouse pointer to a watch. BUSYFIGURE(FIGUREHANDLE, BUSY, STATUSSTRING, OLDINFO) also sets status information via the Matlab 'setstatus' function; passing an empty string will skip this call. (Note that passing in an empty string does _not_ set the status to ''.) When freezing, the figure's original pre-freeze state is returned; pass this structure as the fourth argument when unfreezing to restore state.


0001 function oldinfo = busyfigure(figurehandle, busy, statusstring, oldinfo) 0002 %BUSYFIGURE Disable/restore a UI figure. 0003 % OLDINFO = BUSYFIGURE(FIGUREHANDLE, BUSY) freezes (or unfreezes) the UI 0004 % figure when it is busy (done) with a task; the BUSY argument is 1 to 0005 % freeze and 0 to unfreeze. Freezing disables all uicontrols, disables 0006 % the figure's click callback, and sets the mouse pointer to a watch. 0007 % 0008 % BUSYFIGURE(FIGUREHANDLE, BUSY, STATUSSTRING, OLDINFO) also sets status 0009 % information via the Matlab 'setstatus' function; passing an empty 0010 % string will skip this call. (Note that passing in an empty string 0011 % does _not_ set the status to ''.) When freezing, the figure's 0012 % original pre-freeze state is returned; pass this structure as the 0013 % fourth argument when unfreezing to restore state. 0014 0015 if (busy) % FREEZE 0016 0017 % Get current uicontrol handles and enable states. 0018 controls = get(figurehandle, 'Children'); 0019 oldinfo.controls = controls(strcmp(get(controls, 'Type'), 'uicontrol')); 0020 oldinfo.enables = get(oldinfo.controls, 'Enable'); 0021 set(oldinfo.controls, 'Enable', 'off'); 0022 0023 % Deal with the status bar. 0024 statusbarH = controls(find(strcmp(get(controls, 'Tag'), 'Status'))); 0025 if (~isempty(statusbarH)), set(statusbarH, 'Enable', 'on'); end % need enabled 0026 if (~isempty(statusstring)), setstatus(figurehandle, statusstring); end 0027 0028 % Unset the figure mouse press callback, but save it for later restoration. 0029 oldinfo.figure_click_callback = get(figurehandle, 'ButtonDownFcn'); 0030 set(figurehandle, 'ButtonDownFcn', ''); 0031 0032 % Set pointer to watch to visually indicate that we're busy. 0033 oldinfo.pointer = get(figurehandle, 'Pointer'); 0034 setptr(figurehandle, 'watch'); 0035 0036 else % RESTORE 0037 if (nargin < 4) 0038 error('Unfreezing requires the structure returned when the figure was frozen.'); 0039 end 0040 0041 % Restore enable states. 0042 for cntrl = 1:length(oldinfo.enables) 0043 set(oldinfo.controls(cntrl), 'Enable', oldinfo.enables{cntrl}); 0044 end 0045 0046 % Status update. 0047 if (~isempty(statusstring)), setstatus(figurehandle, statusstring); end 0048 0049 % Reset the figure mouse click callback. 0050 set(figurehandle, 'ButtonDownFcn', oldinfo.figure_click_callback); 0051 0052 % Finally, restore old pointer. 0053 setptr(figurehandle, oldinfo.pointer); 0054 end