Skip to content

Gtk.FileLauncher

class — extends GObject.Object

Asynchronous API to open a file with an application.

GtkFileLauncher collects the arguments that are needed to open the file.

Depending on system configuration, user preferences and available APIs, this may or may not show an app chooser dialog or launch the default application right away.

The operation is started with the FileLauncher.launch function.

To launch uris that don't represent files, use UriLauncher.

Constructors

new

@classmethod
def new(cls, file: Gio.File | None = ...) -> FileLauncher

Creates a new GtkFileLauncher object.

Parameters:

  • file — the file to open

Methods

get_always_ask

def get_always_ask(self) -> bool

Returns whether to ask the user which app to use.

get_file

def get_file(self) -> Gio.File | None

Gets the file that will be opened.

get_writable

def get_writable(self) -> bool

Returns whether to make the file writable for the handler.

launch

def launch(self, parent: Window | None = ..., cancellable: Gio.Cancellable | None = ..., callback: Gio.AsyncReadyCallback | None = ...) -> None

Launches an application to open the file.

This may present an app chooser dialog to the user.

Parameters:

  • parent — the parent window
  • cancellable — a cancellable to cancel the operation
  • callback — a callback to call when the operation is complete

launch_finish

def launch_finish(self, result: Gio.AsyncResult) -> bool

Finishes the FileLauncher.launch call and returns the result.

Parameters:

  • result — the result

open_containing_folder

def open_containing_folder(self, parent: Window | None = ..., cancellable: Gio.Cancellable | None = ..., callback: Gio.AsyncReadyCallback | None = ...) -> None

Launches a file manager to show the file in its parent directory.

This is only supported for native files. It will fail if file is e.g. a http:// uri.

Parameters:

  • parent — the parent window
  • cancellable — a cancellable to cancel the operation
  • callback — a callback to call when the operation is complete

open_containing_folder_finish

def open_containing_folder_finish(self, result: Gio.AsyncResult) -> bool

Finishes the FileLauncher.open_containing_folder call and returns the result.

Parameters:

  • result — the result

set_always_ask

def set_always_ask(self, always_ask: bool) -> None

Sets whether to always ask the user which app to use.

If false, the file might be opened with a default app or the previous choice.

Parameters:

  • always_ask — whether to always ask

set_file

def set_file(self, file: Gio.File | None = ...) -> None

Sets the file that will be opened.

Parameters:

  • file — the file

set_writable

def set_writable(self, writable: bool) -> None

Sets whether to make the file writable for the handler.

Parameters:

  • writable — whether to make the file writable

Properties

always_ask

always_ask: bool  # read/write

Whether to ask the user to choose an app for opening the file. If FALSE, the file might be opened with a default app or the previous choice.

file

file: Gio.File  # read/write

The file to launch.

writable

writable: bool  # read/write

Whether to make the file writable for the handler.