Code covered by the BSD License  

Highlights from
Waitbox

Waitbox

by

 

24 Jun 2013 (Updated )

Opens a window similar to waitbar.

[FigHandle]=waitbox(varargin)
function [FigHandle]=waitbox(varargin)
%WAITBOX Display wait bar.
%   H = waitbox()
%   creates and displays a waitbox.The
%   handle to the waitbox figure is returned in H.
%   
%   
%   waitbox ('message') will update the message text in
%   the waitbox figure, 
%
%   waitbox('message','title') will update the message text in
%   the waitbox figure and set tilte of the main figure window. 
%
%   Example:
%       figure;   
%       h = waitbox();
%       pause on;
%       for i=1:10:100,
%            plot(i:i+10,[i:i+10].*[i:i+10]);pause(0.1);
%            hold on;
%       end
%       delete(h)
%       
%       figure;
%       h = waitbox('Processing,Please wait..','Plot');
%       pause on;
%       for i=1:10:100,
%            plot(i:i+10,[i:i+10].*[i:i+10]);pause(0.1);
%            hold on;
%       end
%       delete(h)

%  By Shivaputra N. Narke,India

switch length(varargin)
    case 0
        Msg='Please wait...';
        Title='Waitbox';
    case 1
        Msg=varargin{1};
    case 2
        Msg=varargin{1};
        Title=varargin{2};
end
handles.figure1=figure('units','Normalized',...
                       'NumberTitle','off',...
                       'Name',Title,...
                       'Color',[0.9255 0.9137 0.8471],...
                       'ToolBar','None',...
                       'Menubar','None',...
                       'Position',[0.3604 0.3698 0.2783 0.1540],...
                       'Interruptible','on','BusyAction','cancel',...
                       'IntegerHandle','off',...
                       'InvertHardcopy','off','resize','off',...
                       'Nextplot','Replace');
 
                   
handles.text1 =uicontrol('units','Normalized','style','text',...
                        'Position',[0.0848 0.3059 0.8410 0.1529],...
                        'Backgroundcolor',[ 0.8549    0.7020    1.0000]);
                    
handles.text2 =uicontrol('units','Normalized','style','text',...
                        'Position',[0.0848 0.3059 0.1272 0.1529],...
                        'Backgroundcolor',[0.7490 0 0.7490]);
                    
handles.text3 =uicontrol('units','Normalized','style','text',...
                        'Position',[0.1131 0.5412 0.7809 0.1529],...
                        'String',Msg,'Fontsize',11);
Divider=4;
ud.Div=Divider;
FigHandle=handles.figure1;                    

movegui(handles.figure1,'center');
% drawnow;
set(FigHandle,'HandleVisibility','off');
set(FigHandle,'UserData',ud);

Position=get(handles.text1,'Position');
Position(3)=Position(3)/Divider;

Width=Position(3);
set(handles.text2,'Position',Position);
set(handles.text2,'Visible','on');
pause on;
t=timer;
set(t,'Period',0.34);
set(t,'TimerFcn',{@HandleTimerEvent,handles,Width});
set(t,'ExecutionMode','FixedSpacing');
start(t);
                    
                    
function HandleTimerEvent(varargin)

handles=varargin{3};
Width=varargin{4};

% Divider=varargin{5};
try
ud=get(handles.figure1,'UserData');
catch
   stop(varargin{1});return 
end
Divider=ud.Div;
try
Cpos=ud.Cpos;
catch
    Cpos=0;
end
Position=get(handles.text2,'Position');
% Position(3)=Position(3)/4;
if Cpos<Divider-1
Position(1)=Position(1)+Width;

else
Position(1)=Position(1)-Width;

end
Cpos=Cpos+1;
if Cpos==(Divider-1)*2
   Cpos=0; 
end
ud.Cpos=Cpos;
set(handles.figure1,'UserData',ud);
set(handles.text2,'Position',Position);
drawnow;



Contact us