GtkShortcutsWindow always in "search" mode
Hello. Not sure if here is the right place to ask but I am building an application that will show the shortcuts for the current active window using Python and GTK.
I am using the amazing GtkShortcutsWindow widget for that but I have a problem. It is always in "internal-search" mode. and by default it dont display any shortcuts. I am also having trouble displaying my shortcuts into groups. I tried to set the property "section-name" like in https://developer.gnome.org/gtk3/stable/GtkShortcutsWindow.html but it seems in doesnt have any effect.
Anyone can give me a hand?
Here is the code of my Window:
class AppWindow(object):
def __init__(self, application):
self.Application = application
self.shortcuts = {}
self.win = Gtk.ShortcutsWindow()
self.win.set_title("Shortcuts")
self.win.set_default_size(WINDOW_WIDTH, WINDOW_HEIGHT)
self.win.set_position(Gtk.WindowPosition.CENTER)
self.win.connect("delete-event", self.on_shortcuts_window_close)
self.win.set_application(application)
def on_shortcuts_window_close(self, window, event, data=None):
window.hide()
return True # dont close the window
def show(self):
self.win.show_all()
def set_shortcuts(self, shortcuts):
self.shortcuts = shortcuts
self.build_widgets()
def build_widgets(self):
if len(self.win.get_children()) > 0:
self.win.get_children()[0].destroy()
section = Gtk.ShortcutsSection()
section.set_property('section-name', "General")
for sectionName, items in self.shortcuts.iteritems():
group = Gtk.ShortcutsGroup(
title=sectionName)
section.add(group)
for shortcut in items:
title = shortcut.keys()[0]
accelerator = shortcut.values()[0]
short = Gtk.ShortcutsShortcut(
title=title, accelerator=accelerator)
short.show()
group.add(short)
self.win.set_property('section-name', "General")
self.win.add(section)
self.win.get_property('section-name')
And here is the result:
If I search something then my shortcuts appear.
Thank you for your help.