[Subversion] / Trellis / Collections.txt  

Diff of /Trellis/Collections.txt

Parent Directory | Revision Log

version 2420, Wed Nov 14 20:01:36 2007 UTC version 2528, Fri Apr 25 22:07:07 2008 UTC
Line 8 
Line 8 
     >>> from peak.events import trellis, collections      >>> from peak.events import trellis, collections
   
   
   .. contents:: **Table of Contents**
   
   
 SortedSet  SortedSet
 ---------  ---------
   
Line 25 
Line 28 
 example, the Trellis package includes a ``SortedSet`` type that maintains an  example, the Trellis package includes a ``SortedSet`` type that maintains an
 index of items sorted by keys, with a cell that lists changed regions.  index of items sorted by keys, with a cell that lists changed regions.
   
 A ``trellis.SortedSet`` is a specialized component that lets you wrap a  A ``collections.SortedSet`` is a specialized component that lets you wrap a
 ``trellis.Set`` (or anything similar to one, that offers iteration plus  ``trellis.Set`` (or anything similar to one, that offers iteration plus
 ``added`` and ``removed`` cells) with a sort key, to get a list::  ``added`` and ``removed`` cells) with a sort key, to get a list::
   
Line 33 
Line 36 
     >>> myIndex = collections.SortedSet(data=myItems)      >>> myIndex = collections.SortedSet(data=myItems)
   
     >>> class Viewer(trellis.Component):      >>> class Viewer(trellis.Component):
     ...     trellis.values(model = None)      ...     model = trellis.attr(None)
     ...      ...
     ...     @trellis.action      ...     @trellis.perform
     ...     def view_it(self):      ...     def view_it(self):
     ...         if self.model is not None:      ...         if self.model is not None:
     ...             print self.model      ...             print self.model
Line 65 
Line 68 
     >>> view.model = None   # quiet, please      >>> view.model = None   # quiet, please
   
     >>> class Watcher(trellis.Component):      >>> class Watcher(trellis.Component):
     ...     @trellis.action      ...     @trellis.perform
     ...     def dump(self):      ...     def dump(self):
     ...         print myIndex.changes      ...         print myIndex.changes
   
Line 158 
Line 161 
     >>> myIndex      >>> myIndex
     [0, 1, 4]      [0, 1, 4]
   
 TODO: ``reversed`` flag, test changes to ``.data``  As does setting or clearing the ``reverse`` flag (which reverses the effect of
   the sort key)::
   
       >>> myIndex.reverse = True
       [(0, 3, 3)]
       []
       >>> myIndex
       [4, 1, 0]
   
       >>> myItems.add(7)
       [(0, 0, 1)]
       []
       >>> myIndex
       [7, 4, 1, 0]
   
       >>> myItems.add(2)
       [(2, 2, 1)]
       []
       >>> myIndex
       [7, 4, 2, 1, 0]
   
       >>> myItems.remove(7)
       [(0, 1, 0)]
       []
   
       >>> myItems.remove(2)
       [(1, 2, 0)]
       []
   
       >>> myIndex
       [4, 1, 0]
   
       >>> myIndex.reverse = False
       [(0, 3, 3)]
       []
   
       >>> myIndex
       [0, 1, 4]
   
   
   TODO: test changes to ``.data``
   
   
 SubSet  SubSet
Line 212 
Line 255 
   
     >>> def show():      >>> def show():
     ...     print "Changes:", o.changes      ...     print "Changes:", o.changes
     >>> c = trellis.ActionCell(show)      >>> c = trellis.Performer(show)
     >>> c.value  
     Changes: {}      Changes: {}
   
 The ``changes`` attribute is a dictionary (a regular dictionary, not a  The ``changes`` attribute is a dictionary (a regular dictionary, not a


Generate output suitable for use with a patch program
Legend:
Removed from v.2420  
changed lines
  Added in v.2528

cvs-admin@eby-sarna.com

Powered by ViewCVS 1.0-dev

ViewCVS and CVS Help