Not all functions seem to work with SetOptions. e.g.
SetOptions[Grid, BaseStyle -> Directive[Red]];
Grid[{{"hello", "world"}}]
hello world
the font is not red.
SetOptions[Row, BaseStyle -> Directive[Red]];
Row[{"hello", "world"}]
hello world
...and the font is red.

SetOptions[InputField, FieldSize -> 5];
InputField[Dynamic[x]]
the input field size is much larger than 5. But on the other hand
InputField[Dynamic[x], Sequence @@ Options[InputField]]
yields an input field with field size 5.

...and so on.
What is the easiest way to work out (i.e. make a list of ...) which functions can't be used with SetOptions?
Answer
As noted in the question, when you set an option to a function which appears not to work with SetOptions the options do get set, e.g. from the question:
InputField[Dynamic[x], Sequence @@ Options[InputField]]
but for whatever reason the global setting does not get used locally by default.
Another interesting case is this:
SetOptions[Grid, Background -> RGBColor[1, 0, 0]]
which returns a list of Grid options with the new Background, yet when you do the same with GridBox
SetOptions[GridBox, Background -> RGBColor[1, 0, 0]]
SetOptions::nspt: "SetOptions of GridBox is not supported"
So testing the actual "box form" seems to highlight the problem. In this case GridBox is not supported for SetOptions even though Grid did not return an error. So the following solution is a variation of what was provided to me by tech support. Check can be used to return something in the case of a SetOptions error:
Check[SetOptions[GridBox, "a" -> "b"], err, SetOptions::nspt]
SetOptions::nspt: "SetOptions of GridBox is not supported."
err
First get a list of names:
names = Names["System`*"]
test the names for the SetOptions error
list = Quiet[Map[Check[SetOptions[ToExpression[#], "a" -> "b"]; Null, #,
SetOptions::nspt] &, names]];
delete the Null elements
DeleteCases[list, Null]
{ActionMenuBox,AnimatorBox,CheckboxBox,ColorSetterBox,CounterBox,DynamicBox,
DynamicModuleBox,DynamicWrapperBox,GridBox,InputFieldBox,ItemBox,Line3DBox,LineBox,
LocatorBox,LocatorPaneBox,OpenerBox,OptionValueBox,OverlayBox,PaneBox,PanelBox,
PaneSelectorBox,Point3DBox,PointBox,PopupMenuBox,ProgressIndicatorBox,RadioButtonBox,
RectangleBox,RotationBox,SetterBox,Slider2DBox,SliderBox,TabViewBox,TemplateBox,
TogglerBox,TooltipBox,ValueBox}
So we have a list of 36 types of boxes that cannot be used with SetOptions.
Comments
Post a Comment