[PEAK] How do I extract a subset?

Peter Damoc pdamoc at gmail.com
Thu Apr 17 02:23:33 EDT 2008


Ok... here is the class:
SocketRecordVault is a trellis.Set

class LumberjackWidget(trellis.Component):

    trellis.values(
        records = None,
        filtered_records = None,
        sorted_records = None,
    )

    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        trellis.Component.__init__(self)

        self.records = SocketRecordVault()
        self.filtered_records = trellis.Set()
        self.sorted_records =
collections.SortedSet(data=self.filtered_records)

        self.sorted_records.sort_key = lambda x: x.created


        self.txt = wx.TextCtrl(self, style=wx.TE_MULTILINE)

        box = wx.BoxSizer()
        box.Add(self.txt, 1, wx.EXPAND)
        self.SetSizer(box)

        self.fmt = logging.Formatter('%(levelname)s | %(name)s | %(message)s
[@ %(asctime)s in %(filename)s:%(lineno)d]')


    @trellis.observer
    def updateView(self):
        x = len(self.records) # needed to monitor changes
        self.filtered_records = [x for x in self.records]
        if self.sorted_records:
            self.txt.Clear()
            for r in self.sorted_records:
                self.txt.AppendText(self.fmt.format(r)+"\n

the traceback is:

Traceback (most recent call last):
  File "lumberjack.py", line 141, in <module>
    main()
  File "lumberjack.py", line 133, in main
    panel = LumberjackWidget(frame)
  File
"c:\python25\lib\site-packages\DecoratorTools-1.7-py2.5.egg\peak\util\decorators.py",
line 634, in __call__
    return cls.__class_call__.im_func(cls, *args, **kw)
  File "<peak.events.trellis.wrap wrapping
peak.events.trellis.__class_call__ at 0x01BB4770>", line 5, in
__class_call__
  File
"C:\Python25\lib\site-packages\trellis-0.6a1-py2.5.egg\peak\events\stm.py",
line 466, in atomically
    return super(Controller,self).atomically(self._process, func, args, kw)
  File
"C:\Python25\lib\site-packages\trellis-0.6a1-py2.5.egg\peak\events\stm.py",
line 186, in atomically
    self.cleanup(*sys.exc_info())
  File
"C:\Python25\lib\site-packages\trellis-0.6a1-py2.5.egg\peak\events\stm.py",
line 309, in cleanup
    return super(Controller, self).cleanup(*args)
  File
"C:\Python25\lib\site-packages\trellis-0.6a1-py2.5.egg\peak\events\stm.py",
line 182, in atomically
    retval = func(*args, **kw)
  File
"C:\Python25\lib\site-packages\trellis-0.6a1-py2.5.egg\peak\events\stm.py",
line 482, in _process
    self.run_rule(listener)
  File
"C:\Python25\lib\site-packages\trellis-0.6a1-py2.5.egg\peak\events\stm.py",
line 359, in run_rule
    listener.run()
  File "lumberjack.py", line 124, in updateView
    self.filtered_records = [x for x in self.records]
  File
"C:\Python25\lib\site-packages\trellis-0.6a1-py2.5.egg\peak\events\trellis.py",
line 615, in __set__
    cell.value = value
  File
"C:\Python25\lib\site-packages\trellis-0.6a1-py2.5.egg\peak\events\trellis.py",
line 144, in set_value
    raise InputConflict(self._value, value) #self._set_by) #, value,
ctrl.current_listener) # XXX
peak.events.trellis.InputConflict: (Set([]), [])

On Wed, Apr 16, 2008 at 9:32 PM, Phillip J. Eby <pje at telecommunity.com>
wrote:

> At 08:06 PM 4/16/2008 +0300, Peter Damoc wrote:
>
> > Hi Phillip,
> >
> > I tried a naive
> >
> > fitered_records = [r for r in records if "some segment" in <
> > http://r.name>r.name]
> >
> > It didn't work :)
> > I get:
> > peak.events.trellis.InputConflict: (Set([]), [])
> >
>
> You've left out any information that would help me know what the heck is
> going on with this bit.  Like the traceback, and the code.  :)
>
>
>  as for changes, here is the code:
> >
> >    @trellis.observer
> >    def updateView(self):
> >        x = len(self.records) # needed to monitor changes
> >        if self.sorted_records:
> >            self.txt.Clear()
> >            for r in self.sorted_records:
> >                self.txt.AppendText(self.fmt.format(r)+"\n")
> >
> > if I remove the first line in the method the observer no longer gets
> > triggered.
> > In all cases the only thing that changes are new record being added to
> > the records set.
> >
>
> Ah...  you need to be using 'self.sorted_records.changes' in order to
> detect changes in a SortedSet, currently.  Really, that's what SortedSet is
> for, to produce a position-based change log.
>
>


-- 
There is NO FATE, we are the creators.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.eby-sarna.com/pipermail/peak/attachments/20080417/04f9cc08/attachment.html


More information about the PEAK mailing list