Gtk.PlacesSidebar

g Atk.ImplementorIface Atk.ImplementorIface Gtk.Widget Gtk.Widget Atk.ImplementorIface->Gtk.Widget GObject.GInterface GObject.GInterface GObject.GInterface->Atk.ImplementorIface Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable GObject.InitiallyUnowned GObject.InitiallyUnowned GObject.InitiallyUnowned->Gtk.Widget GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned Gtk.Bin Gtk.Bin Gtk.ScrolledWindow Gtk.ScrolledWindow Gtk.Bin->Gtk.ScrolledWindow Gtk.Buildable->Gtk.Widget Gtk.Container Gtk.Container Gtk.Container->Gtk.Bin Gtk.PlacesSidebar Gtk.PlacesSidebar Gtk.ScrolledWindow->Gtk.PlacesSidebar Gtk.Widget->Gtk.Container

Example

../_images/PlacesSidebar.png
Subclasses:

None

Methods

Inherited:

Gtk.ScrolledWindow (33), Gtk.Bin (1), Gtk.Container (35), Gtk.Widget (278), GObject.Object (37), Gtk.Buildable (10)

Structs:

Gtk.ContainerClass (5), Gtk.WidgetClass (12), GObject.ObjectClass (5)

class

new ()

add_shortcut (location)

get_local_only ()

get_location ()

get_nth_bookmark (n)

get_open_flags ()

get_show_connect_to_server ()

get_show_desktop ()

get_show_enter_location ()

get_show_other_locations ()

get_show_recent ()

get_show_starred_location ()

get_show_trash ()

list_shortcuts ()

remove_shortcut (location)

set_drop_targets_visible (visible, context)

set_local_only (local_only)

set_location (location)

set_open_flags (flags)

set_show_connect_to_server (show_connect_to_server)

set_show_desktop (show_desktop)

set_show_enter_location (show_enter_location)

set_show_other_locations (show_other_locations)

set_show_recent (show_recent)

set_show_starred_location (show_starred_location)

set_show_trash (show_trash)

Virtual Methods

Inherited:

Gtk.ScrolledWindow (2), Gtk.Container (10), Gtk.Widget (82), GObject.Object (7), Gtk.Buildable (10)

Properties

Inherited:

Gtk.ScrolledWindow (15), Gtk.Container (3), Gtk.Widget (39)

Name

Type

Flags

Short Description

local-only

bool

r/w

Whether the sidebar only includes local files

location

Gio.File

r/w

The location to highlight in the sidebar

open-flags

Gtk.PlacesOpenFlags

r/w

Modes in which the calling application can open locations selected in the sidebar

populate-all

bool

r/w

Whether to emit ::populate-popup for popups that are not menus

show-connect-to-server

bool

d/r/w

Whether the sidebar includes a builtin shortcut to a ‘Connect to server’ dialog deprecated

show-desktop

bool

r/w

Whether the sidebar includes a builtin shortcut to the Desktop folder

show-enter-location

bool

r/w

Whether the sidebar includes a builtin shortcut to manually enter a location

show-other-locations

bool

r/w

Whether the sidebar includes an item to show external locations

show-recent

bool

r/w

Whether the sidebar includes a builtin shortcut for recent files

show-starred-location

bool

r/w

Whether the sidebar includes an item to show starred files

show-trash

bool

r/w

Whether the sidebar includes a builtin shortcut to the Trash location

Style Properties

Inherited:

Gtk.ScrolledWindow (2), Gtk.Widget (17)

Signals

Inherited:

Gtk.ScrolledWindow (4), Gtk.Container (4), Gtk.Widget (69), GObject.Object (1)

Name

Short Description

drag-action-ask

The places sidebar emits this signal when it needs to ask the application to pop up a menu to ask the user for which drag action to perform.

drag-action-requested

When the user starts a drag-and-drop operation and the sidebar needs to ask the application for which drag action to perform, then the sidebar will emit this signal.

drag-perform-drop

The places sidebar emits this signal when the user completes a drag-and-drop operation and one of the sidebar’s items is the destination.

mount

The places sidebar emits this signal when it starts a new operation because the user clicked on some location that needs mounting.

