Button[label, action] - InputString[]?
- To: mathgroup at smc.vnet.net
- Subject: [mg83591] Button[label, action] - InputString[]?
- From: Joe Sneed <jsneed at mines.edu>
- Date: Sat, 24 Nov 2007 04:07:39 -0500 (EST)
- Organization: Colorado School of Mines
I run V6.01 under Windows XP
I want to construct a button that reads a string input and writes
something determined by the input to a notebook. When I click on "close"
of "X" in the input dialog box, I want nothing to appear in the notebook.
I have two questions: one dealing with evaluation method; another
dealing with the use of If[ _, _, _] in the button function.
As a test, I try to read the input and write it to a selected notebook using
Button[Style["LABEL", Black, 10, FontFamily -> "Arial Black"],
tag=InputString[];
nb=SelectedNotebook[];
If[tag ? $Canceled,
NotebookWrite[nb,Cell[tag,"Text"]]]]
to construct the button.
This yields a button whose underlying expression is
Cell[BoxData[
ButtonBox[
StyleBox["\<\"LABEL\"\>",
StripOnInput->False,
FrontFaceColor->GrayLevel[0],
BackFaceColor->GrayLevel[0],
GraphicsColor->GrayLevel[0],
FontFamily->"Arial Black",
FontSize->10,
FontColor->GrayLevel[0]],
Appearance->Automatic,
ButtonFrame->"DialogBox",
ButtonFunction:>($CellContext`tag =
InputString[]; $CellContext`nb =
SelectedNotebook[];
If[$CellContext`tag != $Canceled,
NotebookWrite[$CellContext`nb,
Cell[$CellContext`tag, "Text"]]]),
Evaluator->Automatic,
Method->"Preemptive"]], "Output",
CellChangeTimes->{3.40483095753125*^9},
CellLabel->"Out[1]="]
This produces an input dialog box that times out without accepting
input. if I change the default
Method->"Preemptive" -- to---> Method->"Queued"
My first question is , "Why must I change the method?".
Having made the method change, I can enter input and without the If[ ]
write the input to the selected notebook.
But the conditional does not work. If I enter input and click OK,
nothing is entered into the selected notebook.
The purpose of the conditional If[ ] is to avoid the appearance of
"$Canceled" in the selected notebook when one clicks on "Cancel" or "X"
in the input dialog box.
My second question has two parts: 1) "Why doesn't the If[ ] work; 2)
what will work to accomplish my purpose?".
Any help much appreciated....
Joe
--
Joe Sneed
Division of Liberal Arts and International Studies
Colorado School of Mines
Golden CO USA
mailto:jsneed at mines.edu
http://www.mines.edu/fs_home/jsneed/