MathGroup Archive 2009

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

Search the Archive

Re: dynamic popupmenu help needed

  • To: mathgroup at smc.vnet.net
  • Subject: [mg98457] Re: dynamic popupmenu help needed
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Fri, 10 Apr 2009 04:53:43 -0400 (EDT)
  • References: <grkgcm$61u$1@smc.vnet.net>

Hi,

> I can't figure out how to get the second popup to insert into a the
> cell where the insertion cursor is:

actually I don't understand what you want to achieve,

> f[e_] := Switch[e, "hey", 1, "you", 2, "now", 3];
> stuff = {{"a", "1", "r"}, {"b", "ee", "23"}, {0}};
> CreatePalette[
>  PopupMenu[Dynamic[x], {"hey", "you", "now"}]
>   Dynamic@PopupMenu[Dynamic[y], stuff[[f[x]]]]]
> NotebookApply[InputNotebook[], Dynamic[y]]

... the above doesn't do anything reasonable on my machine...

> please any suggestions? Any rewrites welcomed. 

Start with something simple. This seems to be clear:

f[e_] := Switch[e, "hey", 1, "you", 2, "now", 3];
stuff = {{"a", "1", "r"}, {"b", "ee", "23"}, {0}};

make sure you understand the building blocks of what you do. This sets x
to the desired value and shows that value:

{PopupMenu[Dynamic[x], {"hey", "you", "now"}], Dynamic[x]}

and this gives a popup menu whose content dynamically changes and shows
which is the current value:

{Dynamic[PopupMenu[Dynamic[y], stuff[[f[x]]]]], Dynamic[y]}

now there are various ways with which you can "initialize" that
PopupMenu to one of the selectable values, with the default, y will just
stay what it was, so cannot be found in the list of possible values
which will make the content of the PopupMenu be viewed as empty. A very
simple way to change that would be to first set y to the first entry in
the new list, e.g.:

{
 Dynamic[y = stuff[[f[x], 1]]; PopupMenu[Dynamic[y], stuff[[f[x]]]]],
 Dynamic[y]
}

Of course you can insert any code you wish to make that entry appear
when changing x that you wish. Once that works as you want, you can
create a palette that controls y:

CreatePalette[{
  Row[{
    PopupMenu[Dynamic[x], {"hey", "you", "now"}],
    Dynamic[y = stuff[[f[x], 1]];
     PopupMenu[Dynamic[y], stuff[[f[x]]]]]
    }, Spacer[5]]
  }]

or maybe you want to make that a little more robust using a local
(dynamic) variable for x:

CreatePalette[{DynamicModule[{x},
  Row[{
    PopupMenu[Dynamic[x], {"hey", "you", "now"}],
    Dynamic[y = stuff[[f[x], 1]];
     PopupMenu[Dynamic[y], stuff[[f[x]]]]]
    }, Spacer[5]]
]}]


> Sure wish hierarchical menus were supported ;-p

I think everything is there to build that, but you should be more
precise in defining what these hierarchical menus should behave like...

hth,

albert


  • Prev by Date: Re: 2-defensive prime number
  • Next by Date: Re: AMERICAN MATHEMATICAL MONTHLY -April 2009:Transformations Between
  • Previous by thread: Re: dynamic popupmenu help needed
  • Next by thread: Re: dynamic popupmenu help needed