Re: Manually culling a list
- To: mathgroup at smc.vnet.net
- Subject: [mg115130] Re: Manually culling a list
- From: Guido Tripaldi <guido at gtripaldi.it>
- Date: Sat, 1 Jan 2011 04:25:43 -0500 (EST)
Hi Tom,
see if you like this way.
cheers,
G
(* define our cull function *)
cullList[items_] :== Module[
{flags },
(* setup a flags array and reset its values *)
flags == Table[False, {Length[items]}];
(* Show up a dialog window, so our function will wait for button before exiting *)
DialogInput[
(* some cosmetic *)
Column[{
Text[Style["Make you choice:", Bold, Medium]],
(* every checkbox/item will have its own indipendent flag, indexed by the item sequence *)
Grid[MapIndexed[{Checkbox[Dynamic[flags[[First[#2]]]]], #1} &, items]],
(* return the appropriate list of values *)
Row[{
(* full list of values and items *)
Button["Full Cull", DialogReturn[MapThread[List, {flags, items}]]],
(* just the checked items *)
Button["Cull Checked", DialogReturn[Pick[items, flags, True]]],
(* just the unchecked items *)
Button["Cull Unchecked", DialogReturn[Pick[items, flags, False]]]
}] (* /Row *)
}] (* /Column *)
](* /DialogInput *)
](* /Module *)
(* call our function *)
culled == cullList[{"Mikey", "Goofy", "Pluto", "Donald"}]
Out[309]== {{False, "Mikey"}, {True, "Goofy"}, {False, "Pluto"}, {True, "Donald"}}
Il giorno 30/dic/2010, alle ore 10.10, ntg ha scritto:
> Hello guys,
>
> Suppose I have a longish list of items that I want to manually cull.
> It seems I should be able to do something like
>
> checkList == ({Checkbox[], #)& /@ list
>
> Then, I could write
>
> instanceOfCheckList == checkList
>
> check away, and hopefully see something like
>
> {{True, item1}, {False, item2}, ...}
>
> which I could manipulate. But all I see is the the list of "checked"
> checkboxs and items, not the consequence of checking the boxes. I can
> do a FullForm on instanceOfCheckList and extract what I need via list
> surgery-- but that is inelegant. I'm sure there is some magic
> incantation involving Evaluate or Interpretation or Dynamic. Can you
> help?
>
> Thanks,
> Tom
>
---
Guido Tripaldi