简体   繁体   English

Python的AppKit和ObjectiveC代理

[英]Python's AppKit and ObjectiveC Delegates

AppKit allows Python programs on a Mac to use ObjectiveC classes. AppKit允许Mac上的Python程序使用ObjectiveC类。 I am not very familiar with ObjectiveC, but I want to access the NSSound class using AppKit in order to create an audio player. 我对ObjectiveC不太熟悉,但我想使用AppKit访问NSSound类以创建音频播放器。

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. 我想有一个名为sound:didFinishPlaying:的方法,在那一刻被调用。 According to the documentation, a delegate has to be set which receives this method call. 根据文档,必须设置一个接受此方法调用的委托。

Can somebody help me translate that to Python/AppKit? 有人可以帮我翻译成Python / AppKit吗? How can I implement a delegate in Python and let it receive the didFinishPlaying notification? 如何在Python中实现委托并让它接收didFinishPlaying通知?

The first step towards successful development of a PyObjC based Cocoa/AppKit application is to learn Objective-C and then learn Cocoa . 成功开发基于PyObjC的Cocoa / AppKit应用程序的第一步是学习Objective-C然后学习Cocoa

The second step is to drop Python and just use Objective-C for your application. 第二步是删除Python并只为您的应用程序使用Objective-C。

PyObjC (and MacRuby) are awesome technologies, but success with both requires that you understand the patterns and APIs of the system frameworks. PyObjC(和MacRuby)是非常棒的技术,但两者的成功要求您了解系统框架的模式和API。 That , in turn, requires a working knowledge of Objective-C, enough to build simple apps. 反过来,需要的Objective-C的工作知识,足以建立简单的应用程序。

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. 现在,如果你需要集成一些庞大的Python库 - 比如说Twisted - 那么使用Python作为实现的主要语言将是完全合适的。 But you would still need a good foundation of knowledge/comfort with Objective-C and the Cocoa APIs. 但是,使用Objective-C和Cocoa API,您仍然需要良好的知识/舒适基础。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM