Search code examples
pythongtkgtk3pygobject

Setting sensitivity of menu item associated with Gio.Action


I created a menubar using the Python bindings for GTK3 and Gio.Action instead of Gtk.Action, similar to how it is described in this answer.

But now I'm having trouble trying to dynamically set the sensitivity of a menu item (whether it is greyed out). Gtk.Action provides a simple set_sensitive method, but I can't find a clean way of getting the Gtk.Action associated with my Gio.Action. Gtk.Application only has methods for directly getting the Gio.MenuModels, not the Gtk.Menu, for instance.


Solution

  • Gio.SimpleAction.set_enabled()

    action = Gio.SimpleAction.new('my-action', None)
    action.set_enabled(False) # This makes it insensitive