Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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];
like image 220
pAkY88 Avatar asked Dec 09 '10 12:12

pAkY88


2 Answers

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]]]]
like image 122
ragfield Avatar answered Nov 20 '22 09:11

ragfield


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

like image 29
Dr. belisarius Avatar answered Nov 20 '22 09:11

Dr. belisarius