Re: Clickable options
- To: mathgroup at smc.vnet.net
- Subject: [mg99622] Re: Clickable options
- From: Bob F <deepyogurt at gmail.com>
- Date: Sat, 9 May 2009 03:23:09 -0400 (EDT)
- References: <gtnjqr$3e9$1@smc.vnet.net> <gtrl4a$1pp$1@smc.vnet.net>
On May 7, 10:13 pm, Thomas M=FCnch <thomas.mue... at gmail.com> wrote:
> [From former thread: Introducing the Wolfram Mathematica Tutorial
> Collection]
>
> > Another user interface issue I would like to see -- it would be so
> > nice to have some sort of "auto completion" mode your could turn on or
> > off as you needed -- perhaps a template of the command as you type.
> > Something that would supply the complete command and you simply change
> > it as you go to fit your needs, plus once you have the basic command,
> > there should be some way to modify it by perhaps right-clicking and
> > have all the optional parameters displayed and you pick and choose
> > which are needed. This would be so much more productive than looking
> > up the command in the DC, reading thru pages and pages of options
> > sometimes and finally finding the one that is needed, and then back to
> > the notebook and type in the just found optional parameter.
>
> > -Bob
>
> Dear Bob -
>
> there IS an autocompletion function - simply press Ctrl-K after the
> first couple of characters of your function name.
>
> As for the options of a function: Here is a nifty little routine that
> I have written to do just what you want. Execute the following code,
> which will create a small palette with 2 buttons. Then, highlight a
> function name in your notebook (or simply have your cursor within or
> directly after the function name, for example "Plot"), and press one
> of the buttons. You will get another palette with all the options of
> your function. Clicking one of the options will insert it into your
> notebook (together with a preceding comma), including the default
> value, which will be highlighted so that you can immediately start
> typing to replace it with your value of choice, or keep clicking on as
> many options as you want. Clicking on the question mark next to an
> option will open the appropriate help page in the Documentation
> Center. Clicking on the function name at the top of the palette will
> open the function's help page.
>
> Normally, the button 'Options (tooltips)' will be the preferred
> choice, as you will get informative tooltips in your palette which
> show you the default value of the option (when hovering over the
> option name), and the usage of the option (when hovering over the
> question mark). However, some functions have an enormous amount of
> options. Try, for example, 'CreateWindow'. Then it can take quite some
> time (several seconds) to create the Options palette. But, the added
> benefit of the tooltips might be worth the wait.
>
> If you call the options for another function while an option palette
> is still open, the currently open palette will be replaced by the new
> one in a way that the top right corner of the new palette window is at
> the same position as the previous one. To implement this, I save the
> option palette notebook object in the global variable
> $optionPaletteCreatedByThisFunction. (This behavior is a feature, as
> people might want to move the palette to a second screen, and want it
> to remember the position when they call the options for another
> function). However, I am not sure that this is the perfect way to
> implement it. If you move a wide palette window (many options, e.g.
> for 'CreateWindow') off to the side, so that its right corner is far
> off-screen, and call a narrow window (with few options, e.g.
> 'Column'), the new window will be invisible. Maybe someone has a
> better idea.
>
> Version restriction: This works only for version 7, as I am using
> scroll bars within 'Pane'. It does sort of work with version 6, but
> not really.
>
> Note: The original idea for this came from Syd Geraghty, who should be
> acknowledged for his work. We worked together to improve the
> functionality of the code.
>
> Here is the code:
>
> makeOptionsButton[tooltips_: True] :=
> Button[If[tooltips, "Options (tooltips)", "Options (no tooltips)"],
> Module[{fun, clen, len, buttons, title, columns, opts,
> maxPanelHight = 800, windowPos, insert,
> maximumNumberOfColumns = 3, tooltipfunction},
> tooltipfunction =
> If[tooltips, # &,
> First];(*determines whether or not to show tooltips*)
>
> (*Extract the currently selected funtion*)
> SelectionMove[InputNotebook[], All, Word];
> fun = ToExpression@ NotebookRead[InputNotebook[]];
> SelectionMove[InputNotebook[], After, Word];
> If[Head[fun] =!= Symbol, Return[]];
>
> opts = Options[fun]; (*read the options*)
> len = Length[opts];
> columns = Max[1, Min[maximumNumberOfColumns, Ceiling[len/30]]];
> clen = Ceiling[len, columns];(*some numbers for formatting*)
>
> (*This is the function that inserts the option into the notebook \
> when the button is pressed, and selects the option value*)
> insert[
> option_] := (NotebookWrite[InputNotebook[],
> RowBox[{",", ToBoxes[option[[1]]],
> StringJoin["\[", ToString@Head@option, "]"]}]];
> NotebookWrite[InputNotebook[], ToBoxes[option[[2]]], All]);
>
> If[len > 0,
> (* If fun has Options: *)
> buttons =
> Grid[{{tooltipfunction@
> Tooltip[
> ReleaseHold@
> MakeExpression@
> ButtonBox["\" ? \"",
> ButtonData ->
> "paclet:ref/" <> ToString[Evaluate[#[[1]]=
]],
> Appearance -> "Palette", BaseStyle -> "Lin=
k",
> ButtonFrame -> None], Evaluate[#[[1]]]::us=
age],
> tooltipfunction@
> Tooltip[
> Button[#[[1]], insert[#], Alignment -> Left,
> Appearance -> "Palette"],
> Column[{"Default value:", #}]]}}] & /@
> opts;(*For each option,
> create a 'help' button and a button for pasting the option*)
> buttons =
> Grid[Partition[PadRight[buttons, clen, ""],
> clen/columns]\[Transpose], Spacings -> {0, 0.05},
> Alignment -> Left];(*arrange into a Grid*)
> title =
> "Options for " <> ToString@fun <> " (Click option to inser=
t)",
>
> (* If fun does not have any Options: *)
> buttons =
> Style[ToString[fun] <> " does not have any Options", Bold,
> White];
> title = "Usage of " <> ToString@fun
> ];
>
> (*Some code to keep the upper right corner of the new options \
> palette window identical to the currently open one.*)
> With[{test =
> AbsoluteOptions[$optionPaletteCreatedByThisFunction,
> WindowMargins]},
> windowPos =
> If[Head[test] === List, test[[1, 2]], {{0, 0}, {0, 0}}];
> windowPos[[All, 1]] = Automatic];
>
> (*This closes the previous Options Pallette*)
> NotebookClose[$optionPaletteCreatedByThisFunction];
>
> (*This creates a new palette and assigns it to the global variable
> \
> $optionPaletteCreatedByThisFunction*)
> $optionPaletteCreatedByThisFunction =
> CreateWindow[
> PaletteNotebook[
> Column[{Tooltip[
> ToExpression@
> ButtonBox[Style[ToString[fun] <> " =BB", Bold],
> ButtonData -> "paclet:ref/" <> ToString[fun],
> BaseStyle -> "Link", ButtonFrame -> None],
> ToExpression[ToString[fun] <> "::usage"]],
> Pane[buttons, ImageSize -> {Automatic, {maxPanelHight}},
> Scrollbars -> Automatic]}], ShowStringCharacters -> Fa=
lse,
> WindowTitle -> title, Saveable -> False,
> WindowMargins -> windowPos]];
> ]]
>
> CreatePalette[Row[makeOptionsButton /@ {True, False}],
> Saveable -> False, WindowTitle -> "Options for selected function"];
Very interesting. Thanks very much. I like that it gives all the
options for a routine, but it doesn't show all the possible values for
each of the options. Have you seen anything that also has that?
-Bob