我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用gi.repository.Gio.Menu()。
def do_activate(self): self.menu_ext = self.extend_menu("tools-section") menu = Gio.Menu() item1 = Gio.MenuItem.new("Start Dict'O'nator", 'win.dictonator_start') item2 = Gio.MenuItem.new("Stop Dict'O'nator", 'win.dictonator_stop') item3 = Gio.MenuItem.new("Setup Dict'O'nator", 'win.dictonator_setup') item4 = Gio.MenuItem.new("Logit Dict'O'nator", 'win.dictonator_logit') menu.append_item(item1) menu.append_item(item2) menu.append_item(item3) menu.append_item(item4) menu_item = Gio.MenuItem.new_submenu("Dict'O'nator", menu) self.menu_ext.append_menu_item(menu_item) self.app.set_accels_for_action("win.dictonator_start", ("<Primary><Alt>2", None)) self.app.set_accels_for_action("win.dictonator_stop", ("<Primary><Alt>3", None)) self.app.set_accels_for_action("win.dictonator_setup", ("<Primary><Alt>4", None)) self.app.set_accels_for_action("win.dictonator_logit", ("<Primary><Alt>5", None))
def activateCb(self, app): window = builder.get_object("window") window.set_wmclass("Mastodon GTK", "Mastodon GTK") window.set_title("Mastodon GTK") app.add_window(window) appMenu = Gio.Menu() appMenu.append("About", "app.about") appMenu.append("Quit", "app.quit") about_action = Gio.SimpleAction.new("about", None) about_action.connect("activate", self.on_about_activate) builder.get_object("aboutdialog").connect( "delete-event", lambda *_: builder.get_object("aboutdialog").hide() or True) app.add_action(about_action) quit_action = Gio.SimpleAction.new("quit", None) quit_action.connect("activate", self.on_quit_activate) app.add_action(quit_action) app.set_app_menu(appMenu) window.show_all()
def activateCb(self, app): window = builder.get_object("window") window.set_wmclass("Gesture Manager", "Gesture Manager") window.set_title("Gesture Manager") app.add_window(window) appMenu = Gio.Menu() appMenu.append("About", "app.about") appMenu.append("Quit", "app.quit") about_action = Gio.SimpleAction.new("about", None) about_action.connect("activate", self.on_about_activate) builder.get_object("aboutdialog").connect( "delete-event", lambda *_: builder.get_object("aboutdialog").hide() or True) app.add_action(about_action) quit_action = Gio.SimpleAction.new("quit", None) quit_action.connect("activate", self.on_quit_activate) app.add_action(quit_action) app.set_app_menu(appMenu) window.show_all()
def __init__(self): Gtk.Application.__init__(self, application_id="org.gnome.IconRequests", flags=Gio.ApplicationFlags.FLAGS_NONE) GLib.set_application_name(_("Icon Requests")) GLib.set_prgname("Icon Requests") Gtk.Settings.get_default().set_property( "gtk-application-prefer-dark-theme", settings.get_is_night_mode()) self.menu = Gio.Menu() cssProviderFile = Gio.File.new_for_uri( 'resource:///org/gnome/IconRequests/css/style.css') cssProvider = Gtk.CssProvider() screen = Gdk.Screen.get_default() styleContext = Gtk.StyleContext() try: cssProvider.load_from_file(cssProviderFile) styleContext.add_provider_for_screen(screen, cssProvider, Gtk.STYLE_PROVIDER_PRIORITY_USER) logging.debug("Loading css file ") except Exception as e: logging.error("Error message %s" % str(e))
def generate_menu(self): # Help section help_content = Gio.Menu.new() help_content.append_item(Gio.MenuItem.new(_("Night Mode"), "app.night_mode")) 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) 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) 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 is_gnome() and not is_app_menu(): self.set_app_menu(self.menu) logging.debug("Adding gnome shell menu")
def __init__(self): Gtk.Application.__init__(self, application_id="org.gnome.Authenticator", flags=Gio.ApplicationFlags.FLAGS_NONE) GLib.set_application_name(_("Gnome Authenticator")) GLib.set_prgname("Gnome Authenticator") self.observable = ApplicaitonObservable() self.menu = Gio.Menu() self.db = Database() result = GK.unlock_sync("org.gnome.Authenticator", None) if result == GK.Result.CANCELLED: self.quit() Gtk.Settings.get_default().set_property( "gtk-application-prefer-dark-theme", settings.get_is_night_mode()) if Gtk.get_major_version() >= 3 and Gtk.get_minor_version() >= 20: cssFileName = "org.gnome.Authenticator-post3.20.css" else: cssFileName = "org.gnome.Authenticator-pre3.20.css" cssProviderFile = Gio.File.new_for_uri( 'resource:///org/gnome/Authenticator/%s' % cssFileName) cssProvider = Gtk.CssProvider() screen = Gdk.Screen.get_default() styleContext = Gtk.StyleContext() try: cssProvider.load_from_file(cssProviderFile) styleContext.add_provider_for_screen(screen, cssProvider, Gtk.STYLE_PROVIDER_PRIORITY_USER) logging.debug("Loading css file ") except Exception as e: logging.error("Error message %s" % str(e))
def do_startup(self): print("Starting up...") Gtk.Application.do_startup(self) menu = Gio.Menu() for action, is_menu_item, callback in self._actions: if is_menu_item: menu.append(action.capitalize(), "app.%s" % action) simple_action = Gio.SimpleAction.new(action, None) simple_action.connect('activate', callback) self.add_action(simple_action) self.set_app_menu(menu)
def __init__(self, bus): self.get_config() self.bus = bus self.action_group = Gio.SimpleActionGroup() self.menu = Gio.Menu() self.sub_menu = Gio.Menu() self.current_condition_icon = self.CLEAR self.current_condition_text = 'Clear' self.current_temperature = 75 self.error = 'No weather data yet'
def _create_section(self): section = Gio.Menu() current_menu_item = Gio.MenuItem.new(self.current_state(), 'indicator.{}'.format(self.CURRENT_ACTION)) icon = Gio.ThemedIcon.new_with_default_fallbacks(self.current_icon()) current_menu_item.set_attribute_value('icon', icon.serialize()) section.append_item(current_menu_item) settings_menu_item = Gio.MenuItem.new(_('Forecast'), 'indicator.{}'.format(self.FORECAST_ACTION)) section.append_item(settings_menu_item) settings_menu_item = Gio.MenuItem.new(_('Weather Settings'), 'indicator.{}'.format(self.SETTINGS_ACTION)) section.append_item(settings_menu_item) return section
def do_activate(self): window = self.builder.get_object('window') self.add_window(window) window.set_wmclass('razerCommander', 'razerCommander') window.set_title('razerCommander') appMenu = Gio.Menu() appMenu.append("About", "app.about") appMenu.append("Quit", "app.quit") about_action = Gio.SimpleAction.new("about", None) about_action.connect("activate", self.on_about_activate) self.builder.get_object("aboutdialog").connect( "delete-event", lambda *_: self.builder.get_object("aboutdialog").hide() or True ) self.add_action(about_action) quit_action = Gio.SimpleAction.new("quit", None) quit_action.connect("activate", self.on_quit_activate) self.add_action(quit_action) self.set_app_menu(appMenu) # initialization protocols self.refreshDevices() self.refreshProfiles() self.keyboardBox.hide() self.updateDevicesConnected() # Quit if we only need initialization if self.args.quit_after_init: self.quit() window.show_all() self.updateDevicesConnected() self.refreshFxList() self.keyboardBox.hide()
def do_startup(self): Gtk.Application.do_startup(self) menu = Gio.Menu() menu.append("Preferences", "app.preferences") menu.append("About", "app.about") menu.append("Quit", "app.quit") self.set_app_menu(menu) self.add_simple_action('preferences', self.on_action_preferences_activated) self.add_simple_action('about', self.on_action_about_activated) self.add_simple_action('quit', self.on_action_quit_activated)
def do_startup(self): # start the application Gtk.Application.do_startup(self) # create a menu menu = Gio.Menu() # append to the menu three options menu.append("New", "app.new") menu.append("About", "app.about") menu.append("Quit", "app.quit") # set the menu as menu of the application self.set_app_menu(menu) # create an action for the option "new" of the menu new_action = Gio.SimpleAction.new("new", None) # connect it to the callback function new_cb new_action.connect("activate", self.quit_cb) # add the action to the application self.add_action(new_action) # option "about" about_action = Gio.SimpleAction.new("about", None) about_action.connect("activate", self.quit_cb) self.add_action(about_action) # option "quit" quit_action = Gio.SimpleAction.new("quit", None) quit_action.connect("activate", self.quit_cb) self.add_action(quit_action) # callback function for "quit"
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")