pAkY88
pAkY88

Reputation: 6294

Update a progress bar in mathematica

during the computation I would update the value of progress bar to notify to the user the progress of the computation.

Unfortunately I'm not able to do this because when I call SetPropertyValue function

ref@SetPropertyValue[{"bar", "value"}, 70];

the value isn't updated.

I obtain ref in this way

ref = GUIRun[mainWindow];

Upvotes: 6

Views: 3391

Answers (3)

Dr. belisarius
Dr. belisarius

Reputation: 61026

This is just an extension to @ragfield's answer.

If you want to represent bounded and unbounded magnitudes, you colud do something along these lines:

Clear["Global`*"];
count = 0; inRange = 0; i = 0; sumTgt = 10^5
Monitor[
  While[count < sumTgt,
   If[.14 < (rand = RandomReal[]) < .15, inRange++];
   count += rand;
  ]
  , {{"SumTillNow", ProgressIndicator[count,   {0, sumTgt}  ],count},
     {"InRange",    ProgressIndicator[inRange, Indeterminate],inRange}} 
   // MatrixForm
];

If you want to save the progress indicators as an animated gif for presententations and the such, you could modify it a bit:

count = 0; inRange = 0; i = 0; sumTgt = 10^4
Monitor[
  While[count < sumTgt,
   If[.14 < (rand = RandomReal[]) < .15, inRange++];
   count += rand;
  ]
  , a[++i] = Grid[
                 {{"SumTillNow", ProgressIndicator[count, {0, sumTgt}],count},       
                  {"InRange", ProgressIndicator[inRange, Indeterminate],inRange + 0.}},
              Frame -> All, Alignment -> {{Left, Center, Right}}, 
              ItemSize -> {{Automatic, Automatic, 8}}];
];
Export["c:\Anim.gif", Table[a[j]//MatrixForm, {j, i}],"DisplayDurations"->{.3}]  

and the result is:

alt text

Upvotes: 6

ragfield
ragfield

Reputation: 2506

With Mathematica 6 or later try using Monitor and ProgressIndicator instead of the older GUIKit package:

With[{count = 1000}, 
 Monitor[Do[Pause[0.01];, {i, count}], 
  ProgressIndicator[Dynamic[i/count]]]]

Upvotes: 9

High Performance Mark
High Performance Mark

Reputation: 78316

Did you remember to execute

Needs["GUIKit`"];

before starting to use the GUIKit ? If not your commands won't execute, because they are not known. If you load the GUIKit after you start using it, don't forget that some of its symbols may be shadowed by the symbols you have inadvertently defined.

Upvotes: 1

Related Questions