Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Putting a progress bar on a GUI - sorry, you're out of luck

1,499 views
Skip to first unread message

ImageAnalyst

unread,
Dec 11, 2008, 10:13:20 AM12/11/08
to
How can I put a progress bar onto my own custom GUI?

I know Ash asked this on Sept. 30th, and Walter said to check out
waitbar(), but this solution doesn't really work. For one thing,
waitbar brings up a completely separate window - it is not placed on
my main GUI.
Secondly, and most annoyingly, when my GUI is busy crunching away in
it's loop and displaying stuff (like images) on the GUI, the GUI comes
to the top and completely obscures the waitbar (which is now
underneath). I like to have my GUI's be full screen and a (bad)
workaround would be to make the GUI non-fullscreen, and try to arrange
the waitbar and GUI so that the waitbar does not get obscured, but
this is not really a nice solution.

Similarly there are several waitbar or progress bar functions uploaded
to the File Exchange but they're all separate windows and can't be
placed on your own custom GUI. GET A CLUE MATHWORKS! Look at the
most commonly searched terms on the FileExchange:
"abort ascii ascii progress bar bar class completion eta example
graphics gui gui tools interrupt merge meter ode process progress
progress bar progress text status terminate time left utilities wait
bar waitbar "
13 of the 25 terms of them are various names for showing progress or
completion. Doesn't that tell you something?????!!!!!

You should be able to have a progress bar placed on the GUI. MATLAB
only adds a built-in control every few years (most recently the table/
grid control). Why can't they add something as basic, simple, and
useful as a progress bar. I know I can add third party ActiveX
controls but for crying out loud, MATLAB should add this fundamental
essential control that will most likely get heavily user by their
customer. Like I said, over half the file exchange searches are for
such a capability!!!

So I guess the answer to my question is "You can't - unless you use
third party AcrtiveX controls" so my question will probably turn into
a request for enhancement for a future version.

Regards,
ImageAnalyst

Gavrilo Bozovic

unread,
Dec 11, 2008, 11:05:18 AM12/11/08
to
ImageAnalyst <imagea...@mailinator.com> wrote in message <a6b98772-2bb0-4a16...@k19g2000yqg.googlegroups.com>...

A quick and dirty solution:

h=waitbar(x);
set(h,'windowstyle','modal');

this way, the waitbar should always remain on top of the GUI. It's better than making the GUI smaller than fullsize, but still not very elegant...

Doug Schwarz

unread,
Dec 11, 2008, 11:19:47 AM12/11/08
to
In article
<a6b98772-2bb0-4a16...@k19g2000yqg.googlegroups.com>,
ImageAnalyst <imagea...@mailinator.com> wrote:

> How can I put a progress bar onto my own custom GUI?

Come on, you could have written it in barely more time than it took you
to rant. Okay, sometimes it's feels good to rant. :-)

Anyway, I wrote this for you. Merry Christmas or <insert preferred
holiday here>!


function h = uiwaitbar(varargin)
%uiwaitbar: A waitbar that can be embedded in a GUI figure.
% Syntax:
% POSITION = [20 20 200 20]; % Position of uiwaitbar in pixels.
% H = uiwaitbar(POSITION);
% for i = 1:100
% uiwaitbar(H,i/100)
% end

% written by Doug Schwarz, 11 December 2008

if ishandle(varargin{1})
ax = varargin{1};
value = varargin{2};
p = get(ax,'Child');
x = get(p,'XData');
x(3:4) = value;
set(p,'XData',x)
return
end

pos = varargin{1};
bg_color = 'w';
fg_color = 'r';
h = axes('Units','pixels',...
'Position',pos,...
'XLim',[0 1],'YLim',[0 1],...
'XTick',[],'YTick',[],...
'Color',bg_color,...
'XColor',bg_color,'YColor',bg_color);
patch([0 0 0 0],[0 1 1 0],fg_color,...
'Parent',h,...
'EdgeColor','none',...
'EraseMode','none');

--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.

ImageAnalyst

unread,
Dec 11, 2008, 11:25:49 AM12/11/08
to
On Dec 11, 11:05 am, "Gavrilo Bozovic" <gavrilo.bozo...@helbling.ch>
wrote:
> ImageAnalyst <imageanal...@mailinator.com> wrote in message <a6b98772-2bb0-4a16-932a-918c1d1cf...@k19g2000yqg.googlegroups.com>...
> this way, the waitbar should always remain on top of the GUI. It's better than making the GUI smaller than fullsize, but still not very elegant...- Hide quoted text -
>
> - Show quoted text -

