MathGroup Archive 2008

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

Search the Archive

Re: Use of RuleDelayed in PaneSelector

  • To: mathgroup at smc.vnet.net
  • Subject: [mg91146] Re: Use of RuleDelayed in PaneSelector
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Thu, 7 Aug 2008 04:41:22 -0400 (EDT)
  • References: <g7bqtd$mrh$1@smc.vnet.net>

Hi,

> I'm trying to implement a potentially infinite GUI tree control using
> PaneSelector's and Opener's.
> The issue is that I use RuleDelayed in the PaneSelector's first
> argument to make the contents of panels lazy, so that the contents
> would be constructed only when the corresponding panel is activated.
> For example:
> 
> {Toggler[Dynamic[x]],  PaneSelector[{False -> "Inactive", True :>
> Print["Activated!"]},   Dynamic[x]]}
> 
> I want this to produce a widget that prints "Activated!" each time x
> transitions to True. However, all I get is an expression
> Print["Activated!"].
> If I wrap it into Evaluate[], I get "Activated!" printed immediately
> and only once.
> 
> How should this code be written to satisfy the condition above?

The following works, although I'm not sure whether I would recommend to
build on it. The trick is to use Dynamic in the content of the pane
selector and make x appear within that dynamic, so we use x as a dummy
argument for the activate function. There are of course other
possibilities to achieve the above but having an extra activate function
might be a good idea anyway. With these changes, "Activated!" will be
printed if the pane becomes visible _and_ x changes, which in this case
always happens when pane becomes visible by toggling the Toggler, but
not if e.g. the pane selector is scrolled out of sight and back.

ClearAll[activate]

activate[x_] := Print["Activated!"]

{
 Toggler[Dynamic[x]],
 PaneSelector[
  {False -> "Inactive", True -> Dynamic[activate[x]]}, Dynamic[x]
  ]
 }

> ....OK, perhaps is a 'potentially infinite GUI tree control' already
> written somewhere in the standard library? :)

honestly, I have problems to imagine what a potentially infinity GUI
would look like on my 1280x1024 pixel screen :-).


hth,

albert




  • Prev by Date: Re: RE: Re: Workaround for an unexpected behavior of Sum
  • Next by Date: Re: Multiplying a vector over multiple vectors
  • Previous by thread: Use of RuleDelayed in PaneSelector
  • Next by thread: Re: Re: Re: Warning for use of 3D Graphics manipulation