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

How to make a progress bar?

116 views
Skip to first unread message

Andrey B.

unread,
Sep 28, 2006, 7:12:35 AM9/28/06
to
Hello,
Does anybody know how to force Mathematica to put symbols in one
continuous line by repeatedly call the operator (say Print[]). If we
call Print["a"] twice - we get two lines, and I want one line "a,a"

It is common question when I do something like

Do[
MyFunction; (*Complicated and Very long*)
Print["."] (*printed dot makes me know that an iteration has done*)
,{imax}]

I get many lines with dot and I want ONE progress bar line growing,
like
.........

but not
.
.
.

Is there any chance?

Thanks,
Andrey B.

David Annetts

unread,
Sep 30, 2006, 5:23:16 AM9/30/06
to
Hi Andrey,

> Does anybody know how to force Mathematica to put symbols in one
> continuous line by repeatedly call the operator (say Print[]). If we
> call Print["a"] twice - we get two lines, and I want one line "a,a"
> It is common question when I do something like
>
> Do[
> MyFunction; (*Complicated and Very long*) Print["."] (*printed dot
> makes me know that an iteration has done*) ,{imax}]
>
> I get many lines with dot and I want ONE progress bar line growing,
> like .........

Print[] puts its output on a separate line so the only way this will work
through a loop, is to print your line with increasing numbers of dots.

(
Print[StringJoin["." & /@ Range[#]]]
) & /@ Range[10];

Perhaps a better way might make use of the status bar. There's a detailed
post by Paul Abbot from a few years ago
(http://forums.wolfram.com/mathgroup/archive/1999/Feb/msg00351.html), and
another by Jens-Peer Kuska
(http://forums.wolfram.com/mathgroup/archive/2000/Nov/msg00056.html) that
will help.

Regards,

Dave

dimm...@yahoo.com

unread,
Sep 30, 2006, 5:29:21 AM9/30/06
to
With Print I fail to put in one line "a,a,..." how you want.
I am sure someone else will be more helpful.
Anyway executing the following command you get something similar
to what you want

TableForm[Table[a, {10}], TableDirections -> Row]


Ο/Η Andrey B. έγραψε:

albert

unread,
Sep 30, 2006, 5:39:28 AM9/30/06
to
Hi,

It is possible, but not straightforward. The following assumes you are using
the notebook frontend, not the pure kernel.

What would come closest to what you have in mind is to use CellPrint to
write a cell that is marked with a special CellTag. When you want to add a
point, you could use frontend programming to delete the old cell and write
a new cell with one point added. If you think that sounds complicated for a
simple task, I fully agree. The approach is something I would recommend
only if e.g. you want to show the progress in some kind of plot or more
complicated information which needs complex formatting.

If I have to give simple status like information I prefer to write it to the
statusline of the frontend, which after all is what the status line is for.
If you search the archives for WriteStatus you will find postings with
explicit code which does this.

Last but not least you could look into the GUIKit documentation which comes
with versions > 5.0 and contains examples of how to create a real status
bar window.

hth,

albert

Ingolf Dahl

unread,
Sep 30, 2006, 5:43:31 AM9/30/06
to
Hi Andrey,
another good opportunity to advertise my packages... (freeware!)
Go to http://web.telia.com/~u31815170/Mathematica/ and download the
TaggedCells package. Install according to instructions. Open the Help
Browser.
Look beneath Add-ons and Links, TaggedCells, IntroductionTaggedCells,
Overview.
There a ProgressBar function defined, somewhat more fancy than that you are
asking for. If you want to have it exactly in your style, you might use the
AppendToTaggedCell command in the same package. Instead of Print["."] you
just substitute AppendToTaggedCell[".", "Progress bar"]; , where "Progress
bar" the CellTag setting off the cell you want to write to. (Such a cell
will be created the first time you use the command, if it is not there
already.)
Alternatively you might use ExpressionToTaggedCell[i, "Output", "progress"];
if your iteration index is i.
The package is still "beta", but these things definitely works.

Best regards

Ingolf Dahl


> -----Original Message-----
> From: Andrey B. [mailto:be...@gorodok.net]
> Subject: How to make a progress bar?
>
> Hello,

David Reiss

unread,
Oct 1, 2006, 4:27:00 AM10/1/06
to

The trick is to use Notebook Programming. Generally functions like
Print, and Return are in Mathematica for the sake of those coming from
other languages, but they are quit restrictive and you can't get very
far with them..

But the real powerful thing is to remember that Cells and Notebooks are
expressions that you can manipulate just as any other expression in
Mathematica.

So with this in mind here is a refined example that might get you
started along the path you want to go. First do something like this.

In one input Cell execute the following to create a cell with a
specific cell tag:


CellPrint[Cell[" ","Text",CellTags->"progress"]]


Now, in another cell in the same notebook, execute the following which
finds and then writes into the end of the text in the cell that was
created by executing the previous input line


Do[

Module[{nb},
nb=EvaluationNotebook[ ];

NotebookFind[EvaluationNotebook[ ],"progress",All,CellTags,
AutoScroll\[Rule]False];

SelectionMove[nb,After,CellContents,AutoScroll\[Rule]False];
NotebookWrite[nb, "x"];
Pause[1]
],

{i,1,15}]

Take a look at http://scientificarts.com/worklife for the sorts of
things you can do with notebook programming and a bunch of tools that
make some of it more accessible. (Shameless plug for a useful product!)

0 new messages