AppChooserButton

An AppChooserButton allows the selection of applications via a dropdown menu. The use of an AppChooserButton is useful in applications which have limited space available.

Constructor

The AppChooserButton can be constructed using the following:

appchooserbutton = Gtk.AppChooserButton(content_type)

Setting the content_type to a MIME type allows the AppChooserButton to limit the applications shown to those which are able to open the content type specified.

Methods

By default, the AppChooserButton is displayed as a basic dropdown menu. To enable the advanced dropdown and associated dialog functionality, from which items are chosen use:

appchooserbutton.set_show_dialog_item(show_dialog_item)

If show_dialog_item is set to True, applications matching the MIME type are displayed in a dialog.

..note :

The AppChooserButton utilises the AppChooser backend for common methods and functions.

Signals

The commonly used signals of a AppChooserButton are:

"changed" (appchooserbutton)

The "changed" signal emits from the AppChooserButton when the user changes the application which is to open the item.

Example

Below is an example of a AppChooserButton:

#!/usr/bin/env python3

from gi.repository import Gtk

class AppChooserButton(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)
        self.set_default_size(200, -1)
        self.connect("destroy", Gtk.main_quit)

        appchooserbutton = Gtk.AppChooserButton(content_type="audio/flac")
        appchooserbutton.set_show_dialog_item(True)
        appchooserbutton.connect("changed", self.on_item_changed)
        self.add(appchooserbutton)

    def on_item_changed(self, appchooserbutton):
        app_info = appchooserbutton.get_app_info()
        name = app_info.get_display_name()
        description = app_info.get_description()

        print("Name:\t\t%s" % (name))
        print("Description:\t%s" % (description))

window = AppChooserButton()
window.show_all()

Gtk.main()

Download: AppChooserButton