[PEAK] Re: Trellis <-> Cocoa KVC bridging

Phillip J. Eby pje at telecommunity.com
Fri Dec 28 14:56:55 EST 2007

At 12:25 PM 12/28/2007 -0500, Adam Atlas wrote:
>Greetings. I'm trying to figure out how I could bridge the Trellis to
>Cocoa's Key-Value Coding/Observing (through PyObjC), which is vaguely
>similar, though it takes the traditional route of requiring explicit
>registration for change notifications. My goal is to allow Trellis
>cells to see Objective-C object keys as cells, and to allow 
>Objective- C code to subscribe to Trellis cell-properties using the 
>usual Key- Value Observing API. (My secondary goal is to make Mac programming
>more Mac-like.)
>So, I'm wondering if this is actually possible. Have you thought at
>all about bridging Trellis to manual-subscription-type systems?
>Starting with letting real Trellis cells observe Objective-C keys,
>could I do that by perhaps coming up with a subclass of Cell, and
>creating some custom CellFactory that sets up the fields for an ObjC
>class? And then, how would the Cell subclass work -- I'm thinking it
>would have something to do with overriding dirty(), get_value(), 
>and/ or set_value(), but I am not exactly sure what. Have you any thoughts
>on that?

The simplest way to wrap an outside system as a cell is to register a 
callback with the outside system that sets the value of an existing cell.

Conversely, the simplest way to wrap cells as belonging to an outside 
system, is to have an @observer that issues the callbacks requested 
by the outside system.

It's unlikely that you'll need to create your own cell types, either way.

If callbacks can make changes, however, you'll probably want the 
callbacks in both cases to be sent via EventLoop.call(), to prevent 
unwanted recursion.  Whether you invoke all the callbacks in the same 
.call() or separate ones is up to you; you'll probably want it to be 
all in one, though.

(By the way, please don't send me off-list messages regarding PEAK or 
any other open-source project, except to inquire about consulting.)

More information about the PEAK mailing list