---------------------------------------------------------------
Gavrilo:
Thanks for the tip. I just tried it and it doesn't exactly work. It
does stay on top but there are tons of "bonks." It's weird, every
time I put a breakpoint in the code, I can continue and there are no
beeps/bonks but if I take the breakpoint out, there are tons of them.
I tried to track it down a bit and it seems like it has something to
do with calling the axes() command to set focus to different axes on
my GUI. Whenever I want to display an image or plot something I need
to call the axes() function to make sure it happens in the desired
axes. I even tried calling figure(handles.figMainWindow) to set focus
to my main GUI (instead of the waitbar) before I called the axes
command but that didn't work. I still get lots of annoying bonk
sounds.
- ImageAnalyst

Darik

unread,
Dec 11, 2008, 12:25:04 PM12/11/08
to
> How can I put a progress bar onto my own custom GUI?
> [...]
> Regards,
> ImageAnalyst

Check out Yair Altman's statusbar on the fex. It's got a progress bar.

ImageAnalyst

unread,
Dec 11, 2008, 1:17:05 PM12/11/08
to
On Dec 11, 11:19 am, Doug Schwarz <s...@sig.for.address.edu> wrote:
> In article
> <a6b98772-2bb0-4a16-932a-918c1d1cf...@k19g2000yqg.googlegroups.com>,

--------------------------------------------------
Thanks Doug. Works like a charm. One additional note, to get rid of
the waitbar, delete the handle:
% Get rid of the waitbar.
delete(hWaitBar);
I originally tried to set the visibility to "off" but that didn't
work. So I tried deleting the handle and that works.

It was a little bit of work to get it positioned correctly - not as
easy as just dragging it out in GUIDE - but I did get it where I
wanted by first placing a scroll bar on the figure, changing the units
property from characters to pixels (even though my figure was
normalized), noting the "position" property of the scroll bar, and
copying that to your POSITION variable.

I wasn't familiar with the "patch()" command, so I guess sometimes
ranting does get good results - much faster than waiting for the new
GUIDE, which they've been working on for quite a while with no
announced ETA (hopefully it will be a major improvement over these
tiny little interim improvements they've been making with the MATLAB
releases).

Thanks again,
ImageAnalyst
P.S. It would still be nice if such a control were built into GUIDE.

ImageAnalyst

unread,
Dec 11, 2008, 1:28:32 PM12/11/08
to
> P.S. It would still be nice if such a control were built into GUIDE.- Hide quoted text -

>
> - Show quoted text -

---------------------------------------
An additional note: because my main GUI had units of "normalized" so
that everything would scale properly if the user maximized the window,
the waitbar no longer was in the correct place if they did that
(because the units were pixels). I tried changing the units of the
axes to "normalized" after they it was created but it still left the
waitbar in the wrong place after maximizing. So I changed the units
to normalized when it was created with the axes command, and again
found the position by placing a "normalized-units" scrollbar in the
location that I wanted the waitbar, and then everything was fine. It
was in the right place when the window first came up and in the right
place after the GUi was maximized.
Thanks!

Glenn

unread,
Apr 17, 2009, 4:31:01 PM4/17/09
to
FYI, a progress bar can be implemented.
Use a Slider Control with the Enable property set to Inactive. This prevents the slider from being moved by the user.
Change the Value property of the control from inside your coding to indicate progress.
The slider changes position according to the Value property.
The Value property must be between the Min and Max properties of the Slider Control but these can also be changed if necessary.
For progress labels (such as % complete) use a Static Text button just above the slider with text spaced appropriately so as to span the range of movement of the slider.

Doug Schwarz

unread,
Apr 17, 2009, 9:18:11 PM4/17/09
to

> How can I put a progress bar onto my own custom GUI?
>

[snip]


I have one that I've been working in my spare time that eventually will
go up on the FEX. It's not done, but give me a couple of days to at
least make sure it's working and I'd be glad to send it to you. It's a
class using the new class syntax so you have to be using at least R2008a
to run it. I have tried to make it as much like a uicontrol as I can.

Use it like this:

h = uiwaitbar('Position',[20 100 200 16]);


for i = 1:100

set(h,'Value',i/100)
end

Send me an email to confirm your email address.

ImageAnalyst

