GNOME Bugzilla – Bug 671024
Tooltips don't appear on MenuBar objects
Last modified: 2018-05-02 15:20:47 UTC
Below is the following code from http://python-gtk-3-tutorial.readthedocs.org/en/latest/menus.html#example doesn't show tooltips on the MenuBar even though they are defined but show tooltips for other defined objects such as the ToolBar. Another menu system designed in Glade showed the tooltips in the menu appropriately. Here is the code that has been slightly modified from original: #! /usr/bin/env python # -*- coding: utf-8 -*- from gi.repository import Gtk, Gdk UI_INFO = """ <ui> <menubar name='MenuBar'> <menu action='FileMenu'> <menu action='FileNew'> <menuitem action='FileNewStandard' /> <menuitem action='FileNewFoo' /> <menuitem action='FileNewGoo' /> </menu> <separator /> <menuitem action='FileQuit' /> </menu> <menu action='EditMenu'> <menuitem action='EditCopy' /> <menuitem action='EditPaste' /> <menuitem action='EditSomething' /> </menu> <menu action='ChoicesMenu'> <menuitem action='ChoiceOne'/> <menuitem action='ChoiceTwo'/> <separator /> <menuitem action='ChoiceThree'/> </menu> </menubar> <toolbar name='ToolBar'> <toolitem action='FileNewStandard' /> <toolitem action='FileQuit' /> </toolbar> <popup name='PopupMenu'> <menuitem action='EditCopy' /> <menuitem action='EditPaste' /> <menuitem action='EditSomething' /> </popup> </ui> """ class MenuExampleWindow(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title="Menu Example") self.set_default_size(200, 200) action_group = Gtk.ActionGroup("my_actions") self.add_file_menu_actions(action_group) self.add_edit_menu_actions(action_group) self.add_choices_menu_actions(action_group) uimanager = self.create_ui_manager() uimanager.insert_action_group(action_group) menubar = uimanager.get_widget("/MenuBar") print menubar box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) box.pack_start(menubar, False, False, 0) toolbar = uimanager.get_widget("/ToolBar") box.pack_start(toolbar, False, False, 0) eventbox = Gtk.EventBox() eventbox.connect("button-press-event", self.on_button_press_event) box.pack_start(eventbox, True, True, 0) label = Gtk.Label("Right-click to see the popup menu.") label.set_tooltip_text('This is the label tooltip') eventbox.add(label) self.popup = uimanager.get_widget("/PopupMenu") self.add(box) def add_file_menu_actions(self, action_group): action_filemenu = Gtk.Action("FileMenu", "_File", "This should be the tooltip", None) action_group.add_action_with_accel(action_filemenu, None) action_filenewmenu = Gtk.Action("FileNew", None, None, Gtk.STOCK_NEW) action_group.add_action(action_filenewmenu) action_new = Gtk.Action("FileNewStandard", "_New", "Create a new file", Gtk.STOCK_NEW) action_new.connect("activate", self.on_menu_file_new_generic) action_group.add_action_with_accel(action_new, None) action_group.add_actions([ ("FileNewFoo", None, "New Foo", None, "Create new foo", self.on_menu_file_new_generic), ("FileNewGoo", None, "_New Goo", None, "Create new goo", self.on_menu_file_new_generic), ]) action_filequit = Gtk.Action("FileQuit", None, None, Gtk.STOCK_QUIT) action_filequit.connect("activate", self.on_menu_file_quit) action_group.add_action(action_filequit) def add_edit_menu_actions(self, action_group): action_group.add_actions([ ("EditMenu", None, "Edit"), ("EditCopy", Gtk.STOCK_COPY, None, None, None, self.on_menu_others), ("EditPaste", Gtk.STOCK_PASTE, None, None, None, self.on_menu_others), ("EditSomething", None, "Something", "<control><alt>S", None, self.on_menu_others) ]) def add_choices_menu_actions(self, action_group): action_group.add_action(Gtk.Action("ChoicesMenu", "Choices", None, None)) action_group.add_radio_actions([ ("ChoiceOne", None, "One", None, None, 1), ("ChoiceTwo", None, "Two", None, None, 2) ], 1, self.on_menu_choices_changed) three = Gtk.ToggleAction("ChoiceThree", "Three", None, None) three.connect("toggled", self.on_menu_choices_toggled) action_group.add_action(three) def create_ui_manager(self): uimanager = Gtk.UIManager() # Throws exception if something went wrong uimanager.add_ui_from_string(UI_INFO) # Add the accelerator group to the toplevel window accelgroup = uimanager.get_accel_group() self.add_accel_group(accelgroup) return uimanager def on_menu_file_new_generic(self, widget): print "A File|New menu item was selected." def on_menu_file_quit(self, widget): Gtk.main_quit() def on_menu_others(self, widget): print "Menu item " + widget.get_name() + " was selected" def on_menu_choices_changed(self, widget, current): print current.get_name() + " was selected." def on_menu_choices_toggled(self, widget): if widget.get_active(): print widget.get_name() + " activated" else: print widget.get_name() + " deactivated" def on_button_press_event(self, widget, event): # Check if right mouse button was preseed if event.type == Gdk.EventType.BUTTON_PRESS and event.button == 3: self.popup.popup(None, None, None, None, event.button, event.time) return True # event has been handled window = MenuExampleWindow() window.connect("delete-event", Gtk.main_quit) window.show_all() Gtk.main()
Confirmed with GTK 3.4.1 and pygobject 3.2.0. Could be related to the GtkAction override.
This looks like a bug in GTK. get_tooltip() verifies that the tool tip was set correctly, but it simply doesn't appear. Perhaps GTK deprecated having tool tips in menus?
(In reply to Martin Pitt from comment #2) > This looks like a bug in GTK. get_tooltip() verifies that the tool tip was > set correctly, but it simply doesn't appear. get_tooltip() on the GtkAction, you mean? It never gets anywhere, because the GTK+ Inspector shows me NULLs for all the tooltips on all widgets that make up the File menuitem. > Perhaps GTK deprecated having tool tips in menus? I've seen someone say they don't like it, but normal widget tooltips on menus seem to work A-OK. What is deprecated is GtkUiManager, GtkAction*, etc al. Still, that doesn't seem to explain why the tooltip never ends up on the widget here.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gtk/issues/385.