4

Below are two questions on the same component:

  1. Which signal is triggered when the mouse passes over a Gio.MenuItem?
  2. How to implement a tooltip for Gio.MenuItem?
Alex M
  • 2,756
  • 7
  • 29
  • 35
Matheus Saraiva
  • 1,144
  • 1
  • 11
  • 33

2 Answers2

3

Gio.MenuItem is a direct descendent from GObject.GObject (See https://lazka.github.io/pgi-docs/Gio-2.0/classes/MenuItem.html). It does not have any signals itself, and only receives a notify signal via its descent from GObject.

As Gio.MenuItem is not a widget, it does not receive any signals from the GUI. It only represents data (opaque data at that).

I suspect you want Gtk.MenuItem, which is the visual component.

EDIT It seems the widget you are after is Gtk.PopoverMenu. Just to be clear, Gio.MenuItem is not a visible item, which is why I replied as above. Gtk.PopoverMenu is a widget (widget = a visible item).

PopoverMenu is the visible widget, and you can see how it fits together with other widgets. It inherits from Popover, which inherits from Gtk.Bin, Gtk.Container and finally from Gtk.Widget.

So, you have all the signals from those widgets, but those are for the 'complete' Gtk.PopoverMenu, not for the individual items.

According to this definition, the individual items are Gtk.ModelButtons, so you might be able to access them that way.

jcoppens
  • 5,306
  • 6
  • 27
  • 47
  • Unfortunately GtkMenuItem does not have the same appearance as Gio.MenuItem :-\. For this reason I am using a Gio.MenuItem instead of a GtkMenuItem. – Matheus Saraiva Aug 16 '16 at 23:12
  • Can you show the part of the program where you actually use Gio.Menuitem? – jcoppens Aug 16 '16 at 23:25
  • My intention is to make a menu like [this](http://oi64.tinypic.com/dg3sq1.jpg). This is the menu of `Devhelp` application – Matheus Saraiva Aug 16 '16 at 23:36
  • If I use GtkMenu and GtkMenuItem I get [this](http://oi67.tinypic.com/2n84k7c.jpg) appearance. That is, I get a squared menu without rounded corners – Matheus Saraiva Aug 16 '16 at 23:49
  • Thanks for taking some of your time to answer. I saw in the documentation that GtkPopoverMenu is available from version 3.16 of GTK. But my OS (Debian 8.5) uses GTK 3.14. Is there another way to get a menu like it? Curiosity: If my operating system uses gtk 3.14, how the Devhelp application has a PopoverMenu? The Devhelp's version is 3.14 too. – Matheus Saraiva Aug 17 '16 at 13:43
  • I downloaded the [Devhelp's code 3.14](http://ftp.gnome.org/mirror/gnome.org/sources/devhelp/3.14/) but still can not find the part of code related to PopoverMenu. – Matheus Saraiva Aug 17 '16 at 14:02
  • After a little more research, I found that Gio.Menu and Gio.MenuItem implement a "new" concept, a different concept of Gtk signals. This "new" concept is called Actions. So if I want something to happen when a Gio.MenuItem is clicked I need to associate it to an Action. In [an example](http://paste.debian.net/790265) I tried to implement an action for an GMenuItem, but is not working. – Matheus Saraiva Aug 18 '16 at 13:37
  • PopoverMenu is documented in [Lazca's PGI API](https://lazka.github.io/pgi-docs/), particularly in [this place](https://lazka.github.io/pgi-docs/#Gtk-3.0/classes/PopoverMenu.html). This documentation is 'priceless', and very well updated. You can download it and browse it locally. – jcoppens Aug 18 '16 at 14:09
  • PopoverMenu does not fit my case because my version of GTK is 3.14. I think the solution to this case is `Gio.Menu`, `Gio.MenuItem` using `Gio.SimpleAction`. I created a [new question](http://stackoverflow.com/questions/39020511/understanding-the-concept-of-actions) about the Actions feature. – Matheus Saraiva Aug 18 '16 at 14:24
  • Actions are a way to centralize the code for several widgets. Eg. if you have a program, you typicially have a File menu, with an Open option. Then you have a toolbar with an 'Open' button. You can then make both point to the same Action to do the work. – jcoppens Aug 18 '16 at 15:09
  • I understand that actions are also the way you can give functionality to `GMenuItem`, since these do not use signs like Gtk components. So I think I can use `GMenu` and `GMenuItem` to get the menu that I want. And give roles to `MenuItem` through actions. But what's wrong with my [test](http://paste.debian.net/790301)? – Matheus Saraiva Aug 18 '16 at 15:41
1

The solution to get this was much further than I thought. I always suspected that the Devhelp's menu could not be built using GtkPopoverMenu because my OS uses gtk 3.14. The solution involves a totally new concept of running an application, proposed by Gtk.Application interface and the Gtk.Action features. These "new" concepts can be studied in the following places.

http://python-gtk-3-tutorial.readthedocs.io/en/latest/application.html?highlight=Gtk.Application

https://wiki.gnome.org/HowDoI/GtkApplication

https://github.com/Programmica/python-gtk3-tutorial/blob/master/_examples/application.py

Apparently tooltip features are not available for this menu type.

Matheus Saraiva
  • 1,144
  • 1
  • 11
  • 33