In a Manipulate, one can specific the type of an individual control like so:
Manipulate[v, {v, Red, ColorSetter}]
I tried to do the same with FileNameSetter, i.e.
Manipulate[v, {v, "no file chosen", FileNameSetter}]
but that doesn't work, and the control is a slider. I can work around the issue like so:
Manipulate[{v, FileNameSetter[Dynamic[v]]}, {v, "no file chosen"},
ControlType -> None]
but I would rather understand why my second example above doesn’t behave as expected. Do you have any idea?
Answer
Manipulate does not directly support a control type called "FileNameSetter", but fortunately it is possible to use custom controls (both in Manipulate and other functions), as described e.g. in the Control documentation:
{u,func}an arbitrary control from a function
The trick to getting it working is that func must be a pure function. This is mentioned in the Advanced Manipulate Tutorial, in the section showing how to build a custom slider.
So, somewhat unusually, Control[{v, FileNameSetter}] will not work, but Control[{v, FileNameSetter[##]&}] will. The equivalent construction using Manipulate would be:
Manipulate[v, {{v, "none"}, FileNameSetter[##] &}]
(Of course things would be much simpler if Manipulate would just support FileNameSetter directly as it does ColorSetter)
Comments
Post a Comment