Re: Silly Mathematica button question
- To: mathgroup at smc.vnet.net
- Subject: [mg36148] Re: [mg36139] Silly Mathematica button question
- From: Rolf Mertig <rolf at mertig.com>
- Date: Fri, 23 Aug 2002 21:34:37 -0400 (EDT)
- Organization: Mertig Consulting
- Sender: owner-wri-mathgroup at wolfram.com
Hi, evaluating the following gives you a sample "x=x+1" button: NotebookPut@Notebook[{Cell[BoxData[ ButtonBox[\(x = \(x + 1\)\), RuleDelayed[ButtonFunction, CompoundExpression[If[Not[ ValueQ[x]], Set[x, 0]], Set[x, Plus[x, 1]]]], Rule[ButtonEvaluator, Automatic]] ], "NotebookDefault", PageBreakAbove -> True, CellTags -> "GeneratedButtonBoxx=x+1"]}, ClosingAutoSave -> True, Editable -> False, WindowToolbars -> {}, PageWidth -> 299.5, WindowSize -> {89., 29.}, WindowMargins -> {{92., Automatic}, {Automatic, 56.}}, WindowFrame -> "Palette", WindowElements -> {}, WindowFrameElements -> "CloseBox", WindowClickSelect -> False, ScrollingOptions -> {"PagewiseScrolling" -> True}, ShowCellBracket -> False, CellMargins -> {{0., 0.}, {Inherited, 0.}}, Active -> True, CellOpen -> True, ShowCellLabel -> False, ShowCellTags -> False, ImageMargins -> {{0., Inherited}, {Inherited, 0.}}, Magnification -> 1.5] (* ********************************* *) Now, how do you create such a button in less than a minute? ... : One way is to just create a section cell and the underlying "ButtonFunction" code as input cells, i.e., type interactively such that you get something like: NotebookPut[Notebook[ {Cell[CellGroupData[ {Cell["x=x+1", "Section"], Cell["If[!ValueQ[x], x=0]", "Input"], Cell["x=x+1", "Input"]}, Open]]}]] Then hit the "F2B" (function to Button) button in ButtonTools.nb ( my freeware button tools from http://www.mertig.com/mathdepot ) and you get the button. With the "HP" and "VP" you can easily and quickly generate (horizontally or verically) palettes. Check out the "Help" button, or also the source code. It basically is all straightforward and there is actually documentation about all those ButtonFunction features somewhere. I agree that the whole Button-design could have been made better, but up to a point is quite useful. Of course the world is used to better GUI's these days but if you really need nice GUI's and buttons, use Java and JLink ( and there are also simple examples in the JLink manual of how to do this ). If you don't like Java, go with VBA and use the nice "Mahematica for Active X" product from http://www.episoft.com Regards, Rolf Mertig Mertig Consulting http://www.mertig.com