如何更改纯Python应用程序包中OSX菜单栏中的应用程序名称?
我正在尝试为 wxPython 应用程序创建一个纯 Python 应用程序包。我使用 Apple 文档中描述的文件以及 Info.plist 文件等创建了 .app 目录。“普通”应用程序和此捆绑包之间的唯一区别是入口点(CFBundleExecutable)是一个以以下内容开头的脚本line:
#!/usr/bin/env python2.5
一切工作正常,除了 OSX 菜单栏中的应用程序名称仍然是“Python”,尽管我已经在 Info.plist 中设置了 CFBundleName(实际上我复制了 py2app 的结果)。 可以在此处查看完整的 Info.plist。
我怎样才能改变这个?我到处都读到菜单栏名称仅由 CFBundleName 确定。 Python解释器怎么可能在运行时改变这个呢?
注意:我之前使用过 py2app,但结果太大(> 50 MB 而不是当前的 100KB),并且它甚至无法在 Leopard 和 Snow Leopard 之间移植......所以看起来“手动”创建纯 Python 应用程序包比转换 py2app 的输出要容易得多。
I am trying to create a pure-Python application bundle for a wxPython app. I created the .app directory with the files described in Apple docs, with an Info.plist file etc. The only difference between a "normal" app and this bundle is that the entry point (CFBundleExecutable) is a script which starts with the following line:
#!/usr/bin/env python2.5
Everything works fine except that the application name in the OSX menubar is still "Python" although I have set the CFBundleName in Info.plist (I copied the result of py2app, actually). The full Info.plist can be viewed here.
How can I change this? I have read everywhere that the menubar name is only determined by CFBundleName. How is it possible that the Python interpreter can change this in runtime?
Note: I was using py2app before, but the result was too large (>50 MB instead of the current 100KB) and it was not even portable between Leopard and Snow Leopard... so it seems to be much easier to create a pure-Python app bundle "by hand" than transforming the output of py2app.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将
Info.plist
中名为LSHasLocalizedDisplayName
的键更改为true
,如下所示:然后在可执行包中创建一个
包含以下行的文件
Change a key called
LSHasLocalizedDisplayName
inInfo.plist
totrue
, as in:and then create a file in the executable bundle
which has lines
Python 开发者工具附带的“Build Applet.app”实际上是一个纯 Python 应用程序包。它执行以下操作:
MacOS/
目录中,Foo.app/Contents/MacOS/Foo
) 设置一些环境变量并调用此解释器的 os.execve() 。可执行脚本如下所示(假设程序的入口点位于Resources/main.py中):
The "Build Applet.app" that comes with the Python developer tools is actually a pure-Python app bundle. It does the following:
MacOS/
directoryFoo.app/Contents/MacOS/Foo
) sets up some environment variables and callsos.execve()
to this interpreter.The executable script looks like this (it is assumed that the entry point of the program is in
Resources/main.py
):实际上,如果您创建一个到 python 可执行文件的软链接并使用它而不是可执行文件本身(在您的 MyApp.app/Contents/MacOs/-script- 内),一切似乎都能正常工作。我个人使用“#!/bin/sh”脚本代替,只使用“exec”命令。 (我可能仍然需要使用 wx.App.SetAppName(MyAppName)。)例如:
Actually, if you create a soft link to the python executable and use that rather than the executable itself (inside your MyApp.app/Contents/MacOs/-script-), everything seems to work properly. I personally use a "#! /bin/sh" script instead and just use the "exec" command. (I you may still have to use wx.App.SetAppName(MyAppName).) For example: