# Removing a ProgessIndicator when no longer needed

I have a progress indicator in my Mathematica notebook that I update as various calculations are performed:

indicator = ProgressIndicator[Dynamic[progress]];


I would like to figure out how to remove the indicator when the calculations are complete or in the case above when

progress == 1


I’ve looked through the documentation and can’t seem to find a good way to do this.

-
Does the second example in the Basic Examples section of Monitor in the docs look useful? – kglr Apr 17 '14 at 2:09
Good to know about Monitor but that didn’t help... – Pam Apr 17 '14 at 15:41

Let's just not draw it if the progress goal is achieved:

Dynamic[
x = Clock[3];
If[x < 1,
ProgressIndicator[x],
Sequence[]
]
]


Sequence can be "" or whatever is appropriate in your application.

-
All the answers are good… I didn’t explain my situation fully. Hence I will chose the first answer. – Pam Apr 17 '14 at 15:42

It is quite unclear where that element is, so maybe this approach will fit you needs:

progress := Clock[1, 1, 1];

nb = CreatePalette[DynamicWrapper[
ProgressIndicator@Dynamic@progress,
If[progress == 1, NotebookClose@nb], UpdateInterval -> 1]
]

-

Here's an inelegant way of getting rid of progress indicators at the end of a calculation, while leaving other results alone:

nb = EvaluationNotebook[]; (*The current notebook object.*)
SelectionMove[nb, Previous, GeneratedCell]; (*Select ALL cells just generated ...*)
sc = SelectedCells[]; (*... and get them.*)
MapIndexed[ (*Map over them, and...*)
(nr = ToString[NotebookRead[#1]]; (*... get a String version.*)
If[Not[StringFreeQ[nr, "ProgressIndicator"]],(*Does it have "ProgressIndicator"?*)
NotebookDelete[sc[[#2[[1]]]]] (*If so, delete the cell.*)
]
)&, sc];

SelectionMove[nb, After, Cell]; (*Finally, put the selection back where it belongs.*)


Better late than never! I hope this helps. Obviously, the code could also be invoked from 'progress' with an 'If' statement.

-

Let's try such code:

trig = True;

pi = Dynamic[If[trig, ProgressIndicator[0.5], ""]];

pi


If trig is True, then ProgressIndicator is visible, otherwise it is not..

Playing with value of trig you can dynamically change the state of any visible elements.

-