MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Initialization cell and button

  • To: mathgroup at
  • Subject: [mg70107] Re: Initialization cell and button
  • From: Markus Huber <mhla at>
  • Date: Wed, 4 Oct 2006 05:58:44 -0400 (EDT)
  • References: <eftdnh$6co$>

Thank you, the version with the InterpretationBox will work fine for me.


Ingolf Dahl wrote:
> Markus,
> You must remember that the FrontEnd is almost, but not exactly, as smart as
> the bomb in the computer game "Starship Titanic" by Douglas Adams... When
> the "EvaluateInitialization" command is executed, the initialization cells
> are not inserted into the program flow and evaluated immediately; they just
> are put onto the evaluation stack, to be evaluated after the button function
> as such. You thus must put the print command even later on the evaluation
> stack to obtain the desired functionality. The easiest way is of course to
> include a print command as the last initialization cell, but that solution
> is probably too simple for your purposes (?). Another solution is to hide a
> print command inside the button cell. Execute the following command to
> obtain such a button:
> NotebookWrite[InputNotebook[], Cell[BoxData[InterpretationBox[ButtonBox["a",
> ButtonFunction:>
> FrontEndExecute[CompoundExpression[FrontEndToken["EvaluateInitialization"],
> SelectionMove[ButtonNotebook[],All,ButtonCell],
> FrontEndToken["EvaluateCells"]]], ButtonEvaluator->None, Active->True,
> ButtonFrame->"DialogBox"], Print@a]],"Input"]]
> (You have to modify the button if you want to generate a palette from it.) 
> Another approach to put commands onto the evaluation stack is to let the
> ButtonFunction create a scrap notebook, write the commands there together
> with a command that closes the same scrap notebook, and then use
> SelectionEvaluate to evaluate these commands. But in this case we then would
> have to redirect the output of Print to be able to see anything.
> Best regards
> Ingolf Dahl
>> -----Original Message-----
>> From: Markus Huber [mailto:mhla at] 
To: mathgroup at
>> Subject: [mg70107]  Initialization cell and button
>> I've got the following simplified problem with a button:
>> Create an initialization cell which contains a=1;
>> Create a button with
>> Button["a", Active -> True,
>>      ButtonFunction :> (FrontEndExecute[
>>            FrontEndToken["EvaluateInitialization"]];
>>          Print@a), ButtonEvaluator -> Automatic] // DisplayForm
>> but say no, if Mathematica asks if to evaluate the 
>> initialization cells in the NB.
>> Now press the button .
>> In my opinion the result should be the printout of 1. Instead 
>> M prints a. If you press the button again it prints correctly 1.
>> Why is M not aware of the value of a when evaluating the 
>> Print function although the initialization cells should have 
>> been evaluated already?
>> Regards,
>> Markus Huber

  • Prev by Date: undocumented
  • Next by Date: On "Equilibrium points for..."
  • Previous by thread: RE: Initialization cell and button
  • Next by thread: Re: equation question