Gtk.RecentChooserDialog


Gtk.RecentChooserDialog — Displays recently used files in a dialog

Object Hierarchy:

    GObject
    ╰── GInitiallyUnowned
        ╰── Gtk.Widget
            ╰── Gtk.Container
                ╰── Gtk.Bin
                    ╰── Gtk.Window
                        ╰── Gtk.Dialog
                            ╰── Gtk.RecentChooserDialog

See also:

Gtk.RecentChooser, Gtk.Dialog


Functions:

  • new () -> Gtk.Widget

Description:

Gtk.RecentChooserDialog is a dialog box suitable for displaying the recently used documents. This widgets works by putting a Gtk.RecentChooserWidget inside a GtkDialog. It exposes the Gtk.RecentChooserIface interface, so you can use all the Gtk.RecentChooser functions on the recent chooser dialog as well as those for Gtk.Dialog.

Note that Gtk.RecentChooserDialog does not have any methods of its own.

Instead, you should use the functions that work on a Gtk.RecentChooser.

Typical usage:

In the simplest of cases, you can use the following code to use a Gtk.RecentChooserDialog to select a recently used file:

    def on_button_clicked(self, button):
        dialog = Gtk.RecentChooserDialog(parent=self)    
        dialog.add_button('Cancel', Gtk.ResponseType.CANCEL)
        dialog.add_button('OK', Gtk.ResponseType.OK)
        dialog.set_default_response(Gtk.ResponseType.OK)
        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            item = dialog.get_current_item()
            if item:
                print('Item selected:')
                print('Name:\t %s' % (item.get_display_name()))
                print('URI:\t %s' % (item.get_uri()))            
        dialog.destroy()

Recently used files are supported since GTK+ 2.10.


Function Details:

new()

new () -> Gtk.Widget

Creates a new Gtk.RecentChooserDialog. This function is analogous to`Gtk.Dialog:new_with_buttons()`.

  • Returns: a new Gtk.RecentChooserDialog

  • Since: 2.10


Example:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

class RecentChooserDialog(Gtk.RecentChooserDialog):
    def __init__(self):
        Gtk.RecentChooserDialog.__init__(self)
        self.set_title('RecentChooserDialog')
        self.set_default_size(250, -1)
        self.add_button('Cancel', Gtk.ResponseType.CANCEL)
        self.add_button('OK', Gtk.ResponseType.OK)
        self.set_default_response(Gtk.ResponseType.OK)
        self.connect('response', self.on_response)

    def on_response(self, recentchooserdialog, response):
        if response == Gtk.ResponseType.OK:
            item = recentchooserdialog.get_current_item()

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

dialog = RecentChooserDialog()
dialog.run()
dialog.destroy()

results matching ""

    No results matching ""