如何在纯Python应用程序捆绑包的OSX菜单栏中更改应用程序名称? [英] How to change the app name in OSX menubar in a pure-Python application bundle?
问题描述
我正在尝试为wxPython应用程序创建纯Python应用程序包。我用Apple文档中描述的文件以及Info.plist文件等创建了.app目录。普通应用程序和此捆绑包之间的唯一区别是,入口点(CFBundleExecutable)是一个脚本,该脚本以以下内容开头行:
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
一切正常,除了OSX菜单栏中的应用程序名称仍为 Python,尽管我已在Info.plist中设置了CFBundleName(我复制了py2app的结果,实际上)。 完整的Info.plist可以在此处查看。
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.
我该如何更改?我到处都读到菜单栏名称仅由CFBundleName确定。
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?
注意:我以前使用的是py2app,但结果太大了(> 50 MB,而不是当前的100KB),甚至在Leopard和Snow Leopard之间都不是可移植的...因此,手工创建纯Python应用程序包似乎比转换py2app的输出要容易得多。
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.
推荐答案
Python开发人员工具随附的 Build Applet.app实际上是一个纯Python应用程序捆绑包。它执行以下操作:
The "Build Applet.app" that comes with the Python developer tools is actually a pure-Python app bundle. It does the following:
- 将Python解释器放置(或链接)到
MacOS / $ c中$ c>目录
- 可执行脚本(
Foo.app/Contents/MacOS/Foo
)设置一些环境变量并调用os.execve()
到此解释器。
- a Python interpreter is placed (or linked) into the
MacOS/
directory - the executable script (
Foo.app/Contents/MacOS/Foo
) sets up some environment variables and callsos.execve()
to this interpreter.
可执行脚本如下所示(假定程序的入口点位于 Resources / main.py
中):
The executable script looks like this (it is assumed that the entry point of the program is in Resources/main.py
):
#!/System/Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python
import sys, os
execdir = os.path.dirname(sys.argv[0])
executable = os.path.join(execdir, "Python")
resdir = os.path.join(os.path.dirname(execdir), "Resources")
libdir = os.path.join(os.path.dirname(execdir), "Frameworks")
mainprogram = os.path.join(resdir, "main.py")
sys.argv.insert(1, mainprogram)
pypath = os.getenv("PYTHONPATH", "")
if pypath:
pypath = ":" + pypath
os.environ["PYTHONPATH"] = resdir + pypath
os.environ["PYTHONEXECUTABLE"] = executable
os.environ["DYLD_LIBRARY_PATH"] = libdir
os.environ["DYLD_FRAMEWORK_PATH"] = libdir
os.execve(executable, sys.argv, os.environ)
这篇关于如何在纯Python应用程序捆绑包的OSX菜单栏中更改应用程序名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!