Re: Button[label, action] - InputString?
- To: mathgroup at smc.vnet.net
- Subject: [mg83624] Re: Button[label, action] - InputString?
- From: Albert <awnl at arcor.net>
- Date: Sun, 25 Nov 2007 04:35:21 -0500 (EST)
- References: <firstname.lastname@example.org>
Joe Sneed wrote:
> 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"],
> If[tag ? $Canceled,
> to construct the button.
> This yields a button whose underlying expression is
> FontFamily->"Arial Black",
> ButtonFunction:>($CellContext`tag =
> InputString; $CellContext`nb =
> If[$CellContext`tag != $Canceled,
> Cell[$CellContext`tag, "Text"]]]),
> Method->"Preemptive"]], "Output",
> 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?".
Because Preemptive means that the kernel is interrupted in doing what it
does for a quick calculation so that these buttons are reactive even
when the kernel is busy doing something else. To make sense these
actions are limited to a default of 5 or 6 seconds. Using Queued, the
evaluation is done in the usual way like when evaluating cells, that is
it is queued, and of course then the need for a timeout does not apply.
To learn more about this, read the tutorials for Dynamic.
> 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?".
This is a very common pitfall when using == which is in mathematica used
for mathematical equivalence and usualy is returned unevaluated when
either the right or lefthand side contain a symbol, which you can check
by evaluating this:
"input string" == $Canceled
Usually if you are not handling mathematical expression SameQ (===) is a
better choice, like:
"input string" === $Canceled
which will be evaluated to False. So the following should cure your
Style["LABEL", Black, 10, FontFamily -> "Arial Black"],
If[tag === $Canceled, NotebookWrite[nb,Cell[tag,"Text"]]],
Prev by Date:
Re: Database like "left join" or SAS like Merge function
Next by Date:
Previous by thread:
Button[label, action] - InputString?
Next by thread:
Mathematica 6 Automated Compatibility Tools