在 OSX 中,将应用程序名称从“python”更改为“python”。

发布于 2024-10-18 06:41:53 字数 3929 浏览 0 评论 0原文

我正在开发 Orange,并且我在 OSX (10.6.5) 中的菜单栏名称中遇到了这个问题是“Python”而不是橙色。这是一个 python/qt 应用程序。我需要改变什么?

澄清一下:

  • qt 应用程序,不是 cli,不在终端中运行。

我的 info.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDisplayName</key>
    <string>YOORANGE</string>
        <key>CFBundleExecutable</key>
        <string>Orange</string>
        <key>CFBundleIconFile</key>
        <string>orange.icns</string>
        <key>CFBundleIdentifier</key>
        <string>si.ailab.Orange</string>
        <key>CFBundleInfoDictionaryVersion</key>
        <string>6.0</string>
        <key>CFBundleName</key>
        <string>Orange</string>
        <key>CFBundleGetInfoString</key>
        <string>Orange, component-based data mining software</string>
        <key>CFBundlePackageType</key>
        <string>APPL</string>
        <key>CFBundleSignature</key>
        <string>Orng</string>
        <key>CFBundleShortVersionString</key>
        <string>1.0.0</string>
        <key>CFBundleVersion</key>
        <string>1.0.0</string>
        <key>CFBundleDocumentTypes</key>
        <array>
                <dict>
                        <key>CFBundleTypeExtensions</key>
                        <array>
                                <string>ows</string>
                        </array>
                        <key>CFBundleTypeName</key>
                        <string>Orange Canvas Schema</string>
                        <key>CFBundleTypeOSTypes</key>
                        <array>
                                <string>OWSf</string>
                        </array>
                        <key>CFBundleTypeIconFile</key>
                        <string>schema.icns</string>
                        <key>CFBundleTypeRole</key>
                        <string>Viewer</string>
                        <key>LSIsAppleDefaultForType</key>
                        <true/>
                </dict>
        </array>
</dict>
</plist>

这是 Orange 启动脚本,经过修改以尝试使用符号链接。显然有些工作有效:)

#!/bin/bash

BUNDLE_DIR=`dirname $0`/../
BUNDLE_DIR=`perl -MCwd=realpath -e 'print realpath($ARGV[0])' $BUNDLE_DIR`/
FRAMEWORKS_DIR="$BUNDLE_DIR"Frameworks/

CANVAS_FILE="$FRAMEWORKS_DIR"Python.framework/Versions/2.6/lib/python2.6/site-packages/orange/OrangeCanvas/orngCanvas.    pyw

cp "$FRAMEWORKS_DIR"Python.framework/Resources/Python.app/Contents/MacOS/{Python-32,AWESOME}
PYTHONEXECUTABLE="$FRAMEWORKS_DIR"Python.framework/Resources/Python.app/Contents/MacOS/AWESOME
PYTHONHOME="$FRAMEWORKS_DIR"Python.framework/Versions/2.6/

#DYLD_FRAMEWORK_PATH="$FRAMEWORKS_DIR"${DYLD_FRAMEWORK_PATH:+:$DYLD_FRAMEWORK_PATH}
DYLD_FRAMEWORK_PATH="$FRAMEWORKS_DIR":"$BUNDLE_DIR"Resources/Qt4/lib${DYLD_FRAMEWORK_PATH:+:$DYLD_FRAMEWORK_PATH}

export PYTHONEXECUTABLE
export PYTHONHOME

export DYLD_FRAMEWORK_PATH
export DYLD_LIBRARY_PATH="$BUNDLE_DIR"Resources/openbabel/lib/:"$BUNDLE_DIR"Resources/openbabel/lib/openbabel/2.2.3/:$    DYLD_LIBRARY_PATH

# LaunchServices passes the Carbon process identifier to the application with -psn paramter - we do not want it
if [[ "$1" == -psn* ]] ; then
 shift
fi

echo "$0"
echo "$PYTHONEXECUTABLE"
echo "$@"

exec -a "$0" "$PYTHONEXECUTABLE" "$CANVAS_FILE" "$@"

I am working on Orange, and I am getting this nit where in OSX (10.6.5), the menubar name is 'Python' instead of orange. It's a python/qt app. What do I need to change?

To clarify:

  • qt app, not a cli, not running in terminal.

my info.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDisplayName</key>
    <string>YOORANGE</string>
        <key>CFBundleExecutable</key>
        <string>Orange</string>
        <key>CFBundleIconFile</key>
        <string>orange.icns</string>
        <key>CFBundleIdentifier</key>
        <string>si.ailab.Orange</string>
        <key>CFBundleInfoDictionaryVersion</key>
        <string>6.0</string>
        <key>CFBundleName</key>
        <string>Orange</string>
        <key>CFBundleGetInfoString</key>
        <string>Orange, component-based data mining software</string>
        <key>CFBundlePackageType</key>
        <string>APPL</string>
        <key>CFBundleSignature</key>
        <string>Orng</string>
        <key>CFBundleShortVersionString</key>
        <string>1.0.0</string>
        <key>CFBundleVersion</key>
        <string>1.0.0</string>
        <key>CFBundleDocumentTypes</key>
        <array>
                <dict>
                        <key>CFBundleTypeExtensions</key>
                        <array>
                                <string>ows</string>
                        </array>
                        <key>CFBundleTypeName</key>
                        <string>Orange Canvas Schema</string>
                        <key>CFBundleTypeOSTypes</key>
                        <array>
                                <string>OWSf</string>
                        </array>
                        <key>CFBundleTypeIconFile</key>
                        <string>schema.icns</string>
                        <key>CFBundleTypeRole</key>
                        <string>Viewer</string>
                        <key>LSIsAppleDefaultForType</key>
                        <true/>
                </dict>
        </array>
