Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: ProgressIndicator inside DynamicModule

  • To: mathgroup at smc.vnet.net
  • Subject: [mg109843] Re: ProgressIndicator inside DynamicModule
  • From: Leonid Shifrin <lshifr at gmail.com>
  • Date: Wed, 19 May 2010 20:13:57 -0400 (EDT)

Hi Istvan,

Alas, can not answer your questions properly, but the following modification
of your code
seems to also work fine:

DynamicModule[{range == {0, 100}, sw == False},
 Module[{pr == 0},
  Grid@{{
     Button["Push me",
      (sw == True;
       Do[pr == i; Pause[.02];, {i, range[[1]], range[[2]]}];
       sw == False;), Method -> "Queued"],
     Dynamic@ProgressIndicator[pr, range],
     Dynamic@pr,
     Dynamic@Switch[sw,
       True, "Calculating...",
       False, "Finished.",
       _, "Standing by."]}}]]

The issue seems to be with the <pr> variable.  My guess is that by
localizing <pr> with DynamicModule vs plain Module or not localizing at all,
you somehow indicate to Dynamic that <pr> is going to change due to Dynamic
updating, so  Dynamic does not track its possible changes by other means
(like by explicit assignments in a loop that you have).  My guess is
supported by observing that  once you localize with DynamicModule,

1. Dynamic@ProgressIndicator[pr, range], works while
ProgressIndicator[Dynamic[pr], range] does not

2. Consider the following  modification:

ClearAll[f];
DynamicModule[{pr == 0, range == {0, 100}, sw == False},
 Grid@{{
    Button["Push me",
     (sw == True;
      Do[pr == i; Pause[.02];, {i, range[[1]], range[[2]]}];
      sw == False;), Method -> "Queued"],
    Dynamic@ProgressIndicator[pr, range],
    Dynamic[f[pr]],
    Dynamic@Switch[sw,
      True, "Calculating...",
      False, "Finished.",
      _, "Standing by."]}}]

You will observe that now the value of <pr> inside <f> is being properly
updated inside Dynamic during the run of your code. In particular, by using
f[x_]:==x, you can get back the desired result  - you can even localize <f>
as well as put this definition inside the same DynamicModule (although this
is certainly a hack). In both cases, we replaced Dynamic[pr] with something
else, which apparently made Dynamic properly update the output. Of course,
my observations  at best somewhat clarify "how", but not "why" - hopefully
others will have more to say here.

Hope this helps.

Regards,
Leonid



2010/5/19 Zachar Istv=E1n <replicatorzed at gmail.com>

> Dear Group,
>
> dealing with dynamic functions is very frustrating: every now and then
> a problem appears, which is totally against my previous experience and
> knowledge, and I am simply not able to resolve it. Here is a new one,
> any help would be welcome.
>
> Why does ProgressIndicator won't work inside DynamicModule, where
> 1. it works without enclosing the Grid in DynamicModule,
> 2. the 'sw' switch is correctly displayed (but not 'pr').
> ??
>
> DynamicModule[
>  {pr == 0, range == {0, 100}, sw == False},
>  Grid@{{
>    Button["Push me",
>     (sw == True;
>      Do[pr == i; Pause[.02];, {i, range[[1]], range[[2]]}];
>      sw == False;), Method -> "Queued"],
>    Dynamic@ProgressIndicator[Dynamic@pr, range],
>    Dynamic@pr,
>    Dynamic@Switch[sw, True, "Calculating...", False, "Finished.", _,
> "Standing by."]
>    }}
>  ]
>
>
> Thanks in advance
> Istvan
>
>


  • Prev by Date: Re: ProgressIndicator inside DynamicModule
  • Next by Date: Evaluate to...
  • Previous by thread: Re: ProgressIndicator inside DynamicModule
  • Next by thread: Re: ProgressIndicator inside DynamicModule