GUI Examples #9:Explore user notification

December 8, 2009 by Matt Fig 
Filed under: GUI, Tutorials 
Leave a Comment
VN:F [1.8.1_1037]
Rating: 0 (from 0 votes)
VN:F [1.8.1_1037]
Rating: 0.0/10 (0 votes cast)

Pushing the pushbutton causes the GUI  to simulate a running process and let the user know this process has not finished.

GUIExample9

GUIExample9_2

function [] = GUI_9()
% Demonstrate one way to let the user know a process is running.
% Creates a pushbutton which, when pushed, simulates some process running
% in the background and lets the user know this is happening by a text and
% color change.  When the process is finished, the button returns to
% normal.  CAREFULLY READ THE COMMENTS BELOW IF YOU PLAN ON USING THIS
% METHOD IN ONE OF YOUR GUIs.
%
%
% Author:  Matt Fig
% Date:  7/15/2009
 
S.fh = figure('units','pixels',...
 'position',[300 300 200 100],...
 'menubar','none',...
 'name','GUI_9',...
 'numbertitle','off',...
 'resize','off');
S.pb = uicontrol('style','push',...
 'unit','pix',...
 'position',[20 20 160 60],...
 'string','Push Me',...
 'callback',{@pb_call},...
 'backgroundc',[0.94 .94 .94],...
 'busyaction','cancel',...% So multiple pushes don't stack.
 'interrupt','off');
 
function [] = pb_call(varargin)
% Callback for pushbutton.
h = varargin{1}; % Get the caller's handle.
col = get(h,'backg')% Get the background color of the figure.
set(h,'str','RUNNING...','backg',[1 .6 .6]) % Change color of button.
% The pause (or drawnow) is necessary to make button changes appear.
% To see what this means, try doing this with the pause commented out.
pause(.01)  % FLUSH the event queue, drawnow would work too.
% Here is where you put whatever function calls or processes that the
% pushbutton is supposed to activate.
% Next we simulate some running process.  Here just sort a vector.
A = rand(3000000,1);
A = sort(A);
set(h,'str','Push Me','backg',col)  % Now reset the button features.
VN:F [1.8.1_1037]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.1_1037]
Rating: 0 (from 0 votes)

Popularity: 3% [?]

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Live
  • PDF
  • Technorati
  • Twitter
  • Yahoo! Bookmarks
  • Add to favorites
  • email
  • MySpace
  • RSS

Related Posts

Comments

Comments are closed.