如何使用Cocoa和Python(PyObjC)创建状态栏项目? [英] How can I create a status bar item with Cocoa and Python (PyObjC)?

查看:384
本文介绍了如何使用Cocoa和Python(PyObjC)创建状态栏项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在XCode中创建了一个全新的项目,并在我的AppDelegate.py文件中有以下内容:

I have created a brand new project in XCode and have the following in my AppDelegate.py file:

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)

但是,当我启动应用程序时,不会出现状态栏项。 main.py和main.m中的所有其他代码都是默认的。

However, when I launch the application no status bar item shows up. All the other code in main.py and main.m is default.

推荐答案


  1. 打开MainMenu.xib。确保应用程序代理的类是 MyApplicationAppDelegate 。我不知道你是否必须这样做,但我做到了。

  1. Open MainMenu.xib. Make sure the class of the app delegate is MyApplicationAppDelegate. I'm not sure if you will have to do this, but I did. It was wrong and so the app delegate never got called in the first place.

添加 statusItem.retain(),因为它会立即自动释放。

Add statusItem.retain() because it gets autoreleased right away.

这篇关于如何使用Cocoa和Python(PyObjC)创建状态栏项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