Re: Palettes
- To: mathgroup at smc.vnet.net
- Subject: [mg9229] Re: [mg9163] Palettes
- From: Allan Hayes <hay at haystack.demon.co.uk>
- Date: Fri, 24 Oct 1997 01:00:44 -0400
- Sender: owner-wri-mathgroup at wolfram.com
Shashidhar N S <shashi at cc.UManitoba.CA> [mg9163] Palettes
writes
> I am trying to set up a simple palette which displays filenames and
> "Gets" whatever file is clicked upon. I would appreciate help on
> doing this.
> I find the settings ButtonFunction, ButtonData, etc very confusing.
Shashidhara:
I am assuming that you want a palette with file names on the buttons
that, when a button is clicked, "Gets" the file named on it.
We need to make arrange that clicking the button enters the expression
Get["file path"]
(the necessary file path may be much longer than your name for the
file -- it can be found and pasted in by using the menu, Input>Get
File Path ...)
All we need do is make Get["file path"] the ButtonFunction and set up
the button so as to evaluate it when clicked - we don't need to use
ButtonData, Button Source ... for this.
Here is the *cell expression* for a cell containing the button.
GET FILE
Cell[BoxData[
ButtonBox[
RowBox[{"get", " ", "file"}], (*text shown on button*)
ButtonFunction:>Get["file path"], (*button function*)
ButtonEvaluator->Automatic, (*evaluator of button function*)
Active->True]], (*makes the button evaluate when clicked*)
"Input"]
(To make the button
-- make an empty input cell,
-- show its cell expression (use menu Format>ShowExpression)
-- replace the cell expression with the code given
-- use Format>ShowExpression again. )
We could have defined the expression to be evaluated outside: getfile :=
Get[ "file path"]
and used ButtonFunction:>getfile in the cell expression above. This
can be connvenient since in the cell expression we have to use fuller
forms, like CompoundExpression[a,b,c] for a;b;c.
Any expression can be used as the ButtonFunction.Here are some more
related examples:
DISPLAY FILE
Cell[BoxData[
ButtonBox[
RowBox[{"display", " ", "file"}],
ButtonFunction:>
ToExpression[ "!!file path"], (*trick!*)
ButtonEvaluator->Automatic,
Active->True]], "Input"]
LOAD PACKAGE
Cell[BoxData[
ButtonBox[
RowBox[{"load", " ", "package"}],
ButtonFunction:>Get[ "Graphics`Arrow`"],
ButtonEvaluator->Automatic,
Active->True]], "Input"]
OPEN NOTEBOOK
Cell[BoxData[
ButtonBox[
RowBox[{
RowBox[{"open", " ", "notebook"}], " "}],
ButtonFunction:>NotebookOpen[ "file path"],
ButtonEvaluator->Automatic,
Active->True]], "Input"]
OPEN COPY OF NOTEBOOK
Cell[BoxData[
ButtonBox[
RowBox[{
RowBox[{"open", " ", "copy", " ", "of", " ", "notebook"}], " "}],
ButtonFunction:>NotebookPut[
Get[ "file path"]],
ButtonEvaluator->Automatic,
Active->True]], "Input"]
Where do * ButtonData and Button Source* come in? They are used so
that the button function can access information:
We can set
ButtonData -> buttondata (any expression) and
ButtonSource -> to ButtonContents, ...
(please look up ButtonSource in the Help browser).
Now, if take a pure function like say F[#1,#2]&, as the button function:
ButtonFunction :> (F[#1,#2]&) (*brackets essential*)
Then, on clicking the button we evaluate
F[#1,#2]&[sourcedata, buttondata]
where sourcedata is determined by what we have set for ButtonSource.
You can, of course use the menu items Input>Create Button, Input> Edit
Button and Format>Option Inspector... to so some of this. Incidentally
the choosing a button styles from Create Button (Paste, Evaluate,..)
automatically sets up the appearence and function of the button. You
wont see the details in the cell expression, just the style option
chose ButtonStyle->"Paste", or ButtonStyle->"Evaluate" ..... But,
in the Option Inspector you will find the button function (maybe
looking rather bewildering because of using "Front End" functions
rather than the regular ones)
Allan Hayes
hay at haystack.demon.co.uk
http://www.haystack.demon.co.uk/training.html voice:+44 (0)116 2714198
fax: +44 (0)116 2718642
Leicester, UK