Message Boards Message Boards

How do I create an Object-Box such as returned as an xxxObject

I am picking up a question (https://community.wolfram.com/groups/-/m/t/793307) that has been raised before. However, I am unable to find any advice, workflow or template that would allow me to create my own Object-like Output. I would appreciate some guidance as to where and for which keywords I should search.

E.g. ColorData["Rainbow"] returns a ColorDataFunction. E.g. SparseArray[...] returns this when visualized with Show Expression:

Cell[BoxData[
 TagBox[
  TemplateBox[{
    RowBox[{
      StyleBox[
       TagBox["SparseArray", "SummaryHead"]....

Update & Summary:

First of all, thank you very much for the suggestions. I might be the last one in this community, but I finally have a rough idea how a SummaryBox is created and which WL functions make it work.

Below find some code, which relies mainly on two MSE contributions. I am interested in generating a dynamic text pane within a SummaryBox. The MSE contributors successfully addressed task. Still it is a pity that the functions Names["BoxForm`*Summary*"] are not documented by Wolfram.

Limiting window width of Summary Box

How to create expanding summary boxes like the ones displayed for InterpolatingFunction, ...

ClearAll[MyObject];

MyObject /: 
  MakeBoxes[obj : MyObject[asc_?myObjectAscQ], 
   form : (StandardForm | TraditionalForm)] :=
  Module[{above, below, len},
   above = {(*example grid*)
     {BoxForm`SummaryItem[{"Name: ", asc["Name"]}]},
     {BoxForm`SummaryItem[{"Variables: ", asc["Variables"]}],
      Column[{BoxForm`SummaryItem[{"Date: ", asc["Date"]}],
        BoxForm`SummaryItem[{"Length: ", 
          ToString@StringLength@asc["Response"]}]}]},
     {Pane[
       Row[{Style["Short: ", "SummaryItemAnnotation"], 
         asc["Response"] // Short}],
       {300, Automatic}, BaselinePosition -> Baseline]
      }
     };
   below = {(*example column*)
     {BoxForm`SummaryItem[{"Date: ", DateList[asc["Date"]]}]},
     {BoxForm`SummaryItem[{"Prompt: ", asc["Prompt"]}]},
     {BoxForm`SummaryItem[{"Metadata: ", asc[MetaInformation]}]},
     {Pane[
       Row[{Style["Long: ", "SummaryItemAnnotation"], 
         asc["Response"]}],
       {500, 60}, BaselinePosition -> Baseline, Scrollbars -> True]
      }
     };
   BoxForm`ArrangeSummaryBox[
    MyObject,(*head*)
    obj,(*interpretation*)
    $icon,(*icon, use None if not needed*)
    (*above and below must be in a format suitable for Grid or Column*)
    above,(*always shown content*)
    below,(*expandable content*)
    form,
    "Interpretable" -> Automatic
    ]
   ];
myObjectAscQ[asc_?AssociationQ] := 
 AllTrue[{"Name", "Variables", "Date", "Prompt", "Length", "Response",
    MetaInformation}, KeyExistsQ[asc, #] &]
myObjectAscQ[_] = False;

MyObject[asc_?AssociationQ][prop_] := Lookup[asc, prop]

A simple icon

$icon =
  Graphics[{Red, Disk[]},
   ImageSize -> Dynamic[{(*this seems to be the standard icon size*)
      Automatic,
      3.5 CurrentValue["FontCapHeight"]/
        AbsoluteCurrentValue[Magnification]
      }]
   ];

Generating the summary box

MyObject[<|
  "Name" -> "My particular object",
  "Length" -> 10,
  "Variables" -> {a, b, c},
  "Date" -> Today,
  "Prompt" -> "Where is this city?",
  "Response" -> 
   StringTake[ExampleData[{"Text", "DeclarationOfIndependence"}], 500],
  MetaInformation -> "more info..."
  |>]
4 Replies

I found this on MSE.

POSTED BY: Rohit Namjoshi

I found a way to do this some 8 years ago. Completely forgot how I did it, but it is immortalized in the code of my StackEchange answer here where, somewhere at the bottom of the code, an object box is created.

POSTED BY: Sjoerd de Vries

Hi thanks for the suggestion. The Objects I referred to provide a lot of functionality. Eg they store accessible information (+ symbol, „ name“) and the object/box can be used as input!

Posted 1 year ago

Maybe Iconize will work for you?

Iconize[RandomInteger[{-50, 50}, 100], "Some integers"]

Or:

enter image description here

POSTED BY: Hans Milton
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract