9
$\begingroup$

I have a function which produces a large object I would like to hide. Formatting is of course an option but I'm hoping for something a little more meaningful using raster graphics and Tooltip.

Also, Format doesn't allow the object to be copied and pasted while retaining the internals of the object whereas MakeBoxes does.

Here is some sample code that produces what I want without the Tooltip.

f /: MakeBoxes[dat : f[args_], fmt_] :=
 TagBox[ToBoxes[Rasterize@RandomImage[1, {100, 100}]],
  InterpretTemplate[f[args] &], Editable -> False, Selectable -> True,
   SelectWithContents -> True]

f[1]

This produces the raster graphic with a Tooltip but the graphic is now editable/resizable.

f /: MakeBoxes[dat : f[args_], fmt_] :=
 TagBox[ToBoxes[
   Tooltip[Rasterize@RandomImage[1, {100, 100}], "tooltip"]],
  InterpretTemplate[f[args] &], Editable -> False, Selectable -> True,
   SelectWithContents -> True]

f[1]

Is there a way to have both a Tooltip and the non-editable raster graphic?

$\endgroup$
2
  • $\begingroup$ I always found the boxes stuff rather scary. There isn't really a thorough introduction into this matter in the documentation. This one here doesn't really count as such. And now you're introducing the undocumented InterpretTemplate. Yikes! $\endgroup$ Commented Mar 18, 2012 at 20:45
  • $\begingroup$ @SjoerdC.deVries Scary indeed but very powerful and often necessary :) $\endgroup$
    – Andy Ross
    Commented Mar 18, 2012 at 21:36

1 Answer 1

8
$\begingroup$

My colleague John Fultz suggested the following answer.

f /: MakeBoxes[dat : f[args_], fmt_] := 
 TagBox[ToBoxes[Rasterize@RandomImage[1, {100, 100}]], 
  InterpretTemplate[f[args] &], Editable -> False, Selectable -> True,
   SelectWithContents -> True, Tooltip -> "tooltip"]

After a bit of exploring I realized that I should have checked the Options for TagBox all along.

Options[TagBox]

==> {AutoDelete -> False, BaseStyle -> {}, 
 DefaultBaseStyle -> {}, DefaultTooltipStyle -> "TooltipLabel", 
 DeleteWithContents -> True, DeletionWarning -> False, 
 Editable -> Automatic, SelectWithContents -> False, 
 Selectable -> Automatic, StripWrapperBoxes -> False, 
 SyntaxForm -> Automatic, TagBoxNote -> None, Tooltip -> None, 
 TooltipDelay -> 0., TooltipStyle -> {}}

Hopefully someone else finds this useful.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.