A palette with graphics in the buttons

P. J. Hinton of Wolfram Research provided the amazing solution below to the Math Group which makes a palette with graphics in the buttons.  First we define a list of graphics objects that will appear in the buttons.

grList = {Plot[Sin[x], {x, 0, 2π}, DisplayFunctionIdentity], Plot3D[Sin[x] Cos [y], {x, 0, 2π}, {y, 0, 2π}, DisplayFunctionIdentity] } ;

Next convert the graphics objects to Mathematica  PostScript strings.

psStringList = Map[DisplayString, grList] ;

Now create a list of cells containing the graphics at 100 x 100 pixels.

cellExprList = Map[Cell[GraphicsData["PostScript", #], ImageSize {100, 100}] &, psStringList] ;

The next line generates the needed ButtonBoxes. Here the buttons paste copies of the images so the front end automatically determines the size of the pasted image.

btnBoxList = Map[ButtonBox[#, ButtonFunction (NotebookWrite[In ... utomatic)]) , ButtonEvaluatorAutomatic, ActiveTrue] &, cellExprList] ;

Finally a cell with buttons containing the graphics in a RowBox strcuture is created.  Pressing one of the buttons pastes a copy of the graphic in the notebook.

CellPrint[Cell[BoxData[RowBox[btnBoxList]]]]


Created by Mathematica  (May 16, 2004)

Back to Ted’s Tricks index page