将Mac OSX应用程序菜单菜单栏项设置为除"Python"以外的其他项.在我的python Qt应用程序中 [英] Setting Mac OSX Application Menu menu bar item to other than "Python" in my python Qt application

查看:130
本文介绍了将Mac OSX应用程序菜单菜单栏项设置为除"Python"以外的其他项.在我的python Qt应用程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用python和Qt编写GUI应用程序.在Mac上启动应用程序时,屏幕顶部Mac菜单栏中的第一个菜单项是"Python".我希望那里的应用程序名称是我的应用程序名称.我如何在这里获取程序名称?

I am writing a GUI application using python and Qt. When I launch my application on Mac, the first menu item in the Mac menu bar at the top of the screen is "Python". I would prefer the application name there to be the name of my application. How can I get my program name up there?

以下演示程序创建一个带有两个菜单的窗口:"Python"和"Foo".我不喜欢这样,因为无论是用python还是COBOL编写应用程序,这对我的用户都没有影响.相反,我需要菜单"MyApp"和"Foo".

The following demo program creates a window with two menus: "Python", and "Foo". I don't like that, because it makes no difference to my users whether I wrote the app in python or COBOL. Instead I want menus "MyApp" and "Foo".

#!/usr/bin/python

# This example demonstrates unwanted "Python"
# application menu name on Mac.

# Makes no difference whether we use PySide or PyQt4
from PySide.QtGui import *
# from PyQt4.QtGui import *

import sys

app = QApplication(sys.argv)
# Mac menubar application menu is always "Python".
# I want "DesiredAppTitle" instead.
# setApplicationName() does not affect Mac menu bar.
app.setApplicationName("DesiredAppTitle")
win = QMainWindow()
# need None parent for menubar on Mac to get custom menus at all
mbar = QMenuBar()
# Add a custom menu to menubar.
fooMenu = QMenu(mbar)
fooMenu.setTitle("Foo")
mbar.addAction(fooMenu.menuAction())
win.setMenuBar(mbar)
win.show()
sys.exit(app.exec_())

如何在Mac上更改该应用程序菜单名称?如果可能的话,我希望继续使用系统python(或用户PATH上的任何python).

How can I change that application menu name on Mac? I would prefer to continue to use the system python (or whatever python is on the user PATH) if possible.

推荐答案

您似乎需要OSX .app才能正常工作,因为其中的Info.plist文件包含放置在应用程序中的用户可见名称那里.默认为Python,这是您在程序菜单中看到的标题. 此博客帖子概述了您需要采取的步骤,而

You seem to need an OSX .app for this to work, as the Info.plist file in there contains the user-visible name for the application that is put there. This defaults to Python, which is the title you see for the program menu. This blog post outlines the steps you need to take, while the OSX Developer Library has the docs on the property list you need to fill.

这篇关于将Mac OSX应用程序菜单菜单栏项设置为除"Python"以外的其他项.在我的python Qt应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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