I am trying to create a dialog with a timed delay: a user would not be able to interact with the dialog until a specified amount of time has passed.
Below is a series of examples that "almost" work.
This is my working prototype for constructng the behavior that I want:
count = 5;
button = Button[
Dynamic[Refresh[If[count-- <= 0, "press me now", count],
TrackedSymbols -> {}, UpdateInterval -> 1]], Print["foo"],
Appearance -> Dynamic[If[count <= 0, "Palette", "None"]],
Enabled -> Dynamic[count <= 0]]
This example works, but notice that the UpdateInterval is slower than specified. I don't understand why it is slow.
signPost1[comment_] := DynamicModule[
{
thisNB = EvaluationNotebook[],
button,
count = 2
},
button =
Button[Dynamic[
Refresh[If[count-- <= 0, "press me", count],
TrackedSymbols -> {}, UpdateInterval -> 1]],
DialogReturn[NotebookWrite[thisNB, ToBoxes@TextCell["ok"]]],
Appearance -> Dynamic@If[count <= 0, "Palette", "None"],
Enabled -> Dynamic@(count <= 0)];
DialogInput[Notebook[
{Cell[comment, "Section"],
Cell[BoxData[ToBoxes[Dynamic@button]], "Input"]}]];
]
signPost1["random comment"];
Here is another example in which I don't use dynamic for the timer, but use a RunScheduledTask. It is also slower than the argument to RunScheduledTask is specified:
signPost2[comment_] := DynamicModule[
{
thisNB = EvaluationNotebook[],
button,
count = 2
},
RunScheduledTask[count--, {.5}];
button =
Button[Dynamic[
Refresh[If[count-- <= 0, "press me", count],
TrackedSymbols -> {}, UpdateInterval -> 1]],
DialogReturn[NotebookWrite[thisNB, ToBoxes@TextCell["ok"]]],
Appearance -> Dynamic@If[count <= 0, "Palette", "None"],
Enabled -> Dynamic@(count <= 0)];
DialogInput[Notebook[
{Cell[comment, "Section"],
Cell[BoxData[ToBoxes[Dynamic@button]], "Input"]}]];
RemoveScheduledTask[ScheduledTasks[]];
]
signPost2["random comment"];
I am hoping someone might see why the timer in the dialog doesn't have the behavior that I am looking for, or can suggest a much cleaner way to do the same thing,