</dict>
</plist>

Here is the Orange startup script, modified to try to use a symlink. Clearly something work work :)

#!/bin/bash

BUNDLE_DIR=`dirname $0`/../
BUNDLE_DIR=`perl -MCwd=realpath -e 'print realpath($ARGV[0])' $BUNDLE_DIR`/
FRAMEWORKS_DIR="$BUNDLE_DIR"Frameworks/

CANVAS_FILE="$FRAMEWORKS_DIR"Python.framework/Versions/2.6/lib/python2.6/site-packages/orange/OrangeCanvas/orngCanvas.    pyw

cp "$FRAMEWORKS_DIR"Python.framework/Resources/Python.app/Contents/MacOS/{Python-32,AWESOME}
PYTHONEXECUTABLE="$FRAMEWORKS_DIR"Python.framework/Resources/Python.app/Contents/MacOS/AWESOME
PYTHONHOME="$FRAMEWORKS_DIR"Python.framework/Versions/2.6/

#DYLD_FRAMEWORK_PATH="$FRAMEWORKS_DIR"${DYLD_FRAMEWORK_PATH:+:$DYLD_FRAMEWORK_PATH}
DYLD_FRAMEWORK_PATH="$FRAMEWORKS_DIR":"$BUNDLE_DIR"Resources/Qt4/lib${DYLD_FRAMEWORK_PATH:+:$DYLD_FRAMEWORK_PATH}

export PYTHONEXECUTABLE
export PYTHONHOME

export DYLD_FRAMEWORK_PATH
export DYLD_LIBRARY_PATH="$BUNDLE_DIR"Resources/openbabel/lib/:"$BUNDLE_DIR"Resources/openbabel/lib/openbabel/2.2.3/:$    DYLD_LIBRARY_PATH

# LaunchServices passes the Carbon process identifier to the application with -psn paramter - we do not want it
if [[ "$1" == -psn* ]] ; then
 shift
fi

echo "$0"
echo "$PYTHONEXECUTABLE"
echo "$@"

exec -a "$0" "$PYTHONEXECUTABLE" "$CANVAS_FILE" "$@"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

悲凉≈ 2024-10-25 06:41:54

我想提出另一种解决方案。
它使用Cocoa来设置应用程序名称,
无需摆弄符号链接。
在使用 PyQt 之前,尽早在主模块中运行它。

    if sys.platform.startswith('darwin'):
        # Set app name, if PyObjC is installed
        # Python 2 has PyObjC preinstalled
        # Python 3: pip3 install pyobjc-framework-Cocoa
        try:
            from Foundation import NSBundle
            bundle = NSBundle.mainBundle()
            if bundle:
                app_name = os.path.splitext(os.path.basename(sys.argv[0]))[0]
                app_info = bundle.localizedInfoDictionary() or bundle.infoDictionary()
                if app_info:
                    app_info['CFBundleName'] = app_name
        except ImportError:
            pass

I'd like to propose another solution.
It uses Cocoa to set the application name,
no need to fiddle with symlinks.
Run it early in your main module, before using PyQt.

    if sys.platform.startswith('darwin'):
        # Set app name, if PyObjC is installed
        # Python 2 has PyObjC preinstalled
        # Python 3: pip3 install pyobjc-framework-Cocoa
        try:
            from Foundation import NSBundle
            bundle = NSBundle.mainBundle()
            if bundle:
                app_name = os.path.splitext(os.path.basename(sys.argv[0]))[0]
                app_info = bundle.localizedInfoDictionary() or bundle.infoDictionary()
                if app_info:
                    app_info['CFBundleName'] = app_name
        except ImportError:
            pass
困倦 2024-10-25 06:41:54

简短的回答-这并不简单,因为您正在运行 python 解释器,它是它自己的程序,有自己的默认标题。

长答案-
如果设置了环境变量 PYTHONSTARTUP,Python 解释器将在启动时执行 shell 脚本。您可以在其中设置窗口标题。

  1. 使用 shell 脚本的名称设置环境变量 PYTHONSTARTUP 以
  2. 在该 shell 脚本中启动时执行 (http://docs.python.org/library/idle.html#startup),运行 settitle [title]

获取标题每当您在启动之前必须执行一些额外的环境变量操作时,它都会发生变化。

Short answer- it's not trivial because you are running the python interpreter which is its own program with its own default title.

Long answer-
Python interpreter will execute a shell script on startup if you have environment variable PYTHONSTARTUP set. You can probalby set the window title in this.

  1. set an environment variable PYTHONSTARTUP with the name of a shell script to execute on start up (http://docs.python.org/library/idle.html#startup)
  2. in that shell script, run settitle [title]

To get a title that changes every time you would have to do some extra environment variable stuff before launch.

冷弦 2024-10-25 06:41:54

这是一个作弊,但我相信它有效,

创建一个到 python 应用程序的符号链接。

ln -s /opt/local/bin/python /opt/local/bin/orange

然后调用 Orange 而不是 python 来启动脚本

It's a cheat, but i believe it works,

Create a sym link to the python app.

ln -s /opt/local/bin/python /opt/local/bin/orange

then call orange not python to start your script

霊感 2024-10-25 06:41:54

事实证明,在 Contents/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/Info.plist 中捆绑了一个更深层次的 Info.plist,它被称为。

As it turns out, there was a deeper Info.plist bundled in at Contents/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/Info.plist, that was being called.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文