Python's AppKit and ObjectiveC Delegates
AppKit allows Python programs on a Mac to use ObjectiveC classes. I am not very familiar with ObjectiveC, but I want to access the 开发者_运维技巧NSSound class using AppKit in order to create an audio player.
My player should perform some action, such as loading the next item from the playlist, when the current audio finishes playing. There is a method named sound:didFinishPlaying:, which is called at that moment, I suppose. According to the documentation, a delegate has to be set which receives this method call.
Can somebody help me translate that to Python/AppKit? How can I implement a delegate in Python and let it receive the didFinishPlaying notification?
The first step towards successful development of a PyObjC based Cocoa/AppKit application is to learn Objective-C and then learn Cocoa.
The second step is to drop Python and just use Objective-C for your application.
PyObjC (and MacRuby) are awesome technologies, but success with both requires that you understand the patterns and APIs of the system frameworks. That, in turn, requires a working knowledge of Objective-C, enough to build simple apps.
Now, if you were need to integrate some massive Python library -- say, Twisted -- then using Python as the primary language of implementation would be totally appropriate. But you would still need a good foundation of knowledge/comfort with Objective-C and the Cocoa APIs.
精彩评论