Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: Manually culling a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg115116] Re: Manually culling a list
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Fri, 31 Dec 2010 05:00:46 -0500 (EST)

OR...

cullList[list_] := Block[{t, selected = Unique[cullList] & /@ list},
    t = DialogInput[
      DialogNotebook[{TableForm@
         Partition[
          Riffle[Map[Composition[Checkbox, Dynamic], selected], list],
          2], Button["Finish", DialogReturn[Pick[list, selected]]]}]];
    Remove["Global`cullList$*"];
    t];

Bobby

On Fri, 31 Dec 2010 00:53:51 -0600, Zach Bjornson <bjornson at stanford.edu>  
wrote:

>   Indeed, I only meant to demo the usage of Map@Composition with Dynamic  
> and Checkbox. The obvious extension was to use Symbol or Unique, as you  
> did, Bobby. Downside is that those methods leak new symbols each time  
> they're used.
>
> Here's a reusable function that does the same thing and removes the  
> symbols after use. (Remove is kind of sloppy, with "Global`*$*".)
>
> CullList[list_] :=
>    Block[{t, selected = Table[Unique[], {i, Length@list}] (*Use Table  
> instead of Unique[list] to enable easier use of Remove*)},
>     t = DialogInput[
>       DialogNotebook[{TableForm@
>          Partition[Riffle[Map[Composition[Checkbox, Dynamic], selected],  
> list], 2],
>         Button["Finish", DialogReturn[Pick[list, selected]]]}]];
>     Remove["Global`$*"];
>     Return[t]];
>
> Cheers,
> Zach
>
> On 12/30/2010 7:27 PM, DrMajorBob wrote:
>> Actually, I don't think that does the job.
>>
>> a) When checking items in the "checks" list, you can't see the items in  
>> "list" that you're selecting.
>>
>> b) It involves manually listing variables a, b, c... to match the list,  
>> which isn't very flexible.
>>
>> c) You cannot run
>>
>> checks = Map[Composition[Checkbox, Dynamic], selected]
>>
>> a second time to create a different culled list or to cull it further.
>>
>> The following solves those problems:
>>
>> list = CharacterRange["A", "F"];
>>
>> Grid@{list,
>>   checks = Map[Composition[Checkbox, Dynamic], Unique /@ list]}
>>
>> selected = checks /. {Checkbox -> Identity, Dynamic -> Identity}
>>
>> {True, False, True, False, False, True}
>>
>> cull1 = Pick[list, selected]
>>
>> {"A", "C", "F"}
>>
>> Partition[Riffle[list, selected], 2]
>>
>> {{"A", True}, {"B", False}, {"C", True}, {"D", False}, {"E",
>>   False}, {"F", True}}
>>
>> To further cull the list:
>>
>> Grid@{cull1,
>>   checks = Map[Composition[Checkbox, Dynamic], Unique /@ cull1]}
>>
>> selected = checks /. {Checkbox -> Identity, Dynamic -> Identity}
>>
>> {False, True, True}
>>
>> cull2 = Pick[cull1, selected]
>>
>> {"C", "F"}
>>
>> Partition[Riffle[cull1, selected], 2]
>>
>> {{"A", False}, {"C", True}, {"F", True}}
>>
>> Bobby
>>
>> On Thu, 30 Dec 2010 18:07:18 -0600, Zach Bjornson  
>> <bjornson at stanford.edu> wrote:
>>
>>> Hi,
>>>
>>> In[1]:= list = CharacterRange["A", "F"]
>>> Out[1]= {"A", "B", "C", "D", "E", "F"}
>>>
>>> In[2]:= selected = {a, b, c, d, e, f};
>>>
>>> In[3]:= checks = Map[Composition[Checkbox, Dynamic], selected]
>>> Out[3]:= (*Checkboxes appear here*)
>>>
>>> In[4]:= culledlist = Dynamic@Pick[list, selected]
>>>
>>> Out[4]= (*Dynamic list of selected items appears here*)
>>>
>>> (*The list in the format you described*)
>>> In[5]:= Partition[Riffle[list, selected], 2]
>>> Out[5]= {{"A", True}, {"B", True}, {"C", True}, {"D", False}, {"E",
>>>    True}, {"F", False}}
>>>
>>> Cheers,
>>> Zach
>>>
>>> On 12/30/2010 1:10 AM, ntg wrote:
>>>> 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
>>>>
>>>
>>>
>>
>>


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Re: Manually culling a list
  • Next by Date: Re: getting all interesting sections of 7-d simplex
  • Previous by thread: Re: Manually culling a list
  • Next by thread: change of variable newbie question