2010-07-23

Mathematica Initialization cell

I have been trying to develop little Mathematica applications.  A misconception I have had is that an initialization cell  will run when you open the notebook.  However I don’t think it runs until you either execute another cell when you are then asked to run all initialization cells or Evaluate Initialization Cells from a menu.  However with Player Pro I don’t think it is posible to start an application without clicking once.

Dynamic cells I don’t think help as you still get a “Dynamic Content Warning” dialog box which is offputting to naive users.

I am looking to do a double bootstrap deployment, the first bootstrap gives you a very simple loader notebook which you can deploy on Mathematica Player Pro.  You open it eg from File Explorer click the button and you have your application ready to go.  This is a very simple application.

image

Then you can add other options eg deploying your files to where you need them etc.  I plan to cover later a more complicated example with code in modules and a good user interface using tabbed windows.  Then you need to compress the packages which can all be done with Mathematica. (The first time I did this I made the mistake of unbundling the definitions of report and myProgram so that they didn’t work in the loader.  When I clicked the button on the loader they hadn’t been defined so nothing happened.*)

To save anybody the effort of typing I have the text of the above here s:

myLoader = Notebook[{
    Cell[Button["My Loader",
      NotebookPut[Notebook[{Cell["BootStrap Application"]}]]], "Text"],
    Cell[BoxData[ButtonBox["\<\"Run the Program\"\>",
       Appearance -> Automatic, ButtonFunction :>
        ((*These definitions need to be executed by the click of the \
button to make them available later*)
         report = Notebook[{Cell["Simplest report", "Text"]}];
         myProgram = Notebook[{
            Cell[Button["My Program",
              NotebookPut[Notebook[{Cell["BootStrap Application"]}]]],
              "Text"],
            Cell[BoxData[ButtonBox["\<\"Run the Report\"\>",
               Appearance -> Automatic, ButtonFunction :>
                (
                 NotebookPut[report]
                 ), Evaluator -> Automatic, Method -> "Preemptive"]],
             "Output"]
            }];
         NotebookPut[myProgram];
         NotebookClose[] (*Loader's job is done and it closes to
         prevent any errors corrupting it*)
         ), Evaluator -> Automatic, Method -> "Preemptive"]], "Output"]
    }];

Button["Create Loader",
nb = NotebookPut[myLoader];
NotebookSave[nb, NotebookDirectory[] <> "Loader.nb"]
]

No comments: