2010-03-23

Mathematica Player Pro deployment process

Starting with a working notebook and assuming that you are working in workbench.  The aim is then to first convert this into very simple notebook with all the gui code in a gui package.  Then to combine all these elements into an installable exe file using InnoSetup for deployment on a machine with PlayerPro installed or just copy them across to your destination.

1) Convert the Gui cells to initialisation cells.  This then saves the code to .m package.

2) Supposing you want to keep the template separate then Rename the saved notebook to something else eg _template.  Rename the saved .m file as smethingGUI.m and the template.

3)Edit somethingGUI.m into a package file with a single function runGUI[]. 

a) Whereas before you might have explicit dependencies in the code eg Needs{moduleX`]  this can now be moved into the begin package dependency list:

BeginPackage["somethng`",  {"moduleX`"}]

b) Any references to global variables will now need to be prefixed with Global` now that they are embedded in a private part of the package.

4) Create a new notebook with the single cell and interface

If[Fold[Or, False,
   StringMatchQ[$Path, ___ ~~ "MathematicaPlayerPro" ~~ ___]],
  Needs[# <> "`", NotebookDirectory[] <> # <> ".mx"] &,
  Needs[# <> "`"] &] /@ {"moduleX”, 
  "somethingGUI"}; somethingGUI`runGUI[]

5) Open this notebook with the Mathematica front end  and run it.  It should work, eg display front end and then allow you to interact with the front end.

6) Edit the Gui code for the button and modify  like this

Dynamic@Button[Style["Run report",FontFamily->"Helvetica"],
      (

If[Fold[Or, False,
   StringMatchQ[$Path, ___ ~~ "MathematicaPlayerPro" ~~ ___]],
  Needs[# <> "`", NotebookDirectory[] <> # <> ".mx"] &,
  Needs[# <> "`"] &] /@ {"moduleX”, 
  "somethingGUI"};

        something`createReport[thisDate];
      ),Enabled->fileExists
    ]

(The fileExists is a dynamic variable that depends on a file test depdning on what the user puts in.  If the file doesn’t exsit the buton is not enabled) (This is a bit of kludge but seems to work.  When you save a result it sees to save partial but not all linked files so then using a Needs in the button procedure loads the path but not quite quickly enough so you need to use complete references.  you need to open the file in the front end and execute the code then make code option not open and then save the notebook.  You now get a blank notebook that opens and you can press buttons. on it.

7)  Build a build and deploy module that actually compresses the files and then deploys them to the test machine.

8) When it runs I still have the run dynamic content and run the initialistation bxes to click. but then it does start up

The next stage is to put this all together as a set of sample files.

No comments: