[PEAK] How do I extract a subset?
Phillip J. Eby
pje at telecommunity.com
Thu Apr 17 11:27:53 EDT 2008
At 09:23 AM 4/17/2008 +0300, Peter Damoc wrote:
> @trellis.observer
> def updateView(self):
> x = len(self.records) # needed to monitor changes
> self.filtered_records = [x for x in self.records]
You can't modify trellis data in an observer. Move this line to a
rule of its own, and change it to:
@trellis.rule
def do_filtering(self):
self.filtered_records.clear()
self.filtered_records.update(x for x in self.records if x...)
This way, the same set object will be updated in-place. Your
observer should now check 'self.sorted_records.changes' instead of
'len(self.records)' to ensure it's triggered when a change occurs.
Meanwhile, the reason that you're getting a conflict is because you
are assigning different values to the filtered_records attribute in
two places during the same calculation.
More information about the PEAK
mailing list