RecentChooserMenu

The RecentChooserMenu provides a list of recently opened files which are displayed via a menu.

Constructor

The RecentChooserMenu can be constructed using the following:

recentchoosermenu = Gtk.RecentChooserMenu()

Methods

To configure whether numbers are displayed on the menu, use:

recentchoosermenu.set_show_numbers(show_numbers)

When the show_numbers attribute is set to False, numbers will not be displayed next to the recently opened files. The numbers also serve as a unique accelerator key to open the files via the keyboard.

Example

Below is an example of a RecentChooserMenu:

#!/usr/bin/env python3

from gi.repository import Gtk

class RecentChooserMenu(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)
        self.set_title('RecentChooserMenu')
        self.connect('destroy', Gtk.main_quit)

        menubar = Gtk.MenuBar()
        self.add(menubar)

        menuitem = Gtk.MenuItem('Recent Items')
        menubar.append(menuitem)

        recentchoosermenu = Gtk.RecentChooserMenu()
        recentchoosermenu.connect('item-activated', self.on_item_activated)
        menuitem.set_submenu(recentchoosermenu)

    def on_item_activated(self, recentchoosermenu):
        item = recentchoosermenu.get_current_item()

        if item:
            print("Item selected:")
            print("Name:\t %s" % (item.get_display_name()))
            print("URI:\t %s" % (item.get_uri()))

window = RecentChooserMenu()
window.show_all()

Gtk.main()

Download: RecentChooserMenu