Manipulate[
Module[{result}, abort = False; track = 0;
result = solve[n];
track = 0;
If[abort, "Aborted", "success!"]],
Grid[{{Control[{{n, 10, "size of problem?"}, 1, 1000, 1, Appearance -> "Labeled"}]},
{Button["Abort", abort = True,ImageSize -> {40, 30}]},
{Dynamic[BulletGauge[track, 1, Range[0, 1]]]} (*more options in help*)
}
],
{{track, 0}, None},
{{abort, False}, None},
TrackedSymbols :> {n},
SynchronousUpdating -> False,
ContinuousAction -> False, Initialization :> (
solve[n_] := Module[{k = 0, result = 1, i},
Do[PrimeQ[i];
Pause[0.1];
k = k + 1;
track = k/n;
If[abort, result = -1; Break[]], {i, n}];
result])
]
bug fix in the code. The author forgot the initial Manipulate[ in the second example.
Gustavo Delfino
- 8.7k
- 1
- 29
- 60