FrontEnd trouble
- To: mathgroup@smc.vnet.net
- Subject: [mg11937] FrontEnd trouble
- From: "jmt" <jmt@tea.fr.eu.org>
- Date: Thu, 9 Apr 1998 00:33:45 -0400
The following behaviour of Mathematica 3.0 FrontEnd is surprising and
quite annoying:
In a notebook I define a button, the purpose of which is to start or
stop a MathLink link; the button changes when clicked: green with
"Start link" text on it, red with "Stop link" on it; as far as this
button is not standard, I need to edit it in the "Show Expression" mode
(CTRL-Shift-E. This is the button:
Cell[BoxData[
ButtonBox[
RowBox[{"Starts", " ", "link"}],
tonFunction:>CompoundExpression[
Get[ "StartsEndsButton`"],
StartsEndsButton`StartsEndsFunction, externalFunction],
ButtonEvaluator->Automatic,
ButtonData:>"should changes its color",
Active->True,
ButtonStyle->None,
Background->RGBColor[0, 1, 0],
ButtonNote->"changes its color when clicked"]], "Input",
CellLabel->"In[3]:=",
Editable->False,
Evaluatable->False,
GeneratedCell->True,
CellTags->"StartsEndsButton"]
To fully understand the question, I precise that StartsEndsButton is a
package with a unique function called StartsEndsFunction. The package
has been tested Okay. "externalFunction" stands for a function defined
in the Global` context. The Button evaluator is the Kernel, not the
FrontEnd.
To test the button, I start a new kernel, define the working directory
(because the package is not yet referenced in $Path or in the
Applications Directory), evaluate the definition of the external
function and finally click on my button. Wonderful, its WORKS! Let's
save everything and have a cup of tea. BUT if now I want to have a look
at the Mathematica expression of the button, I get:
Cell[BoxData[
(etc.)
Get[ "StartsEndsButton`"], StartsEndsFunction,
externalFunction],
(etc.)]
which means that next time I will start a new kernel, set the working
directory, etc. and press the button, I will get an error message
because the kernel will define StartsEndsFunction in the global context
before reading the package (I have had a look at the note in The
Mathematica Book Section 2.6.10 that explains the mechanism of order of
creation of symbols).
My questions are now:
1- A FrontEnd question : Why does the cell associated with the button is
modified, even when the cell is not editable; and who did it (the
Kernel, the FrontEnd), according to which rules, and when ? 2- A
general programming question : In case I could not get an answer to the
previous question, how can I write a function that reads a package and
calls a function in the package context all at the same time?
With many thanks,
**************************************** Jean-Marie THOMAS
Conseil et Audit en Inginierie de Calcul Strasbourg, France
****************************************