MathGroup Archive 2010

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

Search the Archive

Re: Scoping constructs Block, Module, ModuleBlock

  • To: mathgroup at smc.vnet.net
  • Subject: [mg111533] Re: Scoping constructs Block, Module, ModuleBlock
  • From: Michael <michael2718 at gmail.com>
  • Date: Wed, 4 Aug 2010 05:50:46 -0400 (EDT)

On 7/26/2010 11:34 AM, John Fultz wrote:
> On Mon, 26 Jul 2010 11:06:56 -0700, Michael wrote:
>> I'm seeing a similar thing happen when I use DynamicModule:
>>
>> xyz = "A";
>> f[] := DynamicModule[{tmp = "A"},
>> CreateDialog[{
>> PopupMenu[Dynamic[tmp], {"A", "B", "C", "D"}],
>> PopupMenu[Dynamic[xyz], {"A", "B", "C", "D"}]
>> }]
>> ];
>> Button["Test", f[]]
>>
>> If I click on the "Test" button, I don't see the value of "tmp" being
>> changed when I pick different options from the pop up menu, but I *do*
>> see the value of "xyz" being changed when I pick different options from
>> its pop up menu.
>>
>> However, if I execute f[] directly, it works for both cases.  Shouldn't
>> clicking the button produce identical results to calling whatever is
>> defined for its action?  There seems to be something related to using a
>> dynamic module variable, perhaps it loses its definition during a Button
>> call or something.
>
> You need to read up on DynamicModule wormholes.
> [...]

Sorry, guess I wasn't specific enough about the problem.  I don't care 
about sharing the value of tmp outside the scope of the dialog box, I 
just want the dialog box's popup menu to reflect the value I select.

Turns out the solution was simple and does not involve dynamic 
wormholes: I apparently put the DynamicModule in the wrong place: 
outside the CreateDialog instead of *inside*. Switching the two gets this:

xyz = "A";
f[] := CreateDialog[
    DynamicModule[{tmp = "A"},
     Column[{
       PopupMenu[Dynamic[tmp], {"A", "B", "C", "D"}],
       PopupMenu[Dynamic[xyz], {"A", "B", "C", "D"}]
       }]
     ]];
Button["Test", f[]]

Now both pop-up menus behave the same.


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


Best Regards,

Michael


  • Prev by Date: Re: Issuing Function Calls within a Plot command
  • Next by Date: Re: Issuing Function Calls within a Plot command
  • Previous by thread: Re: AbsoluteTime and Daylight Saving Time
  • Next by thread: Deleting entries with zero in a table