Gtk.RecentChooserMenu


Gtk.RecentChooserMenu — Displays recently used files in a menu

Object Hierarchy:

    GObject
    ╰── GInitiallyUnowned
        ╰── Gtk.Widget
            ╰── Gtk.Container
                ╰── Gtk.MenuShell
                    ╰── Gtk.Menu
                        ╰── Gtk.RecentChooserMenu

See also:

Gtk.RecentChooser


Functions:

Description:

Gtk.RecentChooserMenu is a widget suitable for displaying recently used files inside a menu. It can be used to set a sub-menu of a Gtk.MenuItem using Gtk.MenuItem::set_submenu(), or as the menu of a Gtk.MenuToolButton.

Note that Gtk.RecentChooserMenu does not have any methods of its own. Instead, you should use the functions that work on a Gtk.RecentChooser.

Note also that Gtk.RecentChooserMenu does not support multiple filters, as it has no way to let the user choose between them as the Gtk.RecentChooserWidget and Gtk.RecentChooserDialog widgets do. Thus using Gtk.RecentChooser::add_filter() on a Gtk.RecentChooserMenu widget will yield the same effects as using Gtk.RecentChooser::set_filter(), replacing any currently set filter with the supplied filter; Gtk.RecentChooser::remove_filter() will remove any currently set Gtk.RecentFilter object and will unset the current filter; Gtk.RecentChooser::list_filters() will return a list containing a single Gtk.RecentFilter object.

Recently used files are supported since GTK+ 2.10.


Function Details:

new()

new () -> Gtk.Widget

Creates a new Gtk.RecentChooser`Menu` widget. This kind of widget shows the list of recently used resources asa menu, each item as a menu item. Each item inside the menu mighthave an icon, representing its MIME type, and a number, for mnemonicaccess. This widget implements the `Gtk.RecentChooser` interface. This widget creates its own `Gtk.RecentManager` object. See the`Gtk.RecentChooserMenu:new_for_manager()` function to know how to createaGtk.RecentChooserMenu widget bound to another Gtk.RecentManager object.

  • Returns: a new Gtk.RecentChooserMenu

  • Since: 2.10


new_for_manager()

new_for_manager (manager:Gtk.RecentManager) -> Gtk.Widget

Creates a new Gtk.RecentChooser`Menu` widget using `manager` asthe underlying recently used resources manager. This is useful if you have implemented your own recent manager,or if you have a customized instance of aGtk.RecentManagerobject or if you wish to share a common Gtk.RecentManager objectamong multiple Gtk.RecentChooser widgets.

  • Returns: a new Gtk.RecentChooserMenu, bound to manager.

  • Since: 2.10


get_show_numbers()

get_show_numbers (self) -> bool

Returns the value set by Gtk.RecentChooserMenu:set_show_numbers().

  • Returns: True if numbers should be shown.

  • Since: 2.10


set_show_numbers()

set_show_numbers (self, show_numbers:bool)

Sets whether a number should be added to the items of menu. Thenumbers are shown to provide a unique character for a mnemonic tobe used inside ten menu item’s label. Only the first the itemsget a number to avoid clashes.

  • Since: 2.10

Example:

import gi
gi.require_version('Gtk', '3.0')
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()

results matching ""

    No results matching ""