unread,
Apr 17, 2009, 9:32:29 PM4/17/09
to
On Apr 17, 9:18 pm, Doug Schwarz <s...@sig.for.address.edu> wrote:
> In article
> <a6b98772-2bb0-4a16-932a-918c1d1cf...@k19g2000yqg.googlegroups.com>,
>
>  ImageAnalyst <imageanal...@mailinator.com> wrote:
> > How can I put a progress bar onto my own custom  GUI?
>
> [snip]
>
> I have one that I've been working in my spare time that eventually will
> go up on the FEX.  It's not done, but give me a couple of days to at
> least make sure it's working and I'd be glad to send it to you.  It's a
> class using the new class syntax so you have to be using at least R2008a
> to run it.  I have tried to make it as much like a uicontrol as I can.
>
> Use it like this:
>
>   h = uiwaitbar('Position',[20 100 200 16]);
>   for i = 1:100
>     set(h,'Value',i/100)
>   end
>
> Send me an email to confirm your email address.
>
> --
> Doug Schwarz
> dmschwarz&ieee,org
> Make obvious changes to get real email address.

-----------------------------------------------------------------------------------
Doug:
I've been using the code you posted earlier in this thread. It works
nicer than any I saw on the FEX so far. It's great that you're
working on converting it from a snippet into a full-fledged class.
Let me know (here) when it's done and I'll download it.

Does the "Position" arg depend on whether the units property of the
main figure are "normalized," "pixels," etc.?
Thanks,
ImageAnalyst

ImageAnalyst

unread,
Apr 17, 2009, 9:35:20 PM4/17/09
to
On Apr 17, 4:31 pm, "Glenn " <JAG...@hotmail.com> wrote:
> FYI, a progress bar can be implemented.
> Use a Slider Control with the Enable property set to Inactive.
[snip]
------------------------------------------------------------------
Glenn:
Yes that's true, but Doug's solution is a much nicer looking solution,
so I'll continue to use that. By the way, I haven't yet downloaded
R2009a - does that have a built-in progress bar?
Thanks,
ImageAnalyst

Doug Schwarz

unread,
Apr 18, 2009, 1:49:57 AM4/18/09
to
In article
<36d79543-ad5c-4de8...@r37g2000yqn.googlegroups.com>,
ImageAnalyst <imagea...@mailinator.com> wrote:

Oh yeah, I'd forgotten that you were the one that got me started on this
in the first place -- that was a while ago. I guess I don't have as
much spare time as I'd like!

Anyway, this new thing will work very much like a uicontrol. If you
don't want the default units (and that's inherited from whatever you've
set to be the default units for uicontrols) then you can just set it
before setting the Position. So, no, the units of the figure (or
uipanel since that can be the Parent, also) don't matter.

Glenn

unread,
Apr 24, 2009, 3:08:01 PM4/24/09
to
ImageAnalyst <imagea...@mailinator.com> wrote in message <2068a6ca-3a45-4564...@k8g2000yqn.googlegroups.com>...

No it does not.

Travis

unread,
May 26, 2009, 7:32:03 PM5/26/09
to
"Glenn " <JAG...@hotmail.com> wrote in message <gsaou5$l8l$1...@fred.mathworks.com>...

> FYI, a progress bar can be implemented.
> Use a Slider Control with the Enable property set to Inactive. This prevents the slider from being moved by the user.
> Change the Value property of the control from inside your coding to indicate progress.
> The slider changes position according to the Value property.
> The Value property must be between the Min and Max properties of the Slider Control but these can also be changed if necessary.
> For progress labels (such as % complete) use a Static Text button just above the slider with text spaced appropriately so as to span the range of movement of the slider.
>

OK, I have a "Process" button on my GUI that runs code. How do i modify something on the GUI from within the other code? I know exactly how I would like to set it, I just don't know how.

Sue

unread,
Jul 15, 2011, 6:10:12 AM7/15/11
to
This seems to be a good progress bar by reading all the comments here but I am new to MATLAB gui's and GUIDE and would like to ask - where abouts would I include this code to make a progress bar appear once a pushbutton has been pressed by the user.

To make things clearer, I am using GUIDE and have a pushbutton which activates an underlying m-file which takes 5-7 mins to run. Instead of the user sitting there wondering whether anything is happening, I wish to put a progress bar on the screen (again not opening up in a separate window) as an indication that yes something is happening albeit in the background.

So my main question is - whereabout would I put this piece of code? And please don't forget, try and explain it clearly and carefully - I really am like a 5 year old trying to learn to read all over again!!

Many thanks, Sue

0 new messages