我在XCode中创建了一个全新的项目,并在我的AppDelegate.py文件:
from Foundation import *
from AppKit import *
class MyApplicationAppDelegate(NSObject):
def applicationDidFinishLaunching_(self, sender):
NSLog("Application did finish launching.")
statusItem = NSStatusBar.systemStatusBar().statusItemWithLength_(NSVariableStatusItemLength)
statusItem.setTitle_(u"12%")
statusItem.setHighlightMode_(TRUE)
statusItem.setEnabled_(TRUE)
但是,当我启动应用程序时,没有显示状态栏项。所有其他代码主.pymain.m是默认值。在
我必须这样做才能成功:
打开主菜单.xib. 确保应用程序委托的类是
MyApplicationAppDelegate
。我不确定你是否必须这么做,但我做了。这是错误的,所以应用程序代表一开始就没有被调用。添加
statusItem.retain()
,因为它会立即自动释放。上面的.retain()用法是必需的,因为从ApplicationIDFinishLaunching()方法返回时statusItem将被销毁。使用将该变量绑定为MyApplicationAppDelegate实例中的字段自身状态项相反。在
下面是一个修改后的示例,它不需要.xib/等。。。在
相关问题 更多 >
编程相关推荐