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..."
|>]