Re: first usage of a button
- To: mathgroup at smc.vnet.net
- Subject: [mg13713] Re: first usage of a button
- From: "P.J. Hinton" <paulh>
- Date: Wed, 19 Aug 1998 01:38:07 -0400
- Organization: "Wolfram Research, Inc."
- References: <6r0v5n$fg2@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
On 14 Aug 1998, jmthomas wrote: > In order to standardize the use of notebooks for non-specialist people, > I have built the following button, that sets the working directory to > the notebook directory. (Other versions can also read a initialization > file). > > Cell[BoxData[ > FormBox[ > ButtonBox["SetWorkingDirectory", > > tonFunction:>SetDirectory[ > DirectoryName[ > Module[ {pathName}, > ToFileName[ > ReplaceAll[ "FileName", > NotebookInformation[ > ButtonNotebook[ ]]]]]]], > ButtonEvaluator->Automatic, > Active->True, > ButtonStyle->None, > ButtonNote->"init"], Null]], "Input"] > > The button works fine but in one case: when Mathematica has just been > started (with an autoloaded kernel) and the notebook just been opened, > I get a message (from the FrontEnd): "Evaluation Nonstandard Form: > Warning: You are giving input which is not InputForm or StandardForm, > etc. " and people can choose between "Cancel" and "Evaluate" Choosing > "Evaluate" performs a correct task, but for first-time users my > notebook does not look like a "click and go" notebook! The message also > suggests to use "convert", which leads to a disaster, ruining the > button itself. > > What can I do to have a clean button? Is there a reason that you chose to embed the ButtonBox in a FormBox with Null format type? I suspect that this is what's flagging the front end warning message dialog box. If you want to get a nice textual appearance, you can use a StyleBox. ButtonBox[ StyleBox["Set Working Directory", FontFamily -> "Times", FontWeight->Plain], ButtonFunction:>SetDirectory[ DirectoryName[ Module[ {pathName}, ToFileName[ ReplaceAll[ "FileName", NotebookInformation[ ButtonNotebook[ ]]]]]]], ButtonEvaluator->Automatic, Active->True, ButtonNote->"init"]// DisplayForm You may want to add some sort of protection against the possibility that NotebookInformation[] does not return a "FileName" replacement rule (e.g. if the notebook is untitled). You could induce some mysterious beeps if a user clicks on this button in a newly-created notebook. -- P.J. Hinton Mathematica Programming Group paulh at wolfram.com Wolfram Research, Inc. http://www.wolfram.com/~paulh/ Disclaimer: Opinions expressed herein are those of the author alone.