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
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...
> 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.
---------------------------------------------------------------
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
Check out Yair Altman's statusbar on the fex. It's got a progress bar.
--------------------------------------------------
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.
---------------------------------------
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!
ImageAnalyst <imagea...@mailinator.com> wrote in message <a6b98772-2bb0-4a16...@k19g2000yqg.googlegroups.com>...
> 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:
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
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.
No it does not.
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.
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