[Pythonmac-SIG] Porting a Tkinter application to Cocoa: question about datatypes

Ronald Oussoren ronaldoussoren at mac.com
Thu Jun 14 03:39:03 CEST 2007

On 13 Jun, 2007, at 17:33, Kevin Walzer wrote:

> Ronald Oussoren wrote:
>> The major exception to this is Key-Value Observing (also known as  
>> Cocoa bindings).  Cocoa bindings requires that objects emit events  
>> when they are mutated (append an item, set the value for a key in  
>> a dict, ...). Sadly enough Python doesn't have the hooks that are  
>> required to emit these events for pure python objects.  Adding  
>> this support requires some low-level changes to python and I'm not  
>> sure if this can be done without adversely affecting the  
>> performance of the interpreter.
> Interesting. Are Cocoa bindings analogous to the updating and  
> binding mechanism in Tk? For instance, in Tkinter, I can assign a  
> value to an object, then update that value later in another  
> function via the StringVar() mechanism. For instance, in in my  
> self.drawGUI function, I can do this:
>         self.status = StringVar()
>         self.status.set('Ready')
> then in another function, I can call this:
>         self.status.set('Process terminated')
> and the value of the label widget will be updated. Was this  
> functionality hard to manage or missing in Objective-C/Cocoa before  
> the "Cocoa Binding" stuff was added?

That seems to be simular to Cocoa Bindings, except that arbitrary  
objects can participate in Cocoa Bindings/KVO. You basicly have to  
implement an interface for getting and setting attributes (simular to  
getattr/setattr in Python) and you have to emit events when changing  
attributes, which is done automaticly by the __setattr__  
implementation for NSObject. The framework does the legwork for  
actually routing the events and making sure that this is done as  
efficiently as possible.

Bindings are explained here: <http://developer.apple.com/ 

Bindings are really powerfull when used in NIB files (basically GUI  
design files), you can connect controls to data in your model  
entirely in the GUI builder tool without writing a single line of  
code. There is a risk for creating greatly obfuscated programs,  
because important parts of your program aren't actually in code.


> -- 
> Kevin Walzer
> Code by Kevin
> http://www.codebykevin.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3562 bytes
Desc: not available
Url : http://mail.python.org/pipermail/pythonmac-sig/attachments/20070613/67137a58/attachment.bin 

More information about the Pythonmac-SIG mailing list