Timing out while waiting for Manipulate code to load
- To: mathgroup at smc.vnet.net
- Subject: [mg89975] Timing out while waiting for Manipulate code to load
- From: "David Park" <djmpark at comcast.net>
- Date: Wed, 25 Jun 2008 06:30:12 -0400 (EDT)
Here is a definition for a generic button that will evaluate a command and color the button that was last used. ClearAll[StepButton]; Attributes[StepButton] = {HoldFirst}; StepButton[stepvalue_, steplabel_, stepnumber_] := Function[{step, stepnum}, Button[steplabel, step = stepvalue; stepnum = stepnumber, Background -> If[stepnum == stepnumber, ColorData["Legacy"]["Gold"], White], BaseStyle -> {FontSize -> 14}, Method -> "Queued"], {HoldAll} ] Here are three expressions that we will use the buttons to evaluate. Two of them are Manipulate statements and they are at the center of the problem. Note that the Manipulate statements end with a semi-colon so they are not actually displayed. step0 = "Hi There! Now push the step1 button."; step1 = Manipulate[x, "Step1", {x, 0, 1}]; step2 = Manipulate[y, "Step2", {y, 1, 2}]; Here is the expression that creates the display of the three buttons. By pushing the buttons you will be able to switch amoung the various displays. Module[ {step = step0, stepnum = 0}, Column[{ Panel[ Dynamic@Grid[ {{StepButton[step0, "step0", 0][step, stepnum], StepButton[step1, "step1", 1][step, stepnum], StepButton[step2, "step2", 2][step, stepnum]}}](* Grid *), Style["Demonstrating of Timing Problem", 16], BaseStyle -> {FontSize -> 14, PanelBoxOptions -> {Background -> LightBlue}}](* Structure Panel *), Dynamic[step] }](* Column *) ] Now, in a fresh Mathematica session (if you have used Manipulate it is not sufficient to just kill the kernel), paste these three pieces of code in a notebook and evaluate in order. Step0 will be displayed and the button will be highlighted. Now push the step1 button, which must evaluate a Manipulate statement. After a wait, about 15-20 seconds on my machine, the evaluation will be aborted. You will not obtain the Manipulate display. But if you then push any of the other buttons everything will be all right, and when you go back to the step1 button, it will now also work. Furthermore, if you kill the kernel and reevaluate the problem will not occur again. Even if you kill the kernel and close the notebook and then paste the code into a new notebook, everything will work. I think the initial Abort may occur because of the time for the Manipulate code to load. That is why I used the Method -> "Queued" option in the Button statement. That did not solve the problem and I think that may be because it only affects kernel functions and this is a front end function. Well, I'm not very certain of the reason so perhaps someone can enlighten me. If the semi-colon is removed from the step1 or step2 definition, so that the Manipulate box is actually displayed, then the problem does not occur. But in my application these are actually quite large displays and I don't want to display them twice. What I am actually doing now is using a small dummy Manipulate statement that displays and this is done in a subsection that a viewer might not actually look at. Is there a more elegant way to solve this problem? Is there a way to get the frontend Manipulate code loaded without actually displaying something? Or is there a way to get the Button not to Abort while waiting for the Manipulate code to load? -- David Park djmpark at comcast.net http://home.comcast.net/~djmpark/