def generate_menu(self):
# Settings section
settings_content = Gio.Menu.new()
settings_content.append_item(
Gio.MenuItem.new(_("Settings"), "app.settings"))
settings_section = Gio.MenuItem.new_section(None, settings_content)
self.menu.append_item(settings_section)
# Help section
help_content = Gio.Menu.new()
help_content.append_item(Gio.MenuItem.new(_("Night Mode"), "app.night_mode"))
if Gtk.get_major_version() >= 3 and Gtk.get_minor_version() >= 20:
help_content.append_item(Gio.MenuItem.new(
_("Shortcuts"), "app.shortcuts"))
help_content.append_item(Gio.MenuItem.new(_("About"), "app.about"))
help_content.append_item(Gio.MenuItem.new(_("Quit"), "app.quit"))
help_section = Gio.MenuItem.new_section(None, help_content)
self.menu.append_item(help_section)
self.settings_action = Gio.SimpleAction.new("settings", None)
self.settings_action.connect("activate", self.on_settings)
self.settings_action.set_enabled(not settings.get_is_locked())
settings.bind('locked', self.settings_action, 'enabled', Gio.SettingsBindFlags.INVERT_BOOLEAN)
self.add_action(self.settings_action)
action = Gio.SimpleAction.new_stateful("night_mode", None, GLib.Variant.new_boolean(settings.get_is_night_mode()))
action.connect("change-state", self.on_night_mode)
self.add_action(action)
if Gtk.get_major_version() >= 3 and Gtk.get_minor_version() >= 20:
action = Gio.SimpleAction.new("shortcuts", None)
action.connect("activate", self.on_shortcuts)
self.add_action(action)
action = Gio.SimpleAction.new("about", None)
action.connect("activate", self.on_about)
self.add_action(action)
action = Gio.SimpleAction.new("quit", None)
action.connect("activate", self.on_quit)
self.add_action(action)
if not show_app_menu():
self.set_app_menu(self.menu)
logging.debug("Adding gnome shell menu")
application.py 文件源码
python
阅读 27
收藏 0
点赞 0
评论 0
评论列表
文章目录