Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: DialogInput in ButtonFunction

  • To: mathgroup at smc.vnet.net
  • Subject: [mg125735] Re: DialogInput in ButtonFunction
  • From: John Fultz <jfultz at wolfram.com>
  • Date: Fri, 30 Mar 2012 04:37:24 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <jku7t5$8jn$1@smc.vnet.net> <201203290805.DAA21956@smc.vnet.net>

On Mar 29, 2012, at 3:05 AM, A Retey wrote:

> Am 28.03.2012 07:34, schrieb Jakob Ebner:
>> I would like to impement something like the following into the
>> function of a button which needs the returned value for further
>> evaluation.
>>
>> DialogInput[{
>>   InputField[Dynamic[dyn], String],
>>   FileNameSetter[Dynamic[dyn]],
>>   Button["Ok", DialogReturn[dyn]]
>>   }]
>>
>> Now I encounter two problems:
>> i) calling DialogInput or CreateDialog whithin a button causes my
>> Mathematica session to crash.
>>
>> ii) if this would work I also have the problem that the browse button
>> won`t work because the evaluation in the main notebook is halted.
>>
>> Any Suggestions?
>
> you need to set the Method of the Button to "Queued", that should save
> you from the crashes. AFAIK you also can't nest two modal dialogs, so
> when you insist on using FileNameSetter (which I tink calls such a
> dialog) then you can't use DialogInput.

Actually, what's going on behind the scenes is that FileNameSetter[] is basically implemented as a button with "Queued".  But, Method->"Queued" means that the evaluation will go to the back of the same queue that's used by Shift+Enter.  Problem is that the Shift+Enter evaluation queue is held up waiting for DialogInput[] to return an answer.

For computer science types, it's a classic deadlock situation (A depends on B finishing, B depends upon A finishing).

So using any Button with Method->"Queued" inside of DialogInput will lead to the same problem, unfortunately. This is one of those rare cases where it might be quite acceptable to use the preemptive method and change the DynamicEvaluationTimeout of a control to a very long timeout. Something like:

FileNameSetter[Dynamic[val], =
BaseStyle->{DynamicEvaluationTimeout->1000}]

I haven't tried this, but I think it should work fine. However, the other solution proposed here using CreateDialog is probably preferable, assuming that it's not necessary to return the result inline in the way that DialogInput does.

Sincerely,

John Fultz
jfultz at wolfram.com
User Interface Group
Wolfram Research, Inc.

> An alternative is to use
> CreateDialog and delay the Set (and all following code) to the
> DialogReturn, which will of course not be run when the user closes the
> window without clicking the OK button:
>
> Button["set filename",
>  CreateDialog[{
>    InputField[Dynamic[dyn], String],
>    FileNameSetter[Dynamic[dyn]],
>    Button["Ok", DialogReturn[filename = dyn]]
>    }],
>  Method -> "Queued"
>  ]
>
> of course you could just as well do:
>
> Button["set filename",
>   filename = SystemDialogInput["FileOpen"],
>   Method -> "Queued"
> ]
>
> hth,
>
> albert
>




  • Prev by Date: Re: PC auto-simplifies output, but mac doesn't
  • Next by Date: Re: Typesetting in Mathematica (TraditionalForm typesetting?)
  • Previous by thread: Re: DialogInput in ButtonFunction
  • Next by thread: Manipulate[Plot[Evaluate[expr]]]