(*********************************************************************** Mathematica-Compatible Notebook This notebook can be used on any computer system with Mathematica 3.0, MathReader 3.0, or any compatible application. The data for the notebook starts with the line of stars above. To get the notebook into a Mathematica-compatible application, do one of the following: * Save the data starting with the line of stars above into a file with a name ending in .nb, then open the file inside the application; * Copy the data starting with the line of stars above to the clipboard, then use the Paste menu command inside the application. Data for notebooks contains only printable 7-bit ASCII and can be sent directly in email or through ftp in text mode. Newlines can be CR, LF or CRLF (Unix, Macintosh or MS-DOS style). NOTE: If you modify the data for this notebook not in a Mathematica- compatible application, you must delete the line below containing the word CacheID, otherwise Mathematica-compatible applications may try to use invalid cache data. For more information on notebooks and Mathematica-compatible applications, contact Wolfram Research: web: http://www.wolfram.com email: info@wolfram.com phone: +1-217-398-0700 (U.S.) Notebook reader applications are available free of charge from Wolfram Research. ***********************************************************************) (*CacheID: 232*) (*NotebookFileLineBreakTest NotebookFileLineBreakTest*) (*NotebookOptionsPosition[ 40491, 1062]*) (*NotebookOutlinePosition[ 41453, 1092]*) (* CellTagsIndexPosition[ 41409, 1088]*) (*WindowFrame->Normal*) Notebook[{ Cell["Button Box HOW-TO: Making a Graphics Generator", "Title"], Cell[TextData[{ "P.J. Hinton\n", StyleBox["Mathematica", FontSlant->"Italic"], " Programming Group\nWolfram Research, Inc." }], "Subsubtitle"], Cell["Last Revised: April 25, 1998", "Subsubtitle"], Cell[CellGroupData[{ Cell["Introduction", "Section"], Cell[TextData[{ StyleBox["Mathematica", FontSlant->"Italic"], " 3.0 introduced the use of ", StyleBox["ButtonBox", "InlineInput"], "es that allow users to create point-and-click interactive elements in \ notebooks. Perhaps the most noticeable example of buttons is in palettes. \ Palettes are simply ", StyleBox["Mathematica", FontSlant->"Italic"], " notebooks that contain a grid of buttons, each of which perform a pasting \ action." }], "Text"], Cell[TextData[{ StyleBox["The Mathematica Book", FontSlant->"Italic"], " describes the low level structures that are used to define and adjust \ buttons, but there still is a lack of step-by-step walkthroughs on how to \ create a button that does more than just pasting, evaluating, or \ hyperlinking. This notebook attempts to help users to learn some of the \ important points to keep in mind when making custom buttons. These \ techniques are suitable for situations where the front end's button creation \ dialogs are too awkward of an interface." }], "Text"] }, Open ]], Cell[CellGroupData[{ Cell["The Problem", "Section"], Cell[TextData[{ "Suppose we wanted to create a button that has generates a plot in a \ standalone notebook window. This is a nontrivial task because there is no ", StyleBox["ButtonStyle", "InlineInput"], " in the common style sheet notebooks that defines this sort of action. \ If we address some key questions before writing the code for the button, our \ work will be much easier." }], "Text"], Cell[CellGroupData[{ Cell[TextData[{ "Question 1 \[Dash] What portion of ", StyleBox["Mathematica", FontSlant->"Italic"], " will be performing the action associated with depressing the button?" }], "Subsection"], Cell["\<\ Buttons can induce actions in the kernel, the front end, or both. \ Sometimes the distinctions are not so clear. We know that the creation of a \ notebook window is a front end function, but the creation of a graphics \ object is a kernel function. \ \>", "Text"], Cell[TextData[{ "The kernel function ", StyleBox["NotebookPut", "InlineInput"], " (", StyleBox["Mathematica", FontSlant->"Italic"], " book, Section ", ButtonBox["2.10.2", ButtonData:>{"2.10.2", "2.21"}, Active->True, ButtonStyle->"MainBookLink"], ") allows one to build a notebook expression within the kernel and then \ pass it on to the front end for display. It makes more sense to define our \ button such that the action is performed in the kernel." }], "Text"], Cell[TextData[{ "The mechanism for specifying where the button's action will take place is \ the ", StyleBox["ButtonBox", "InlineInput"], " option ", StyleBox["ButtonEvaluator", "InlineInput"], " (Reference Guide ", ButtonBox["entry", ButtonData:>{"ButtonEvaluator", None}, Active->True, ButtonStyle->"RefGuideLink"], StyleBox[" ", ButtonBoxOptions->{Active->True, ButtonStyle->"RefGuideLink", ButtonNote->"{\"ButtonEvaluator\", None}"}], "for ", StyleBox["ButtonBox", "InlineInput"], "). We don't care which kernel is used for the evaluation, so we set ", StyleBox["ButtonEvaluator", "InlineInput"], " to be ", StyleBox["Automatic", "InlineInput"], ". That means that the kernel used by default by the front end will be \ used in the button's evaluation." }], "Text"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Question 2 \[Dash] What ", StyleBox["Mathematica", FontSlant->"Italic"], " expressions are to be used to perform the button's action?" }], "Subsection"], Cell[TextData[{ "The action perfomed by a button is specified by the ", StyleBox["ButtonFunction", "InlineInput"], " option. We indirectly answered part of our question in the prior \ subsection. ", StyleBox["NotebookPut", "InlineInput"], " will be the outermost function, but we must also provide a ", StyleBox["Notebook", "InlineInput"], " expression for delivery to the front end. " }], "Text"], Cell[BoxData[ RowBox[{"ButtonFunction", " ", ":>", RowBox[{"NotebookPut", "[", StyleBox[ RowBox[{"notebook", " ", "expression"}], FontSlant->"Italic"], StyleBox["]", "Text", FontSlant->"Italic"]}]}]], "Input", Evaluatable->False], Cell[TextData[{ "The notebook will have a lone cell with a with a PostScript ", StyleBox["GraphicsData", "InlineInput"], " expression (", StyleBox["Mathematica", FontSlant->"Italic"], " Book, Section ", ButtonBox["2.10.7", ButtonData:>{"2.10.7", "7.7"}, Active->True, ButtonStyle->"MainBookLink"], "). To clean up the appearance of the cell some, we can set the ", StyleBox["Cell", "InlineInput"], " option ", StyleBox["ShowCellBracket", "InlineInput"], " to ", StyleBox["False", "InlineInput"], " (", StyleBox["Mathematica", FontSlant->"Italic"], " Book, Section ", ButtonBox["2.10.9", ButtonData:>{"2.10.9", "9.3"}, Active->True, ButtonStyle->"MainBookLink"], "). " }], "Text"], Cell[BoxData[ RowBox[{"Cell", "[", RowBox[{ RowBox[{"GraphicsData", "[", RowBox[{"\"\\"", ",", " ", StyleBox[ RowBox[{ "string", " ", "of", " ", "Mathematica", " ", "abbreviated", " ", "PostScript"}], FontSlant->"Italic"]}], "]"}], ",", " ", RowBox[{"ShowCellBracket", " ", "->", " ", "False"}]}], "]"}]], "Input", Evaluatable->False], Cell[TextData[{ "The evaluation of a plotting function returns a graphics object. We can \ bridge the gap between graphics object and PostScript with the ", StyleBox["DisplayString", "InlineInput"], " function (Reference Guide ", ButtonBox["entry", ButtonData:>{"DisplayString", "None"}, Active->True, ButtonStyle->"RefGuideLink"], " for ", StyleBox["DisplayString", "InlineInput"], ")" }], "Text"], Cell[BoxData[ RowBox[{"DisplayString", "[", StyleBox[ RowBox[{"graphics", " ", "object"}], FontSlant->"Italic"], StyleBox["]", "Text", FontSlant->"Italic"]}]], "Input", Evaluatable->False], Cell[TextData[{ "We'll stop short of adding the actual plotting function here. We'll \ specify that elsewhere. Doing this leaves open the opportunity for us to \ reuse this code for displaying ", StyleBox["any", FontSlant->"Italic"], " plot. To preserve this generality, we have to rewrite our button \ function as a pure function (", StyleBox["Mathematica", FontSlant->"Italic"], " Book, Section ", ButtonBox["2.2.5", ButtonData:>{"2.2.5", None}, Active->True, ButtonStyle->"MainBookLink"], ")" }], "Text"], Cell[BoxData[ RowBox[{"ButtonFunction", " ", ":>", " ", RowBox[{"(", RowBox[{ RowBox[{"NotebookPut", "[", RowBox[{"Notebook", "[", RowBox[{"{", RowBox[{"Cell", "[", RowBox[{ RowBox[{"GraphicsData", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"DisplayString", "[", "#2", "]"}]}], "]"}], ",", RowBox[{"ShowCellBracket", " ", "->", " ", "False"}]}], "]"}], "}"}], "]"}], "]"}], "&"}], " ", ")"}]}]], "Input", Evaluatable->False], Cell[TextData[{ "Note that we have to wrap the pure function in parentheses because the \ postfix operator for ", StyleBox["Function", "InlineInput"], " has a lower precedence than the infix operator for ", StyleBox["RuleDelayed", "InlineInput"], " (", StyleBox["Mathematica", FontSlant->"Italic"], " Book, Section ", ButtonBox["A.2.7", ButtonData:>{"A.2.7", "7.9"}, Active->True, ButtonStyle->"MainBookLink"], "). The reason we use ", StyleBox["#2", "InlineInput"], " in lieu of just ", StyleBox["#", "InlineInput"], " will be made clear later on." }], "Text"], Cell["\<\ Once we get things working, we can always go back and adjust \ notebook level functions to tailor the appearance of the window to our \ liking.\ \>", "Text"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[ "Question 3 \[Dash] What arguments are to be supplied to the the button's \ function? "], "Subsection"], Cell[TextData[{ StyleBox["Mathematica", FontSlant->"Italic"], " supplies two ", StyleBox["ButtonBox", "InlineInput"], " options which allow you to specify up to two arguments to a ", StyleBox["ButtonFunction", "InlineInput"], " \[Dash] ", StyleBox["ButtonSource", "InlineInput"], " and ", StyleBox["ButtonData", "InlineInput"], ". At first glance, these option names seem to a bit obtuse, not spelling \ out very clearly what purpose that they might serve. If my ", StyleBox["ButtonFunction", "InlineInput"], " takes two arguments, which argument is ", StyleBox["ButtonSource", "InlineInput"], " and which one is ", StyleBox["ButtonData", "InlineInput"], "? What if my ", StyleBox["ButtonFunction", "InlineInput"], " takes only one argument?. " }], "Text"], Cell[TextData[{ StyleBox["ButtonSource", "InlineInput"], " is intended to be an argument that can refer to a specific location or \ region in a notebook (", StyleBox["Mathematica", FontSlant->"Italic"], " Book, Section ", ButtonBox["2.10.6", ButtonData:>{"2.10.6", "6.16"}, Active->True, ButtonStyle->"MainBookLink"], "). ", StyleBox["ButtonData", "InlineInput"], " contains hard-coded information that you may want to keep hidden behind \ the scenes. " }], "Text"], Cell[TextData[{ "The command that we will use to generate the plot is highly specific. \ Moreover, because the function syntax may be long, we probably don't want to \ place the plotting command anywhere where the user may see it. It becomes \ clear that ", StyleBox["ButtonData", "InlineInput"], " is the option we will use to house the plotting command." }], "Text"], Cell[TextData[{ "We have no use for a ", StyleBox["ButtonSource", "InlineInput"], " here. Since the ", StyleBox["ButtonData", "InlineInput"], " value is considered to be the option that gives the second argument, we \ now see why we chose ", StyleBox["#2", "InlineInput"], " in our arguments to the ", StyleBox["ButtonFunction", "InlineInput"], " value despite the fact that there is only one argument to the function." }], "Text"], Cell[TextData[{ "In our example, we will choose a ", StyleBox["Plot3D", "InlineInput"], " function. " }], "Text"], Cell[BoxData[ RowBox[{"ButtonData", " ", ":>", " ", RowBox[{"Plot3D", "[", RowBox[{ RowBox[{ RowBox[{"Sin", "[", "x", "]"}], " ", RowBox[{"Cos", "[", "y", "]"}]}], ",", RowBox[{"{", RowBox[{"x", ",", "0", ",", RowBox[{"2", "Pi"}]}], "}"}], ",", " ", RowBox[{"{", RowBox[{"y", ",", "0", ",", RowBox[{"2", "Pi"}]}], "}"}], ",", StyleBox[ RowBox[{"DisplayFunction", " ", "->", " ", "Identity"}], "InlineInput"]}], "]"}]}]], "Input", Evaluatable->False], Cell[TextData[{ "The ", StyleBox["DisplayFunction", "InlineInput"], " value of ", StyleBox["Identity", "InlineInput"], " keeps the plot from being generated in the notebook where the button sits \ as well (", StyleBox["Mathematica", FontSlant->"Italic"], " Book, Section ", ButtonBox["2.9.14", ButtonData:>{"2.9.14", "14.3"}, Active->True, ButtonStyle->"MainBookLink"], "). " }], "Text"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[ "Question 4 \[Dash] What should the button say, and how do I enter it?"], "Subsection"], Cell[TextData[{ "The first part of this question is a generic user design decision that \ shouldn't be taken too lightly, lest your poor choices wind up in the ", ButtonBox["User Interface Hall of Shame", ButtonData:>{ URL[ "http://www.iarchitect.com/mshame.htm"], None}, Active->True, ButtonStyle->"Hyperlink", ButtonNote->"visit the User Interface Hall of Shame"], " \[HappySmiley]. In our case, we'll label the button with a description \ of exactly what the button does." }], "Text"], Cell[TextData[{ "Generate a plot of ", Cell[BoxData[ FormBox[ RowBox[{ RowBox[{"sin", "(", "x", ")"}], " ", RowBox[{"cos", "(", "y", ")"}]}], TraditionalForm]]], " over ", Cell[BoxData[ FormBox[ RowBox[{ RowBox[{"[", RowBox[{"0", ",", " ", RowBox[{"2", "\[Pi]"}]}], "]"}], " ", "\[Cross]", " ", RowBox[{"[", RowBox[{"0", ",", " ", RowBox[{"2", "\[Pi]"}]}], "]"}]}], TraditionalForm]]], "." }], "DisplayText", TextAlignment->Center], Cell[TextData[{ "The label of the button is specified in the first argument to ", StyleBox["ButtonBox", "InlineInput"], ". You can supply either a string or boxes. We'll have some troubles \ trying to squeeze in the inline cells above, but we can work around this by \ pasting the cell's ", StyleBox["contents", FontSlant->"Italic"], " into an ", StyleBox["Input", "InlineInput"], " cell. This converts the ", StyleBox["TextData", "InlineInput"], " into ", StyleBox["BoxData", "InlineInput"], ". Then we can unformat the cell with the front end ", StyleBox["Show Expression", FontFamily->"Helvetica"], " menu item and copy the composite row box. Here is the result we get from \ our label." }], "Text"], Cell[BoxData[ RowBox[{"RowBox", "[", RowBox[{"{", RowBox[{ "\"\\"", ",", " ", "\"\< \>\"", ",", " ", "\"\\"", ",", " ", "\"\< \>\"", ",", " ", "\"\\"", ",", " ", "\"\< \>\"", ",", " ", "\"\\"", ",", " ", "\"\< \>\"", ",", " ", "\n", " ", RowBox[{"FormBox", "[", "\n", " ", RowBox[{ RowBox[{"RowBox", "[", RowBox[{"{", "\n", " ", RowBox[{ RowBox[{"RowBox", "[", RowBox[{"{", RowBox[{ "\"\\"", ",", " ", "\"\<(\>\"", ",", " ", "\"\\"", ",", " ", "\"\<)\>\""}], "}"}], "]"}], ",", " ", "\"\< \>\"", ",", " ", "\n", " ", RowBox[{"RowBox", "[", RowBox[{"{", RowBox[{ "\"\\"", ",", " ", "\"\<(\>\"", ",", " ", "\"\\"", ",", " ", "\"\<)\>\""}], "}"}], "]"}]}], "}"}], "]"}], ",", "\n", " ", "\"\\""}], "]"}], ",", " ", "\"\< \>\"", ",", " ", "\"\\"", ",", " ", "\"\< \>\"", ",", " ", "\n", " ", RowBox[{"RowBox", "[", RowBox[{"{", "\n", " ", RowBox[{ RowBox[{"FormBox", "[", "\n", " ", RowBox[{ RowBox[{"RowBox", "[", RowBox[{"{", "\n", " ", RowBox[{ RowBox[{"RowBox", "[", RowBox[{"{", RowBox[{ "\"\<[\>\"", ",", " ", "\n", " ", RowBox[{"RowBox", "[", RowBox[{"{", RowBox[{ "\"\<0\>\"", ",", " ", "\"\<,\>\"", ",", " ", "\"\<2\[Pi]\>\""}], "}"}], "]"}], ",", " ", "\"\<]\>\""}], "}"}], "]"}], ",", " ", "\"\< \>\"", ",", " ", "\"\<\[Cross]\>\"", ",", " ", "\n", " ", "\"\< \>\"", ",", " ", "\n", " ", RowBox[{"RowBox", "[", RowBox[{"{", RowBox[{ "\"\<[\>\"", ",", " ", "\n", " ", RowBox[{"RowBox", "[", RowBox[{"{", RowBox[{ "\"\<0\>\"", ",", " ", "\"\<,\>\"", ",", " ", "\"\<2\[Pi]\>\""}], "}"}], "]"}], ",", " ", "\"\<]\>\""}], "}"}], "]"}]}], "}"}], "]"}], ",", "\n", " ", "\"\\""}], "]"}], ",", " ", "\"\<.\>\""}], "}"}], "]"}]}], "}"}], "]"}]], "Input", Evaluatable->False] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["The Solution", "Section"], Cell[TextData[{ "By putting a lot of effort into forethought, the solution now becomes very \ straightforward. We can cobble together a button box and display it in the \ notebook for testing by wrapping the ", StyleBox["ButtonBox", "InlineInput"], " in ", StyleBox["DisplayForm", "InlineInput"], ". Go ahead and evaluate this ", StyleBox["Input", "InlineInput"], " cell and then set the resulting output cell's ", StyleBox["Active", "InlineInput"], " option to be ", StyleBox["True", "InlineInput"], ". You can set the option using the ", StyleBox["Cell Properties ", FontFamily->"Helvetica"], "menu item. This will make button presses evaluate the ", StyleBox["ButtonFunction", "InlineInput"], "." }], "Text"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{ RowBox[{"ButtonBox", "[", RowBox[{ RowBox[{"RowBox", "[", RowBox[{"{", RowBox[{ "\"\\"", ",", " ", "\"\< \>\"", ",", " ", "\"\\"", ",", " ", "\"\< \>\"", ",", " ", "\"\\"", ",", " ", "\"\< \>\"", ",", " ", "\"\\"", ",", " ", "\"\< \>\"", ",", " ", "\n", " ", RowBox[{"FormBox", "[", "\n", " ", RowBox[{ RowBox[{"RowBox", "[", RowBox[{"{", "\n", " ", RowBox[{ RowBox[{"RowBox", "[", RowBox[{"{", RowBox[{ "\"\\"", ",", " ", "\"\<(\>\"", ",", " ", "\"\\"", ",", " ", "\"\<)\>\""}], "}"}], "]"}], ",", " ", "\"\< \>\"", ",", " ", "\n", " ", RowBox[{"RowBox", "[", RowBox[{"{", RowBox[{ "\"\\"", ",", " ", "\"\<(\>\"", ",", " ", "\"\\"", ",", " ", "\"\<)\>\""}], "}"}], "]"}]}], "}"}], "]"}], ",", "\n", " ", "\"\\""}], "]"}], ",", " ", "\"\< \>\"", ",", " ", "\"\\"", ",", " ", "\"\< \>\"", ",", " ", "\n", " ", RowBox[{"RowBox", "[", RowBox[{"{", "\n", " ", RowBox[{ RowBox[{"FormBox", "[", "\n", " ", RowBox[{ RowBox[{"RowBox", "[", RowBox[{"{", "\n", " ", RowBox[{ RowBox[{"RowBox", "[", RowBox[{"{", RowBox[{ "\"\<[\>\"", ",", " ", "\n", " ", RowBox[{"RowBox", "[", RowBox[{"{", RowBox[{ "\"\<0\>\"", ",", " ", "\"\<,\>\"", ",", " ", "\"\<2\[Pi]\>\""}], "}"}], "]"}], ",", " ", "\"\<]\>\""}], "}"}], "]"}], ",", " ", "\"\< \>\"", ",", " ", "\"\<\[Cross]\>\"", ",", " ", "\n", " ", "\"\< \>\"", ",", " ", "\n", " ", RowBox[{"RowBox", "[", RowBox[{"{", RowBox[{ "\"\<[\>\"", ",", " ", "\n", " ", RowBox[{"RowBox", "[", RowBox[{"{", RowBox[{ "\"\<0\>\"", ",", " ", "\"\<,\>\"", ",", " ", "\"\<2\[Pi]\>\""}], "}"}], "]"}], ",", " ", "\"\<]\>\""}], "}"}], "]"}]}], "}"}], "]"}], ",", "\n", " ", "\"\\""}], "]"}], ",", " ", "\"\<.\>\""}], "}"}], "]"}]}], "}"}], "]"}], ",", " ", RowBox[{"ButtonEvaluator", " ", "->", " ", "\"\\""}], ",", RowBox[{"ButtonFunction", " ", ":>", " ", RowBox[{"(", RowBox[{ RowBox[{"NotebookPut", "[", RowBox[{"Notebook", "[", RowBox[{"{", RowBox[{"Cell", "[", RowBox[{ RowBox[{"GraphicsData", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"DisplayString", "[", "#2", "]"}]}], "]"}], ",", RowBox[{ "ShowCellBracket", " ", "->", " ", "False"}]}], "]"}], "}"}], "]"}], "]"}], "&"}], " ", ")"}]}], ",", " ", RowBox[{"ButtonData", " ", ":>", " ", RowBox[{"Plot3D", "[", RowBox[{ RowBox[{ RowBox[{"Sin", "[", "x", "]"}], " ", RowBox[{"Cos", "[", "y", "]"}]}], ",", RowBox[{"{", RowBox[{"x", ",", "0", ",", RowBox[{"2", "Pi"}]}], "}"}], ",", " ", RowBox[{"{", RowBox[{"y", ",", "0", ",", RowBox[{"2", "Pi"}]}], "}"}], ",", StyleBox[ RowBox[{"DisplayFunction", " ", "->", " ", "Identity"}], "InlineInput"]}], "]"}]}]}], "]"}], " ", "//", " ", "DisplayForm"}]], "Input"], Cell[BoxData[ TagBox[ ButtonBox[ RowBox[{"Generate", " ", "a", " ", "plot", " ", "of", " ", FormBox[ RowBox[{ RowBox[{"sin", "(", "x", ")"}], " ", RowBox[{"cos", "(", "y", ")"}]}], "TraditionalForm"], " ", "over", " ", RowBox[{ FormBox[ RowBox[{ RowBox[{"[", RowBox[{"0", ",", RowBox[{"2", "\[Pi]"}]}], "]"}], " ", "\[Cross]", " ", RowBox[{"[", RowBox[{"0", ",", RowBox[{"2", "\[Pi]"}]}], "]"}]}], "TraditionalForm"], "."}]}], ButtonFunction:>(NotebookPut[ Notebook[ { Cell[ GraphicsData[ "PostScript", DisplayString[ #2]], ShowCellBracket -> False]}]]&), ButtonEvaluator->Automatic, ButtonData:>Plot3D[ Times[ Sin[ x], Cos[ y]], {x, 0, Times[ 2, Pi]}, {y, 0, Times[ 2, Pi]}, DisplayFunction -> Identity]], DisplayForm]], "Output"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Polishing up the Work", "Section"], Cell[TextData[{ "We can avoid having to set the ", StyleBox["Active", "InlineInput"], " option at the cell level every time we rebuild the button by setting this \ option at the ", StyleBox["ButtonBox", "InlineInput"], " level. The appearance of the output window generated by this button can \ be improved by adjusting ", StyleBox["Notebook", "InlineInput"], " level options like ", StyleBox["WindowSize", "InlineInput"], ", ", StyleBox["WindowElements", "InlineInput"], ", and ", StyleBox["WindowTitle", "InlineInput"], ". Wrapping a ", StyleBox["StyleBox", "InlineInput"], " around the button's contents allows us to adjust the used in displaying \ the button text. Inserting some newline characters will help to reduce the \ width of the ", StyleBox["ButtonBox", "InlineInput"], ". Evaluate this ", StyleBox["Input", "InlineInput"], " cell to see the improvements." }], "Text"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{ RowBox[{"ButtonBox", "[", RowBox[{ RowBox[{"StyleBox", "[", RowBox[{ RowBox[{"RowBox", "[", RowBox[{"{", RowBox[{ "\"\\"", ",", " ", "\"\< \>\"", ",", " ", "\"\\"", ",", " ", "\"\< \>\"", ",", " ", "\"\\"", ",", " ", "\"\< \>\"", ",", " ", "\"\\"", ",", " ", "\"\<\\n\>\"", ",", " ", "\n", " ", RowBox[{"FormBox", "[", "\n", " ", RowBox[{ RowBox[{"RowBox", "[", RowBox[{"{", "\n", " ", RowBox[{ RowBox[{"RowBox", "[", RowBox[{"{", RowBox[{ "\"\\"", ",", " ", "\"\<(\>\"", ",", " ", "\"\\"", ",", " ", "\"\<)\>\""}], "}"}], "]"}], ",", " ", "\"\< \>\"", ",", " ", "\n", " ", RowBox[{"RowBox", "[", RowBox[{"{", RowBox[{ "\"\\"", ",", " ", "\"\<(\>\"", ",", " ", "\"\\"", ",", " ", "\"\<)\>\""}], "}"}], "]"}]}], "}"}], "]"}], ",", "\n", " ", "\"\\""}], "]"}], ",", " ", "\"\<\\n\>\"", ",", " ", "\"\\"", ",", " ", "\"\< \>\"", ",", " ", "\n", " ", RowBox[{"RowBox", "[", RowBox[{"{", "\n", " ", RowBox[{ RowBox[{"FormBox", "[", "\n", " ", RowBox[{ RowBox[{"RowBox", "[", RowBox[{"{", "\n", " ", RowBox[{ RowBox[{"RowBox", "[", RowBox[{"{", RowBox[{ "\"\<[\>\"", ",", " ", "\n", " ", RowBox[{"RowBox", "[", RowBox[{"{", RowBox[{ "\"\<0\>\"", ",", " ", "\"\<,\>\"", ",", " ", "\"\<\[Pi]\>\""}], "}"}], "]"}], ",", " ", "\"\<]\>\""}], "}"}], "]"}], ",", " ", "\"\< \>\"", ",", " ", "\"\<\[Cross]\>\"", ",", " ", "\n", " ", "\"\< \>\"", ",", " ", "\n", " ", RowBox[{"RowBox", "[", RowBox[{"{", RowBox[{ "\"\<[\>\"", ",", " ", "\n", " ", RowBox[{"RowBox", "[", RowBox[{"{", RowBox[{ "\"\<0\>\"", ",", " ", "\"\<,\>\"", ",", " ", "\"\<\[Pi]\>\""}], "}"}], "]"}], ",", " ", "\"\<]\>\""}], "}"}], "]"}]}], "}"}], "]"}], ",", "\n", " ", "\"\\""}], "]"}], ",", " ", "\"\<.\>\""}], "}"}], "]"}]}], "}"}], "]"}], ",", " ", RowBox[{"FontFamily", " ", "->", " ", "\"\\""}]}], "]"}], ",", " ", RowBox[{"ButtonEvaluator", " ", "->", " ", "\"\\""}], ",", RowBox[{"ButtonFunction", " ", ":>", " ", RowBox[{"(", RowBox[{ RowBox[{"NotebookPut", "[", RowBox[{"Notebook", "[", RowBox[{ RowBox[{"{", RowBox[{"Cell", "[", RowBox[{ RowBox[{"GraphicsData", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"DisplayString", "[", "#2", "]"}]}], "]"}], ",", RowBox[{ "ShowCellBracket", " ", "->", " ", "False"}]}], "]"}], "}"}], ",", " ", RowBox[{"WindowSize", " ", "->", " ", RowBox[{"{", RowBox[{"300", ",", "250"}], "}"}]}], ",", " ", RowBox[{"WindowElements", " ", "->", " ", RowBox[{"{", "}"}]}], ",", RowBox[{"WindowTitle", "->", "\"\\""}]}], "]"}], "]"}], "&"}], " ", ")"}]}], ",", " ", RowBox[{"ButtonData", " ", ":>", " ", RowBox[{"Plot3D", "[", RowBox[{ RowBox[{ RowBox[{"Sin", "[", "x", "]"}], " ", RowBox[{"Cos", "[", "y", "]"}]}], ",", RowBox[{"{", RowBox[{"x", ",", "0", ",", RowBox[{"2", "Pi"}]}], "}"}], ",", " ", RowBox[{"{", RowBox[{"y", ",", "0", ",", RowBox[{"2", "Pi"}]}], "}"}], ",", StyleBox[ RowBox[{"DisplayFunction", " ", "->", " ", "Identity"}], "InlineInput"]}], "]"}]}], ",", " ", RowBox[{"Active", " ", "->", " ", "True"}]}], "]"}], " ", "//", " ", "DisplayForm"}]], "Input"], Cell[BoxData[ TagBox[ ButtonBox[ StyleBox[ RowBox[{"Generate", " ", "a", " ", "plot", " ", "of", "\n", FormBox[ RowBox[{ RowBox[{"sin", "(", "x", ")"}], " ", RowBox[{"cos", "(", "y", ")"}]}], "TraditionalForm"], "\n", "over", " ", RowBox[{ FormBox[ RowBox[{ RowBox[{"[", RowBox[{"0", ",", "\[Pi]"}], "]"}], " ", "\[Cross]", " ", RowBox[{"[", RowBox[{"0", ",", "\[Pi]"}], "]"}]}], "TraditionalForm"], "."}]}], FontFamily->"Helvetica"], ButtonFunction:>(NotebookPut[ Notebook[ { Cell[ GraphicsData[ "PostScript", DisplayString[ #2]], ShowCellBracket -> False]}, WindowSize -> {300, 250}, WindowElements -> {}, WindowTitle -> "Graphics"]]&), ButtonEvaluator->Automatic, ButtonData:>Plot3D[ Times[ Sin[ x], Cos[ y]], {x, 0, Times[ 2, Pi]}, {y, 0, Times[ 2, Pi]}, DisplayFunction -> Identity], Active->True], DisplayForm]], "Output"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Reusing your Work", "Section"], Cell[TextData[{ "Earlier in this notebook, we took some pains in separating task-specific \ material from things that might be reusable. Gathering the set of reusable ", StyleBox["ButtonBox", "InlineInput"], " objects together, we can place them in a ", StyleBox["StyleData", "InlineInput"], " cell in a style sheet so that you can speed the creation of similar \ buttons. Here is an example of what a cell style might look like." }], "Text"], Cell[BoxData[ RowBox[{ RowBox[{"Cell", "[", RowBox[{ RowBox[{"StyleData", "[", "\"\\"", "]"}], ",", RowBox[{"StyleMenuListing", "->", "None"}], ",", RowBox[{"ButtonStyleMenuListing", "->", "Automatic"}], ",", " ", RowBox[{"ButtonBoxOptions", "->", RowBox[{"{", RowBox[{ RowBox[{ "ButtonEvaluator", " ", "->", " ", "\"\\""}], ",", RowBox[{"ButtonFunction", " ", ":>", " ", RowBox[{"(", RowBox[{ RowBox[{"NotebookPut", "[", RowBox[{"Notebook", "[", RowBox[{ RowBox[{"{", RowBox[{"Cell", "[", RowBox[{ RowBox[{"GraphicsData", "[", RowBox[{"\"\\"", ",", " ", RowBox[{ "DisplayString", "[", "#2", "]"}]}], "]"}], ",", RowBox[{ "ShowCellBracket", " ", "->", " ", "False"}]}], "]"}], "}"}], ",", " ", RowBox[{"WindowSize", " ", "->", " ", RowBox[{"{", RowBox[{"300", ",", "250"}], "}"}]}], ",", " ", RowBox[{"WindowElements", " ", "->", " ", RowBox[{"{", "}"}]}], ",", RowBox[{ "WindowTitle", "->", "\"\\""}]}], "]"}], "]"}], "&"}], " ", ")"}]}], ",", RowBox[{"Active", " ", "->", " ", "True"}]}], "}"}]}]}], "]"}], " ", "//", " ", "CellPrint"}]], "Input"], Cell[StyleData["PutGraphicInWindow"], GeneratedCell->True, CellAutoOverwrite->True, StyleMenuListing->None, ButtonStyleMenuListing->Automatic, ButtonBoxOptions->{ButtonFunction:>(NotebookPut[ Notebook[ { Cell[ GraphicsData[ "PostScript", DisplayString[ #2]], ShowCellBracket -> False]}, WindowSize -> { 300, 250}, WindowElements -> {}, WindowTitle -> "Graphics"]]&), ButtonEvaluator->Automatic, Active->True}], Cell[TextData[{ "Setting the ", StyleBox["Cell", "InlineInput"], " option ", StyleBox["StyleMenuListing", "InlineInput"], " to ", StyleBox["None", "InlineInput"], " makes sure that the prototype does not appear on the ", StyleBox["Format", FontFamily->"Helvetica"], " \[Rule]", StyleBox["Style", FontFamily->"Helvetica"], " menu, and setting ", StyleBox["ButtonStyleMenuListing", "InlineInput"], " to ", StyleBox["Automatic", "InlineInput"], " makes the ", StyleBox["ButtonStyle", "InlineInput"], " available from the ", StyleBox["Input", FontFamily->"Helvetica"], " \[Rule]", StyleBox[" Create Button", FontFamily->"Helvetica"], " menu. If you do choose to use the ", StyleBox["Edit Button", FontFamily->"Helvetica"], " dialog box facility for editing a button like this, the input on the ", StyleBox["ButtonData", FontFamily->"Helvetica"], " blank must be of the form: " }], "Text"], Cell[BoxData[ RowBox[{"ToExpression", "[", StyleBox[ RowBox[{"string", " ", "containing", " ", "plot", " ", "command"}], FontSlant->"Italic"], StyleBox["]", FontSlant->"Italic"]}]], "Input", Evaluatable->False], Cell["In our example, the input would look like:", "Text"], Cell[BoxData[ RowBox[{ "ToExpression", "[", "\"\\\),\n\"InlineInput\"]\)\!\(\* StyleBox[\\(\\\ \\),\n\"InlineInput\"]\)\!\(\* StyleBox[\\(Identity\\),\n\"InlineInput\"]\)]\>\"", "]"}]], "Input", Evaluatable->False], Cell[TextData[{ "This tutorial is Copyright \[Copyright] 1998 Wolfram Research, Inc. All \ rights reserved. It may be distributed without charge provided that its \ content remains unaltered. No guarantees of support are made or implied. \ Suggestions for improvement are welcome at e-mail address ", ButtonBox["paulh@wolfram.com", ButtonData:>{ URL[ "mailto:paulh@wolfram.com"], None}, ButtonStyle->"Hyperlink", ButtonNote->"Send mail to P.J. Hinton"], ". This notebook was composed and tested with ", StyleBox["Mathematica", FontSlant->"Italic"], " 3.0.2 for Linux (ELF binary)." }], "Commentary"] }, Open ]] }, FrontEndVersion->"Macintosh 3.0", ScreenRectangle->{{0, 800}, {0, 580}}, WindowSize->{518, 398}, WindowMargins->{{Automatic, 207}, {Automatic, 56}}, WindowElements->{ "StatusArea", "HorizontalScrollBar", "VerticalScrollBar", "MenuBar"}, StyleDefinitions -> "Demo.nb", MacintoshSystemPageSetup->"\<\ 00<0001804P000000]P2:?oQon82n@960dL5:0?l0080001804P000000]P2:001 0000I00000400`<300000BL?00400@0000000000000006P801T1T00000000000 00000000000000000000000000000000\>" ] (*********************************************************************** Cached data follows. If you edit this Notebook file directly, not using Mathematica, you must remove the line containing CacheID at the top of the file. The cache data will then be recreated when you save this file from within Mathematica. ***********************************************************************) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[1709, 49, 63, 0, 81, "Title"], Cell[1775, 51, 152, 5, 88, "Subsubtitle"], Cell[1930, 58, 51, 0, 56, "Subsubtitle"], Cell[CellGroupData[{ Cell[2006, 62, 31, 0, 72, "Section"], Cell[2040, 64, 469, 12, 67, "Text"], Cell[2512, 78, 573, 10, 89, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[3122, 93, 30, 0, 72, "Section"], Cell[3155, 95, 404, 7, 76, "Text"], Cell[CellGroupData[{ Cell[3584, 106, 200, 5, 72, "Subsection"], Cell[3787, 113, 276, 5, 51, "Text"], Cell[4066, 120, 497, 14, 65, "Text"], Cell[4566, 136, 822, 23, 79, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[5425, 164, 179, 5, 54, "Subsection"], Cell[5607, 171, 414, 9, 67, "Text"], Cell[6024, 182, 300, 9, 31, "Input", Evaluatable->False], Cell[6327, 193, 747, 26, 71, "Text"], Cell[7077, 221, 463, 12, 63, "Input", Evaluatable->False], Cell[7543, 235, 425, 12, 57, "Text"], Cell[7971, 249, 240, 8, 31, "Input", Evaluatable->False], Cell[8214, 259, 544, 16, 71, "Text"], Cell[8761, 277, 659, 15, 63, "Input", Evaluatable->False], Cell[9423, 294, 604, 19, 71, "Text"], Cell[10030, 315, 167, 4, 43, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[10234, 324, 118, 2, 62, "Subsection"], Cell[10355, 328, 800, 21, 99, "Text"], Cell[11158, 351, 500, 15, 71, "Text"], Cell[11661, 368, 376, 7, 71, "Text"], Cell[12040, 377, 450, 11, 71, "Text"], Cell[12493, 390, 120, 4, 29, "Text"], Cell[12616, 396, 619, 16, 47, "Input", Evaluatable->False], Cell[13238, 414, 422, 15, 57, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[13697, 434, 105, 2, 62, "Subsection"], Cell[13805, 438, 516, 11, 71, "Text"], Cell[14324, 451, 570, 19, 51, "DisplayText"], Cell[14897, 472, 742, 19, 99, "Text"], Cell[15642, 493, 3290, 62, 271, "Input", Evaluatable->False] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[18981, 561, 31, 0, 73, "Section"], Cell[19015, 563, 749, 19, 99, "Text"], Cell[CellGroupData[{ Cell[19789, 586, 5412, 103, 383, "Input"], Cell[25204, 691, 1139, 31, 55, "Output"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[26392, 728, 40, 0, 73, "Section"], Cell[26435, 730, 923, 24, 127, "Text"], Cell[CellGroupData[{ Cell[27383, 758, 6384, 118, 447, "Input"], Cell[33770, 878, 1297, 35, 88, "Output"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[35116, 919, 36, 0, 73, "Section"], Cell[35155, 921, 457, 9, 85, "Text"], Cell[35615, 932, 2063, 41, 191, "Input"], Cell[37681, 975, 470, 12, 38, 37, 0, "StyleData", "PutGraphicInWindow", "All", StyleMenuListing->None, ButtonStyleMenuListing->Automatic], Cell[38154, 989, 960, 32, 99, "Text"], Cell[39117, 1023, 254, 7, 31, "Input", Evaluatable->False], Cell[39374, 1032, 58, 0, 29, "Text"], Cell[39435, 1034, 401, 9, 47, "Input", Evaluatable->False], Cell[39839, 1045, 636, 14, 80, "Commentary"] }, Open ]] } ] *) (*********************************************************************** End of Mathematica Notebook file. ***********************************************************************) ÿ