我可以创建一个wxPython托盘图标应用程序而不在Dock中显示Python图标吗? [英] Can I create a wxPython tray icon application without the Python icon appearing in the Dock?

查看:248
本文介绍了我可以创建一个wxPython托盘图标应用程序而不在Dock中显示Python图标吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在SO上找到的示例托盘图标应用程序的经过稍微修改的源代码:

Here is the slightly modified source code for an example tray icon application I found on SO:

import wx

TRAY_TOOLTIP = 'System Tray Demo'
TRAY_ICON = 'icon.png'

def create_menu_item(menu, label, func):
    item = wx.MenuItem(menu, -1, label)
    menu.Bind(wx.EVT_MENU, func, id=item.GetId())
    menu.AppendItem(item)
    return item

class TaskBarIcon(wx.TaskBarIcon):
    def __init__(self):
        super(TaskBarIcon, self).__init__()
        self.set_icon(TRAY_ICON)
        self.Bind(wx.EVT_TASKBAR_LEFT_DOWN, self.on_left_down)
    def CreatePopupMenu(self):
        menu = wx.Menu()
        create_menu_item(menu, 'Say Hello', self.on_hello)
        menu.AppendSeparator()
        create_menu_item(menu, 'Exit', self.on_exit)
        return menu
    def set_icon(self, path):
        icon = wx.IconFromBitmap(wx.Bitmap(path))
        self.SetIcon(icon, TRAY_TOOLTIP)
    def on_left_down(self, event):
        print 'Tray icon was left-clicked.'
    def on_hello(self, event):
        print 'Hello, world!'
    def on_exit(self, event):
        wx.CallAfter(self.Destroy)

class App(wx.App):
    def OnInit(self):
        self.SetTopWindow(wx.Frame(None, -1))
        TaskBarIcon()

        return True

def main():
    app = App()
    app.MainLoop()

if __name__ == '__main__':
    main()

它成功显示了托盘图标,但实际上没有显示框架,但确实在Dock中显示了Python图标.我假设它还将在Windows任务栏中显示一个Python图标.如何阻止这种情况发生?

It shows a tray icon successfully, and indeed shows no Frame, but it does show the Python icon in the Dock. I assume it will also show a Python icon in the Windows task bar. How do I stop that from happening?

我正在OSX Mountain Lion的Python 2.7上使用wxPython 2.9

推荐答案

您应该从应用程序中创建捆绑软件,并告诉您您的应用程序属于背景"类,因此它不应在停靠栏中显示图标.

You should create a bundle from Your application and tell specify that your app is kind of "background", so it shall not show icon in dock.

为此,您必须将以下属性添加到捆绑包属性文件(Info.plist)中.

To do this, You have to following property to Your bundle property file (Info.plist).

<key>LSUIElement</key>
<string>1</string>

请参阅以下文章:

Apple关于应用程序启动属性的参考: http://developer.apple.com/library/ios/#documentation/general/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html

Apple reference about launch properties of application: http://developer.apple.com/library/ios/#documentation/general/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html

这篇关于我可以创建一个wxPython托盘图标应用程序而不在Dock中显示Python图标吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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