Re: Programatically activate menu like a mouse click



On 23/02/17 15:23, Norbert de Jonge wrote:

I would guess with:
https://developer.gnome.org/gtk3/stable/GtkMenu.html#gtk-menu-popup-at-widget

Thanks, I have 3.22.5. I had tried `gtk-menu-popup-at-widget` but it
didn't work. I've tried lots of combinations to try and get it to work
without success.

Like this:

self.menu.popup_at_widget(self.anchor,Gdk.Gravity.SOUTH_WEST,Gdk.Gravity.NORTH_WEST,None)

I tried with self.menu being the first menu out of the uibuilder and
also with menu that I built manually (using Gtk.Menu, Gtk.MenuItem, etc)
and attached to the menubar. Both kinds of menu appear as expected and
work with the mouse just fine but they are different:

* The uimanager menu is <class 'gi.repository.Gtk.ImageMenuItem'>

* The manually built menu is <class 'gi.overrides.Gtk.Menu'>

This leads to different behaviour when I call popup_at_widget.

If I pull 'self.menu' out of UIManager then I get an error:

    self.menu.popup_at_widget(self.anchor,
          Gdk.Gravity.SOUTH_WEST,Gdk.Gravity.NORTH_WEST,None)
    AttributeError: 'ImageMenuItem' object has no attribute
         'popup_at_widget'

Whereas if I use the manually built menu I get warnings:

    Gtk-WARNING **: no trigger event for menu popup

    Warning: g_object_set_data: assertion 'G_IS_OBJECT (object)' failed
   self.menu.popup_at_widget(self.anchor,Gdk.Gravity.SOUTH_WEST,
    Gdk.Gravity.NORTH_WEST,None)

It makes no difference whether self.anchor is the box widget or the
menubar widget pulled from UI manager.

The menubar widget is <class 'gi.repository.Gtk.MenuBar'>
The box widget is box <class 'gi.overrides.Gtk.Box'>

It's available for GTK+ 3.22 and up, so I cannot test it to verify.

My other thought is that popup_at_widget is only 3.22+. I wanted to find
a solution that worked in Gtk3 and Gtk2 because I am evaluating both of
them (there are things I need that can't be done using Gtk3 without
falling back on Xlib).

So perhaps the above isn't the way, and there is another way to achieve
this...

I appreciate any help.
John




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]