Gtk.AppChooserButton


Gtk.AppChooserButton — A button to launch an application chooser dialog

Object Hierarchy:

    GObject
    ╰── GInitiallyUnowned
        ╰── Gtk.Widget
            ╰── Gtk.Container
                ╰── Gtk.Bin
                    ╰── Gtk.ComboBox
                        ╰── Gtk.AppChooserButton

Functions:


Signals:

  • “custom-item-activated” (self, item_name, user_data)

Description:

The Gtk.AppChooserButton is a widget that lets the user select an application. It implements the Gtk.AppChooser interface.

Initially, a Gtk.AppChooserButton selects the first application in its list, which will either be the most-recently used application or, if Gtk.AppChooserButton::show-default-item is True, the default application.

The list of applications shown in a Gtk.AppChooserButton includes the recommended applications for the given content type. When Gtk.AppChooserButton::show-default-item is set, the default application is also included. To let the user chooser other applications, you can set the Gtk.AppChooserButton::show-dialog-item property, which allows to open a full Gtk.AppChooserDialog.

It is possible to add custom items to the list, using Gtk.AppChooserButton::append_custom_item(). These items cause the Gtk.AppChooserButton::custom-item-activated signal to be emitted when they are selected.

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

Function Details:

new()

new (content_type:str) -> Gtk.Widget

Creates a new Gtk.AppChooserButton for applicationsthat can handle content of the given type.

  • Returns: a newly created Gtk.AppChooserButton

  • Since: 3.0


append_custom_item()

append_custom_item (self, name:str, label:str, icon:Gio.Icon)

Appends a custom item to the list of applications that is shownin the popup; the item name must be unique per-widget.Clients can use the provided name as a detail for the“custom-item-activated” signal, to add acallback for the activation of a particular custom item in the list.See also Gtk.AppChooserButton:append_separator().

  • Since: 3.0

append_separator()

append_separator (self)

Appends a separator to the list of applications that is shownin the popup.

  • Since: 3.0

set_active_custom_item()

set_active_custom_item (self, name:str)

Selects a custom item previously added withGtk.AppChooserButton:append_custom_item(). Use `Gtk.AppChooser:refresh()` to bring the selectionto its initial state.

  • Since: 3.0

get_show_default_item()

get_show_default_item (self) -> bool

Returns the current value of the “show-default-item”property.

  • Returns: the value of “show-default-item”

  • Since: 3.2


set_show_default_item()

set_show_default_item (self, setting:bool)

Sets whether the dropdown menu of this button should show thedefault application for the given content type at top.

  • Since: 3.2

get_show_dialog_item()

get_show_dialog_item (self) -> bool

Returns the current value of the “show-dialog-item”property.

  • Returns: the value of “show-dialog-item”

  • Since: 3.0


set_show_dialog_item()

set_show_dialog_item (self, setting:bool)

Sets whether the dropdown menu of this button should show anentry to trigger a Gtk.AppChooserDialog.

  • Since: 3.0

get_heading()

get_heading (self) -> str

Returns the text to display at the top of the dialog.

  • Returns: the text to display at the top of the dialog,or None, in which case a default text is displayed

set_heading()

set_heading (self, heading:str)

Sets the text to display at the top of the dialog.If the heading is not set, the dialog displays a default text.


Example:

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

class AppChooserButton(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)
        self.set_title("AppChooserButton")
        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()

results matching ""

    No results matching ""