Gtk.FileChooserButton


Gtk.FileChooserButton — A button to launch a file selection dialog

Object Hierarchy:

    GObject
    ╰── GInitiallyUnowned
        ╰── Gtk.Widget
            ╰── Gtk.Container
                ╰── Gtk.Box
                    ╰── Gtk.FileChooserButton

See also:

Gtk.FileChooserDialog


Functions:

Description:

The Gtk.FileChooserButton is a widget that lets the user select a file.

It implements the Gtk.FileChooser interface. Visually, it is a file name with a button to bring up a Gtk.FileChooserDialog.

The user can then use that dialog to change the file associated with that button. This widget does not support setting the select_multiple property to true .

  • Create a button to let the user select a file in /etc:
    filechooserbutton = Gtk.FileChooserButton(title="FileChooserButton")
    filechooserbutton.set_current_folder('/etc')
}

The Gtk.FileChooserButton supports the Gtk.FileChooserActions %GTK_FILE_CHOOSER_ACTION_OPEN and %GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER.

  • Note:

The Gtk.FileChooserButton will ellipsize the label, and will thus request little horizontal space. To give the button more space, you should call Gtk.Widget::get_preferred_size(), Gtk.FileChooserButton::set_width_chars(), or pack the button in such a way that other interface elements give space to the widget.


Function Details:

new()

new (title:str, action:Gtk.FileChooserAction) -> Gtk.Widget

Creates a new file-selecting button widget.

  • Returns: a new button widget.

  • Since: 2.6


new_with_dialog()

new_with_dialog (dialog:Gtk.Dialog) -> Gtk.Widget

Creates a `Gtk.FileChooserButtonwidget which usesdialogas itsfile-picking window. Note thatdialogmust be aGtk.Dialog(or subclass) whichimplements theGtk.FileChooserinterface and must not haveGTK_DIALOG_DESTROY_WITH_PARENTset. Also note that the dialog needs to have its confirmative buttonadded with responseGTK_RESPONSE_ACCEPTorGTK_RESPONSE_OK` inorder for the button to take over the file selected in the dialog.

  • Returns: a new button widget.

  • Since: 2.6


get_title()

get_title (self) -> str

Retrieves the title of the browse dialog used by button. The returned valueshould not be modified or freed.

  • Returns: a pointer to the browse dialog’s title.

  • Since: 2.6


set_title()

set_title (self, title:str)

Modifies the title of the browse dialog used by button.

  • Since: 2.6

get_width_chars()

get_width_chars (self) -> int

Retrieves the width in characters of the button widget’s entry and/or label.

  • Returns: an integer width (in characters) that the button will use to size itself.

  • Since: 2.6


set_width_chars()

set_width_chars (self, n_chars:int)

Sets the width (in characters) that button will use to n_chars.

  • Since: 2.6

get_focus_on_click()

get_focus_on_click (self) -> bool

Returns whether the button grabs focus when it is clicked with the mouse.See Gtk.FileChooserButton:set_focus_on_click().

  • Returns: True if the button grabs focus when it is clicked withthe mouse.

  • Since: 2.10


set_focus_on_click()

set_focus_on_click (self, focus_on_click:bool)

Sets whether the button will grab focus when it is clicked with the mouse.Making mouse clicks not grab focus is useful in places like toolbars whereyou don’t want the keyboard focus removed from the main area of theapplication.

  • Since: 2.10

Example:

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

def file_changed(filechooserbutton):
    print("File selected: %s" % filechooserbutton.get_filename())

window = Gtk.Window()
window.set_title("FileChooserButton")
window.set_default_size(150, -1)
window.connect("destroy", Gtk.main_quit)

filechooserbutton = Gtk.FileChooserButton(title="FileChooserButton")
filechooserbutton.connect("file-set", file_changed)
window.add(filechooserbutton)

window.show_all()

Gtk.main()

results matching ""

    No results matching ""