open-location

The places sidebar emits this signal when the user selects a location in it.

populate-popup

The places sidebar emits this signal when the user invokes a contextual popup on one of its items.

show-connect-to-server

The places sidebar emits this signal when it needs the calling application to present an way to connect directly to a network server. deprecated

show-enter-location

The places sidebar emits this signal when it needs the calling application to present an way to directly enter a location.

show-error-message

The places sidebar emits this signal when it needs the calling application to present an error message.

show-other-locations

The places sidebar emits this signal when it needs the calling application to present a way to show other locations e.g. deprecated

show-other-locations-with-flags

The places sidebar emits this signal when it needs the calling application to present a way to show other locations e.g.

show-starred-location

The places sidebar emits this signal when it needs the calling application to present a way to show the starred files.

unmount

The places sidebar emits this signal when it starts a new operation because the user for example ejected some drive or unmounted a mount.

Fields

Inherited:

Gtk.ScrolledWindow (4), Gtk.Container (4), Gtk.Widget (69), GObject.Object (1)

Class Details

class Gtk.PlacesSidebar(*args, **kwargs)
Bases:

Gtk.ScrolledWindow

Abstract:

No

Structure:

Gtk.PlacesSidebarClass

Gtk.PlacesSidebar is a widget that displays a list of frequently-used places in the file system: the user’s home directory, the user’s bookmarks, and volumes and drives. This widget is used as a sidebar in Gtk.FileChooser and may be used by file managers and similar programs.

The places sidebar displays drives and volumes, and will automatically mount or unmount them when the user selects them.

Applications can hook to various signals in the places sidebar to customize its behavior. For example, they can add extra commands to the context menu of the sidebar.

While bookmarks are completely in control of the user, the places sidebar also allows individual applications to provide extra shortcut folders that are unique to each application. For example, a Paint program may want to add a shortcut for a Clipart folder. You can do this with Gtk.PlacesSidebar.add_shortcut().

To make use of the places sidebar, an application at least needs to connect to the Gtk.PlacesSidebar ::open-location signal. This is emitted when the user selects in the sidebar a location to open. The application should also call Gtk.PlacesSidebar.set_location() when it changes the currently-viewed location.

CSS nodes

Gtk.PlacesSidebar uses a single CSS node with name placessidebar and style class .sidebar.

Among the children of the places sidebar, the following style classes can be used:

  • .sidebar-new-bookmark-row for the ‘Add new bookmark’ row

  • .sidebar-placeholder-row for a row that is a placeholder

  • .has-open-popup when a popup is open for a row

classmethod new()[source]
Returns:

a newly created Gtk.PlacesSidebar

Return type:

Gtk.Widget

Creates a new Gtk.PlacesSidebar widget.

The application should connect to at least the Gtk.PlacesSidebar ::open-location signal to be notified when the user makes a selection in the sidebar.

New in version 3.10.

add_shortcut(location)[source]
Parameters:

location (Gio.File) – location to add as an application-specific shortcut

Applications may want to present some folders in the places sidebar if they could be immediately useful to users. For example, a drawing program could add a “/usr/share/clipart” location when the sidebar is being used in an “Insert Clipart” dialog box.

This function adds the specified location to a special place for immutable shortcuts. The shortcuts are application-specific; they are not shared across applications, and they are not persistent. If this function is called multiple times with different locations, then they are added to the sidebar’s list in the same order as the function is called.

New in version 3.10.

get_local_only()[source]
Returns:

True if the sidebar will only show local files.

Return type:

bool

Returns the value previously set with Gtk.PlacesSidebar.set_local_only().

New in version 3.12.

get_location()[source]
Returns:

a Gio.File with the selected location, or None if nothing is visually selected.

Return type:

Gio.File or None

Gets the currently selected location in the self. This can be None when nothing is selected, for example, when Gtk.PlacesSidebar.set_location() has been called with a location that is not among the sidebar’s list of places to show.

You can use this function to get the selection in the self. Also, if you connect to the Gtk.PlacesSidebar ::populate-popup signal, you can use this function to get the location that is being referred to during the callbacks for your menu items.

New in version 3.10.

get_nth_bookmark(n)[source]
Parameters:

