Re: Dynamic popupmenu AND dynamic variables

*To*: mathgroup at smc.vnet.net*Subject*: [mg98608] Re: [mg98584] Dynamic popupmenu AND dynamic variables*From*: John Fultz <jfultz at wolfram.com>*Date*: Tue, 14 Apr 2009 06:16:26 -0400 (EDT)*Reply-to*: jfultz at wolfram.com

On Mon, 13 Apr 2009 03:35:22 -0400 (EDT), meitnik wrote: > Hi, > > Ok, I finally got a working parts I needed, however, to work smart, I > really hate to hardwire the creation of each group of popupmenus with > unique variable names (I have a hundred to go!). Is there any way to > create a rule, function etc so I can pass data for the menus and > generate unique variable names within. I tried using module but it > fails to work. Is this doable? > > use this code for showing me: > > mainMenu = {"hey", "you", "now"} > stuff = {{"a", "1", "r"}, {"b", "ee", "23"}, {eg,rt,yy}}; > > f[e_] := Switch[e, "hey", 1, "you", 2, "now", 3]; > CreatePalette[ > { > Labeled[ > Row[ > { > PopupMenu[Dynamic[x], mainMenu, Appearance -> "Palette"], > Dynamic[y = stuff[[f[x], 1]]; > PopupMenu[Dynamic[y], stuff[[f[x]]], Appearance -> "Palette"]], > ActionMenu[ > "", { > "Insert" :> NotebookWrite[InputNotebook[], y], > "Wrap" :> NotebookApply[InputNotebook[], > RowBox[{y, "[", "\[SelectionPlaceholder]", "]"}]] > }, ImageSize -> {4, 10}, FrameMargins -> 0 > ] > } > ] > , lbl, Left] > } > ] > > I want to create parameters for mainmenu and stuff; somehow uniquely > named variables for x and y on the fly in a sub routine thingy. Thank > you. Yeah, this isn't so good because you're using the values of the global variables 'x' and 'y'. You should use DynamicModule[] to define your variables. If you put each set of constructs which isn't interdependent in a separate DynamicModule[], then you can use the same variable names repeatedly without worrying about conflicts. E.g., Column[{ DynamicModule[{x, y}, Row[{...}]], DynamicModule[{x, y}, Row[{...}]], ...}] Sincerely, John Fultz jfultz at wolfram.com User Interface Group Wolfram Research, Inc.