I have a little timer widget that times two separate tasks:
It is simple enough, but I can't see why it's not working. Am I not understanding the connection between ScheduleTasks and Dynamics?
Here is the code:
With[{maxLearning = 60, maxWriting = 60},
DynamicModule[{learning = maxLearning, writing = maxWriting, lt, wt},
lt = CreateScheduledTask[learning--];
wt = CreateScheduledTask[writing--];
Grid[{{ToTitleCase@StringTake[ToString@HoldForm[learning], ;; -7],
ProgressIndicator[Dynamic[learning], {0, maxLearning}],
startStop[StartScheduledTask[lt], StopScheduledTask[lt]],
Dynamic[learning, UpdateInterval -> 1]},
{ToTitleCase@StringTake[ToString@HoldForm[writing], ;; -7],
ProgressIndicator[Dynamic[writing], {0, maxWriting}],
startStop[StartScheduledTask[wt], StopScheduledTask[wt]],
Dynamic[writing, UpdateInterval -> 1]}},
Alignment -> {Left, Center}]
]
]
and you need this function:
SetAttributes[startStop,HoldAllComplete];
startStop[startAction_,stopAction_]:=Row[{Button["\!\(\*
StyleBox[AdjustmentBox[\"\[RightPointer]\",\nBoxBaselineShift->0.12313612313612314`,\nBoxMargins->{{0., 0.}, {-0.12313612313612314`, 0.12313612313612314`}}],\nFontSize->24]\)",startAction,Appearance->"Frameless",ImageSize->{30,30},Alignment->Center],Button["\!\(\*AdjustmentBox[\(\[FilledSquare]\),\nBoxBaselineShift->-0.1704961704961705,\nBoxMargins->{{0., 0.}, {0.1704961704961705, -0.1704961704961705}}]\)",stopAction,Appearance->"Frameless",ImageSize->{30,30},Alignment->Center]}," ",BaselinePosition->Center]