Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
    
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! –  Sjoerd C. de Vries Mar 18 '12 at 20:45
    
@SjoerdC.deVries Scary indeed but very powerful and often necessary :) –  Andy Ross Mar 18 '12 at 21:36

1 Answer 1

up vote 8 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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