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.

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?


1 Answer 1

up vote 6 down vote accepted

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)

Oh, you are good… So, let me get this straight: using FileNameSetter does not work, but FileNameSetter[##]& does? (as does FileNameSetter[#]&) How crazy! –  F'x Nov 9 '12 at 16:10
@F'x Yes, it's quite nasty ... a function should be a function regardless of which kind it is. It's just not nice that only a pure function works in this case ... but I can understand why: how would one detect in a reasonable way if a symbol can be considered a function or not? –  Szabolcs Nov 9 '12 at 16:29

This site is currently not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .