For Programmers: Free Programming Magazines  


Home > Archive > Mathematica > November 2007 > Dynamic Timeout









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Dynamic Timeout
thomas

2007-11-21, 4:42 am

Hello Mathgroup,

I have created my own custom Toolbar (DockedCell) with some shortcuts
and buttons that I frequently use. One of the items in the toolbar is
an ActionMenu which contains calls to some of my own functions. In one
of these functions, SystemDialogInput[] is called, with which I can
select a subdirectory on my hard drive.

ActionMenu is implemented as a Dynamic[] object in Mathematica;
therefore, whatever action is triggered by choosing one of the
entries, is subject to the Timeout "feature" of Dynamic[] evaluations.
That means that if I am not fast enough when picking my directory,
nothing will happen, since the call has timed out. Setting the option
SynchronousUpdating->False does not help.

What does help is to increase the Timeout-time by setting
SetOptions[$FrontEnd,DynamicEvaluationTi
meout->10000] or some other
high number.

My problem is: I do not usually want the timeout to be that large, the
normal setting of 5 or 6 seconds is quite reasonable. What I can do,
then, is to automatically re-set DynamicEvaluationTimeout to 6 at the
end of the function - that works. What does NOT work, however, is to
set it to 10000 at the beginning of the function. (Actually, it does
work, but it does not take effect yet for the currently evaluating
Dynamic[] within which it was set to 10000.)

So, the question is: how do I avoid the timeout in this case, without
generally increasing the timeout time?

thomas

p.s. A very easy work-around is to call my function with the help of a
button, instead of using an action menu. This avoids "Dynamic" and the
problem doesn't even show up. Nevertheless, I think it should be
possible to do such things from within an action menu (or from within
other dynamic constructs)

Thomas Muench

2007-11-22, 8:17 am

John,

Thank you for your reply, it works very nicely. I experimented with it
a little bit, and found that it is also quite easy to automatically
re-set the DynamicEvaluationTimeout to a shorter time:

EventHandler[ActionMenu["menu",
{"file" :>
(Print[SystemDialogInput["FileOpen"]];SetOptions[$FrontEnd,
DynamicEvaluationTimeout -> 6])
}], {"MouseDown" :> SetOptions[$FrontEnd, DynamicEvaluationTimeout
-> 1000]}, PassEventsDown -> True]

Sincerly,
thomas

On Nov 22, 2007 2:36 AM, John Fultz <jfultz@wolfram.com> wrote:
> I just posted a response to another user with a similar, and fortunately, more
> soluble problem than what you're dealing with. In the case of Button[], the
> same problem does arise, but it would be trivially resolvable by setting the
> Method->"Queued" option. Clearly, ActionMenu ought to have a similar Method
> option. In version 6, it does not, but it's certainly on our radar for future
> releases.
>
> You can work around it by wrapping an EventHandler[] around your ActionMenu[]
> which resets the DynamicEvaluationTimeout. The below example is not elegant and
> does not restore the DynamicEvaluationTimeout, but it gives you an idea of how
> to proceed.
>
> EventHandler[
> ActionMenu[
> "menu", {"file" :>
> Print[SystemDialogInput["FileOpen"]]}], {"MouseDown" :>
> SetOptions[$FrontEnd, DynamicEvaluationTimeout -> 1000]},
> PassEventsDown -> True]
>
> Sincerely,
>
> John Fultz
> jfultz@wolfram.com
> User Interface Group
> Wolfram Research, Inc.
>
>
> On Wed, 21 Nov 2007 02:56:41 -0500 (EST), thomas wrote:
>
>
>


John Fultz

2007-11-23, 4:38 am

I just posted a response to another user with a similar, and fortunately, more
soluble problem than what you're dealing with. In the case of Button[], the
same problem does arise, but it would be trivially resolvable by setting the
Method->"Queued" option. Clearly, ActionMenu ought to have a similar Method
option. In version 6, it does not, but it's certainly on our radar for future
releases.

You can work around it by wrapping an EventHandler[] around your ActionMenu[]
which resets the DynamicEvaluationTimeout. The below example is not elegant and
does not restore the DynamicEvaluationTimeout, but it gives you an idea of how
to proceed.

EventHandler[
ActionMenu[
"menu", {"file" :>
Print[SystemDialogInput["FileOpen"]]}], {"MouseDown" :>
SetOptions[$FrontEnd, DynamicEvaluationTimeout -> 1000]},
PassEventsDown -> True]

Sincerely,

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


On Wed, 21 Nov 2007 02:56:41 -0500 (EST), thomas wrote:
> Hello Mathgroup,
>
> I have created my own custom Toolbar (DockedCell) with some shortcuts
> and buttons that I frequently use. One of the items in the toolbar is
> an ActionMenu which contains calls to some of my own functions. In one
> of these functions, SystemDialogInput[] is called, with which I can
> select a subdirectory on my hard drive.
>
> ActionMenu is implemented as a Dynamic[] object in Mathematica;
> therefore, whatever action is triggered by choosing one of the
> entries, is subject to the Timeout "feature" of Dynamic[] evaluations.
> That means that if I am not fast enough when picking my directory,
> nothing will happen, since the call has timed out. Setting the option
> SynchronousUpdating->False does not help.
>
> What does help is to increase the Timeout-time by setting
> SetOptions[$FrontEnd,DynamicEvaluationTi
meout->10000] or some other
> high number.
>
> My problem is: I do not usually want the timeout to be that large, the
> normal setting of 5 or 6 seconds is quite reasonable. What I can do,
> then, is to automatically re-set DynamicEvaluationTimeout to 6 at the
> end of the function - that works. What does NOT work, however, is to
> set it to 10000 at the beginning of the function. (Actually, it does
> work, but it does not take effect yet for the currently evaluating
> Dynamic[] within which it was set to 10000.)
>
> So, the question is: how do I avoid the timeout in this case, without
> generally increasing the timeout time?
>
> thomas
>
> p.s. A very easy work-around is to call my function with the help of a
> button, instead of using an action menu. This avoids "Dynamic" and the
> problem doesn't even show up. Nevertheless, I think it should be
> possible to do such things from within an action menu (or from within
> other dynamic constructs)




John Fultz

2007-11-23, 4:38 am

A better solution (i.e. one that never touches the global value of
DynamicEvaluationTimeout) than EventHandler[] would be to set
DynamicEvaluationTimeout using Style.

E.g.,

Style[ActionMenu[...], DynamicEvaluationTimeout->1000]

Mea culpa. I plead temporary insanity while trying to get home for
Thanksgiving. Thanks to Carl Woll for the prod about this.

Sincerely,

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


On Wed, 21 Nov 2007 19:36:59 -0600, John Fultz wrote:[color=darkred]
> I just posted a response to another user with a similar, and fortunately,
> more
>
> soluble problem than what you're dealing with. In the case of Button[],
> the
> same problem does arise, but it would be trivially resolvable by setting
> the
> Method->"Queued" option. Clearly, ActionMenu ought to have a similar
> Method
> option. In version 6, it does not, but it's certainly on our radar for
> future
> releases.
>
> You can work around it by wrapping an EventHandler[] around your
> ActionMenu[]
> which resets the DynamicEvaluationTimeout. The below example is not
> elegant and
> does not restore the DynamicEvaluationTimeout, but it gives you an idea
> of how
> to proceed.
>
> EventHandler[
> ActionMenu[
> "menu", {"file" :>
> Print[SystemDialogInput["FileOpen"]]}], {"MouseDown" :>
> SetOptions[$FrontEnd, DynamicEvaluationTimeout -> 1000]},
> PassEventsDown -> True]
>
> Sincerely,
>
> John Fultz
> jfultz@wolfram.com
> User Interface Group
> Wolfram Research, Inc.
>
>
> On Wed, 21 Nov 2007 02:56:41 -0500 (EST), thomas wrote:



m.r@inbox.ru

2007-11-24, 4:40 am

On Nov 21, 2:13 am, thomas <thomas.mue...@gmail.com> wrote:
> Hello Mathgroup,
>
> I have created my own custom Toolbar (DockedCell) with some shortcuts
> and buttons that I frequently use. One of the items in the toolbar is
> an ActionMenu which contains calls to some of my own functions. In one
> of these functions, SystemDialogInput[] is called, with which I can
> select a subdirectory on my hard drive.
>
> ActionMenu is implemented as a Dynamic[] object in Mathematica;
> therefore, whatever action is triggered by choosing one of the
> entries, is subject to the Timeout "feature" of Dynamic[] evaluations.
> That means that if I am not fast enough when picking my directory,
> nothing will happen, since the call has timed out. Setting the option
> SynchronousUpdating->False does not help.
>
> What does help is to increase the Timeout-time by setting
> SetOptions[$FrontEnd,DynamicEvaluationTi
meout->10000] or some other
> high number.
>
> My problem is: I do not usually want the timeout to be that large, the
> normal setting of 5 or 6 seconds is quite reasonable. What I can do,
> then, is to automatically re-set DynamicEvaluationTimeout to 6 at the
> end of the function - that works. What does NOT work, however, is to
> set it to 10000 at the beginning of the function. (Actually, it does
> work, but it does not take effect yet for the currently evaluating
> Dynamic[] within which it was set to 10000.)
>
> So, the question is: how do I avoid the timeout in this case, without
> generally increasing the timeout time?
>
> thomas
>
> p.s. A very easy work-around is to call my function with the help of a
> button, instead of using an action menu. This avoids "Dynamic" and the
> problem doesn't even show up. Nevertheless, I think it should be
> possible to do such things from within an action menu (or from within
> other dynamic constructs)


You can set DynamicEvaluationTimeout -> 10000. as an option for a
single cell:

Style[ActionMenu[
"menu", {"file" :> Print[SystemDialogInput["FileOpen"]]}],
DynamicEvaluationTimeout -> 10000.]

SetOptions[EvaluationNotebook[],
DockedCells -> Cell[
BoxData@ ToBoxes@
ActionMenu["menu",
{"file" :> (tmp = SystemDialogInput["FileOpen"])}],
DynamicEvaluationTimeout -> 10000.]]

Maxim Rytin
m.r@inbox.ru

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com