When running GTK+ apps under Ubuntu 12.04, how do you set the application name that is displayed in the Application-level menu?
Here's an example app:
from gi.repository import GLib, Gtk, Gio
import sys
class MyApp(object):
def __init__(self):
GLib.set_application_name('My App')
self.app = Gtk.Application.new('org.example.test', 0)
self.app.connect('startup', self.on_app_startup)
self.app.connect('activate', self.on_app_activate)
self.app.connect('shutdown', self.on_app_shutdown)
def run(self, argv):
self.app.run(argv)
def on_app_startup(self, app):
self.window = Gtk.ApplicationWindow.new(app)
self.window.set_default_size(640, 480)
self.window.set_title('AppMenu Demo')
app.add_window(self.window)
# # App menu
app_menu = Gio.Menu()
section = Gio.Menu()
item = Gio.MenuItem.new('Quit', 'app.quit')
item.set_attribute_value("accel", GLib.Variant("s", "<Control>Q"))
section.append_item(item)
app_menu.append_section(None, section)
app.set_app_menu(app_menu)
# # Menu bar
menu_bar = Gio.Menu()
submenu = Gio.Menu()
section = Gio.Menu()
section.append_item(Gio.MenuItem.new('Help', 'app.help'))
submenu.append_section(None, section)
menu_bar.append_submenu('Help', submenu)
app.set_menubar(menu_bar)
action = Gio.SimpleAction.new('quit', None)
action.connect('activate', self.on_quit)
app.add_action(action)
def on_app_activate(self, app):
self.window.show_all()
def on_app_shutdown(self, app):
pass
def on_quit(self, action, data=None):
self.app.quit()
if __name__ == '__main__':
app = MyApp()
app.run(sys.argv)
If you run this code under Ubuntu 12.04, it pops up a window labeled "AppMenu Demo"; the control bar at the top of the screen shows this name as well. If you move your mouse to the control bar, two pulldown menus are displayed; the app menu, and a "Help" menu.
This is all fine - except that the name of the Application menu is "Unknown Application Name". I can't find any way to alter this name. GLib.set_application_name(name) doesn't do it. How do you set the application name?
Or: is this a case where GTK+ is ahead of what Ubuntu supports? Google searches for "unknown application name" point at a range of bug reports and merged patches, which suggests to me that this might be an area of current development, rather than stable API. A quick survey of apps installed in Ubuntu shows that most apps have a "File" menu, but nothing that would be identified as an "app" menu of the type that GTK+ seems to support. Should I just abandon app menus until they're better supported at an OS level?