n (int) – index of the bookmark to query

Returns:

The bookmark specified by the index n, or None if no such index exist. Note that the indices start at 0, even though the file chooser starts them with the keyboard shortcut “Alt-1”.

Return type:

Gio.File or None

This function queries the bookmarks added by the user to the places sidebar, and returns one of them. This function is used by Gtk.FileChooser to implement the “Alt-1”, “Alt-2”, etc. shortcuts, which activate the cooresponding bookmark.

New in version 3.10.

get_open_flags()[source]
Returns:

the Gtk.PlacesOpenFlags of self

Return type:

Gtk.PlacesOpenFlags

Gets the open flags.

New in version 3.10.

get_show_connect_to_server()[source]
Returns:

True if the sidebar will display a “Connect to Server” item.

Return type:

bool

Returns the value previously set with Gtk.PlacesSidebar.set_show_connect_to_server()

Deprecated since version 3.18: It is recommended to group this functionality with the drives and network location under the new ‘Other Location’ item

get_show_desktop()[source]
Returns:

True if the sidebar will display a builtin shortcut to the desktop folder.

Return type:

bool

Returns the value previously set with Gtk.PlacesSidebar.set_show_desktop()

New in version 3.10.

get_show_enter_location()[source]
Returns:

True if the sidebar will display an “Enter Location” item.

Return type:

bool

Returns the value previously set with Gtk.PlacesSidebar.set_show_enter_location()

New in version 3.14.

get_show_other_locations()[source]
Returns:

True if the sidebar will display an “Other Locations” item.

Return type:

bool

Returns the value previously set with Gtk.PlacesSidebar.set_show_other_locations()

New in version 3.18.

get_show_recent()[source]
Returns:

True if the sidebar will display a builtin shortcut for recent files

Return type:

bool

Returns the value previously set with Gtk.PlacesSidebar.set_show_recent()

New in version 3.18.

get_show_starred_location()[source]
Returns:

True if the sidebar will display a Starred item.

Return type:

bool

Returns the value previously set with Gtk.PlacesSidebar.set_show_starred_location()

New in version 3.22.26.

get_show_trash()[source]
Returns:

True if the sidebar will display a “Trash” item.

Return type:

bool

Returns the value previously set with Gtk.PlacesSidebar.set_show_trash()

New in version 3.18.

list_shortcuts()[source]
Returns:

A GLib.SList of Gio.File of the locations that have been added as application-specific shortcuts with Gtk.PlacesSidebar.add_shortcut(). To free this list, you can use

g_slist_free_full (list, (GDestroyNotify) g_object_unref);

Return type:

[Gio.File]

Gets the list of shortcuts.

New in version 3.10.

remove_shortcut(location)[source]
Parameters:

location (Gio.File) – location to remove

Removes an application-specific shortcut that has been previously been inserted with Gtk.PlacesSidebar.add_shortcut(). If the location is not a shortcut in the sidebar, then nothing is done.

New in version 3.10.

set_drop_targets_visible(visible, context)[source]
Parameters:
  • visible (bool) – whether to show the valid targets or not.

  • context (Gdk.DragContext) – drag context used to ask the source about the action that wants to perform, so hints are more accurate.

Make the Gtk.PlacesSidebar show drop targets, so it can show the available drop targets and a “new bookmark” row. This improves the Drag-and-Drop experience of the user and allows applications to show all available drop targets at once.

This needs to be called when the application is aware of an ongoing drag that might target the sidebar. The drop-targets-visible state will be unset automatically if the drag finishes in the Gtk.PlacesSidebar. You only need to unset the state when the drag ends on some other widget on your application.

New in version 3.18.

set_local_only(local_only)[source]
Parameters:

local_only (bool) – whether to show only local files

Sets whether the self should only show local files.

New in version 3.12.

set_location(location)[source]
Parameters:

location (Gio.File or None) – location to select, or None for no current path

Sets the location that is being shown in the widgets surrounding the self, for example, in a folder view in a file manager. In turn, the self will highlight that location if it is being shown in the list of places, or it will unhighlight everything if the location is not among the places in the list.

New in version 3.10.

set_open_flags(flags)[source]
Parameters:

flags (Gtk.PlacesOpenFlags) – Bitmask of modes in which the calling application can open locations

Sets the way in which the calling application can open new locations from the places sidebar. For example, some applications only open locations “directly” into their main view, while others may support opening locations in a new notebook tab or a new window.

This function is used to tell the places self about the ways in which the application can open new locations, so that the sidebar can display (or not) the “Open in new tab” and “Open in new window” menu items as appropriate.

When the Gtk.PlacesSidebar ::open-location signal is emitted, its flags argument will be set to one of the flags that was passed in Gtk.PlacesSidebar.set_open_flags().

Passing 0 for flags will cause Gtk.PlacesOpenFlags.NORMAL to always be sent to callbacks for the “open-location” signal.

New in version 3.10.

set_show_connect_to_server(show_connect_to_server)[source]
Parameters:

show_connect_to_server (bool) – whether to show an item for the Connect to Server command

Sets whether the self should show an item for connecting to a network server; this is off by default. An application may want to turn this on if it implements a way for the user to connect to network servers directly.

If you enable this, you should connect to the Gtk.PlacesSidebar ::show-connect-to-server signal.

New in version 3.10.

Deprecated since version 3.18: It is recommended to group this functionality with the drives and network location under the new ‘Other Location’ item

set_show_desktop(show_desktop)[source]
Parameters:

show_desktop (bool) – whether to show an item for the Desktop folder

Sets whether the self should show an item for the Desktop folder. The default value for this option is determined by the desktop environment and the user’s configuration, but this function can be used to override it on a per-application basis.

New in version 3.10.

set_show_enter_location(show_enter_location)[source]
Parameters:

show_enter_location (bool) – whether to show an item to enter a location

Sets whether the self should show an item for entering a location; this is off by default. An application may want to turn this on if manually entering URLs is an expected user action.

If you enable this, you should connect to the Gtk.PlacesSidebar ::show-enter-location signal.

New in version 3.14.

set_show_other_locations(show_other_locations)[source]
Parameters:

show_other_locations (bool) – whether to show an item for the Other Locations view

Sets whether the self should show an item for the application to show an Other Locations view; this is off by default. When set to True, persistent devices such as hard drives are hidden, otherwise they are shown in the sidebar. An application may want to turn this on if it implements a way for the user to see and interact with drives and network servers directly.

If you enable this, you should connect to the Gtk.PlacesSidebar ::show-other-locations signal.

New in version 3.18.

set_show_recent(show_recent)[source]
Parameters:

show_recent (bool) – whether to show an item for recent files

Sets whether the self should show an item for recent files. The default value for this option is determined by the desktop environment, but this function can be used to override it on a per-application basis.

New in version 3.18.

set_show_starred_location(show_starred_location)[source]
Parameters:

show_starred_location (bool) – whether to show an item for Starred files

If you enable this, you should connect to the Gtk.PlacesSidebar ::show-starred-location signal.

New in version 3.22.26.

set_show_trash(show_trash)[source]
Parameters:

show_trash (bool) – whether to show an item for the Trash location

Sets whether the self should show an item for the Trash location.

New in version 3.18.

Signal Details

Gtk.PlacesSidebar.signals.drag_action_ask(places_sidebar, actions)
Signal Name:

drag-action-ask

Flags:

RUN_LAST

Parameters:
  • places_sidebar (Gtk.PlacesSidebar) – The object which received the signal

  • actions (int) – Possible drag actions that need to be asked for.

Returns:

the final drag action that the sidebar should pass to the drag side of the drag-and-drop operation.

Return type:

int

The places sidebar emits this signal when it needs to ask the application to pop up a menu to ask the user for which drag action to perform.

New in version 3.10.

Gtk.PlacesSidebar.signals.drag_action_requested(places_sidebar, context, dest_file, source_file_list)
Signal Name:

drag-action-requested

Flags:

RUN_LAST

Parameters:
Returns:

The drag action to use, for example, Gdk.DragAction.COPY or Gdk.DragAction.MOVE, or 0 if no action is allowed here (i.e. drops are not allowed in the specified dest_file).

Return type:

int

When the user starts a drag-and-drop operation and the sidebar needs to ask the application for which drag action to perform, then the sidebar will emit this signal.

The application can evaluate the context for customary actions, or it can check the type of the files indicated by source_file_list against the possible actions for the destination dest_file.

The drag action to use must be the return value of the signal handler.

New in version 3.10.

Gtk.PlacesSidebar.signals.drag_perform_drop(places_sidebar, dest_file, source_file_list, action)
Signal Name:

drag-perform-drop

Flags:

RUN_FIRST

Parameters:

The places sidebar emits this signal when the user completes a drag-and-drop operation and one of the sidebar’s items is the destination. This item is in the dest_file, and the source_file_list has the list of files that are dropped into it and which should be copied/moved/etc. based on the specified action.

New in version 3.10.

Gtk.PlacesSidebar.signals.mount(places_sidebar, mount_operation)
Signal Name:

mount

Flags:

RUN_FIRST

Parameters:

The places sidebar emits this signal when it starts a new operation because the user clicked on some location that needs mounting. In this way the application using the Gtk.PlacesSidebar can track the progress of the operation and, for example, show a notification.

New in version 3.20.

Gtk.PlacesSidebar.signals.open_location(places_sidebar, location, open_flags)
Signal Name:

open-location

Flags:

RUN_FIRST

Parameters:

The places sidebar emits this signal when the user selects a location in it. The calling application should display the contents of that location; for example, a file manager should show a list of files in the specified location.

New in version 3.10.

Gtk.PlacesSidebar.signals.populate_popup(places_sidebar, container, selected_item, selected_volume)
Signal Name:

populate-popup

Flags:

RUN_FIRST

Parameters:

The places sidebar emits this signal when the user invokes a contextual popup on one of its items. In the signal handler, the application may add extra items to the menu as appropriate. For example, a file manager may want to add a “Properties” command to the menu.

It is not necessary to store the selected_item for each menu item; during their callbacks, the application can use Gtk.PlacesSidebar.get_location() to get the file to which the item refers.

The selected_item argument may be None in case the selection refers to a volume. In this case, selected_volume will be non-None. In this case, the calling application will have to GObject.Object.ref() the selected_volume and keep it around to use it in the callback.

The container and all its contents are destroyed after the user dismisses the popup. The popup is re-created (and thus, this signal is emitted) every time the user activates the contextual menu.

Before 3.18, the container always was a Gtk.Menu, and you were expected to add your items as Gtk.MenuItems. Since 3.18, the popup may be implemented as a Gtk.Popover, in which case container will be something else, e.g. a Gtk.Box, to which you may add Gtk.ModelButtons or other widgets, such as #GtkEntries, Gtk.SpinButtons, etc. If your application can deal with this situation, you can set Gtk.PlacesSidebar ::populate-all to True to request that this signal is emitted for populating popovers as well.

New in version 3.10.

Gtk.PlacesSidebar.signals.show_connect_to_server(places_sidebar)
Signal Name:

show-connect-to-server

Flags:

RUN_FIRST

Parameters:

places_sidebar (Gtk.PlacesSidebar) – The object which received the signal

The places sidebar emits this signal when it needs the calling application to present an way to connect directly to a network server. For example, the application may bring up a dialog box asking for a URL like “sftp://ftp.example.com”. It is up to the application to create the corresponding mount by using, for example, Gio.File.mount_enclosing_volume().

Deprecated since version 3.18: use the Gtk.PlacesSidebar ::show-other-locations signal to connect to network servers.

Gtk.PlacesSidebar.signals.show_enter_location(places_sidebar)
Signal Name:

show-enter-location

Flags:

RUN_FIRST

Parameters:

places_sidebar (Gtk.PlacesSidebar) – The object which received the signal

The places sidebar emits this signal when it needs the calling application to present an way to directly enter a location. For example, the application may bring up a dialog box asking for a URL like “http://http.example.com”.

New in version 3.14.

Gtk.PlacesSidebar.signals.show_error_message(places_sidebar, primary, secondary)
Signal Name:

show-error-message

Flags:

RUN_FIRST

Parameters:
  • places_sidebar (Gtk.PlacesSidebar) – The object which received the signal

  • primary (str) – primary message with a summary of the error to show.

  • secondary (str) – secondary message with details of the error to show.

The places sidebar emits this signal when it needs the calling application to present an error message. Most of these messages refer to mounting or unmounting media, for example, when a drive cannot be started for some reason.

New in version 3.10.

Gtk.PlacesSidebar.signals.show_other_locations(places_sidebar)
Signal Name:

show-other-locations

Flags:

RUN_FIRST, DEPRECATED

Parameters:

places_sidebar (Gtk.PlacesSidebar) – The object which received the signal

The places sidebar emits this signal when it needs the calling application to present a way to show other locations e.g. drives and network access points. For example, the application may bring up a page showing persistent volumes and discovered network addresses.

New in version 3.18.

Deprecated since version 3.20: use the Gtk.PlacesSidebar ::show-other-locations-with-flags which includes the open flags in order to allow the user to specify to open in a new tab or window, in a similar way than Gtk.PlacesSidebar ::open-location

Gtk.PlacesSidebar.signals.show_other_locations_with_flags(places_sidebar, open_flags)
Signal Name:

show-other-locations-with-flags

Flags:

RUN_FIRST

Parameters:

The places sidebar emits this signal when it needs the calling application to present a way to show other locations e.g. drives and network access points. For example, the application may bring up a page showing persistent volumes and discovered network addresses.

New in version 3.20.

Gtk.PlacesSidebar.signals.show_starred_location(places_sidebar, open_flags)
Signal Name:

show-starred-location

Flags:

RUN_FIRST

Parameters:

The places sidebar emits this signal when it needs the calling application to present a way to show the starred files. In GNOME, starred files are implemented by setting the nao:predefined-tag-favorite tag in the tracker database.

New in version 3.22.26.

Gtk.PlacesSidebar.signals.unmount(places_sidebar, mount_operation)
Signal Name:

unmount

Flags:

RUN_FIRST

Parameters:

The places sidebar emits this signal when it starts a new operation because the user for example ejected some drive or unmounted a mount. In this way the application using the Gtk.PlacesSidebar can track the progress of the operation and, for example, show a notification.

New in version 3.20.

Property Details

Gtk.PlacesSidebar.props.local_only
Name:

local-only

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

Whether the sidebar only includes local files

Gtk.PlacesSidebar.props.location
Name:

location

Type:

Gio.File

Default Value:

None

Flags:

READABLE, WRITABLE

The location to highlight in the sidebar

Gtk.PlacesSidebar.props.open_flags
Name:

open-flags

Type:

Gtk.PlacesOpenFlags

Default Value:

Gtk.PlacesOpenFlags.NORMAL

Flags:

READABLE, WRITABLE

Modes in which the calling application can open locations selected in the sidebar

Gtk.PlacesSidebar.props.populate_all
Name:

populate-all

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

If :populate-all is True, the Gtk.PlacesSidebar ::populate-popup signal is also emitted for popovers.

New in version 3.18.

Gtk.PlacesSidebar.props.show_connect_to_server
Name:

show-connect-to-server

Type:

bool

Default Value:

False

Flags:

DEPRECATED, READABLE, WRITABLE

Whether the sidebar includes a builtin shortcut to a ‘Connect to server’ dialog

Deprecated since version ???.

Gtk.PlacesSidebar.props.show_desktop
Name:

show-desktop

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE

Whether the sidebar includes a builtin shortcut to the Desktop folder

Gtk.PlacesSidebar.props.show_enter_location
Name:

show-enter-location

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

Whether the sidebar includes a builtin shortcut to manually enter a location

Gtk.PlacesSidebar.props.show_other_locations
Name:

show-other-locations

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

Whether the sidebar includes an item to show external locations

Gtk.PlacesSidebar.props.show_recent
Name:

show-recent

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE

Whether the sidebar includes a builtin shortcut for recent files

Gtk.PlacesSidebar.props.show_starred_location
Name:

show-starred-location

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

Whether the sidebar includes an item to show starred files

Gtk.PlacesSidebar.props.show_trash
Name:

show-trash

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE

Whether the sidebar includes a builtin shortcut to the Trash location