Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #9244 > unrolled thread

DialogInput in ButtonFunction

Started byJakob Ebner <jakob.ebner@gmail.com>
First post2012-03-28 05:34 +0000
Last post2012-03-30 09:40 +0000
Articles 3 — 3 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  DialogInput in ButtonFunction Jakob Ebner <jakob.ebner@gmail.com> - 2012-03-28 05:34 +0000
    Re: DialogInput in ButtonFunction A Retey <awnl@gmx-topmail.de> - 2012-03-29 08:10 +0000
    Re: DialogInput in ButtonFunction John Fultz <jfultz@wolfram.com> - 2012-03-30 09:40 +0000

#9244 — DialogInput in ButtonFunction

FromJakob Ebner <jakob.ebner@gmail.com>
Date2012-03-28 05:34 +0000
SubjectDialogInput in ButtonFunction
Message-ID<jku7t5$8jn$1@smc.vnet.net>
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?
Best wishes, Jakob

[toc] | [next] | [standalone]


#9285

FromA Retey <awnl@gmx-topmail.de>
Date2012-03-29 08:10 +0000
Message-ID<jl15de$lgd$1@smc.vnet.net>
In reply to#9244
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. 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

[toc] | [prev] | [next] | [standalone]


#9307

FromJohn Fultz <jfultz@wolfram.com>
Date2012-03-30 09:40 +0000
Message-ID<jl3v38$3n5$1@smc.vnet.net>
In reply to#9244
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@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
>

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web