FileLauncher#

Added in version 4.10.

class FileLauncher(**properties: Any)#

Superclasses: 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 launch function.

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

Constructors#

class FileLauncher
classmethod new(file: File | None = None) FileLauncher#

Creates a new GtkFileLauncher object.

Added in version 4.10.

Parameters:

file – the file to open

Methods#

class FileLauncher
get_always_ask() bool#

Returns whether to ask the user which app to use.

Added in version 4.12.

get_file() File | None#

Gets the file that will be opened.

Added in version 4.10.

get_writable() bool#

Returns whether to make the file writable for the handler.

Added in version 4.14.

async launch(self, parent: Window | None = None) bool#

This is the awaitable version of launch().

Added in version 4.10.

Parameters:

parent – the parent window

launch(parent: Window | None = None, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#

Launches an application to open the file.

This may present an app chooser dialog to the user.

Added in version 4.10.

Parameters:
  • parent – the parent window

  • cancellable – a cancellable to cancel the operation

  • callback – a callback to call when the operation is complete

  • user_data – data to pass to callback

launch_finish(result: AsyncResult) bool#

Finishes the launch call and returns the result.

Added in version 4.10.

Parameters:

result – the result

async open_containing_folder(self, parent: Window | None = None) bool#

This is the awaitable version of open_containing_folder().

Added in version 4.10.

Parameters:

parent – the parent window

open_containing_folder(parent: Window | None = None, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = 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.

Added in version 4.10.

Parameters:
  • parent – the parent window

  • cancellable – a cancellable to cancel the operation

  • callback – a callback to call when the operation is complete

  • user_data – data to pass to callback

open_containing_folder_finish(result: AsyncResult) bool#

Finishes the open_containing_folder call and returns the result.

Added in version 4.10.

Parameters:

result – the result

set_always_ask(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.

Added in version 4.12.

Parameters:

always_ask – whether to always ask

set_file(file: File | None = None) None#

Sets the file that will be opened.

Added in version 4.10.

Parameters:

file – the file

set_writable(writable: bool) None#

Sets whether to make the file writable for the handler.

Added in version 4.14.

Parameters:

writable – whether to make the file writable

Properties#

class FileLauncher
props.always_ask: bool#

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.

Added in version 4.12.

props.file: File#

The file to launch.

Added in version 4.10.

props.writable: bool#

Whether to make the file writable for the handler.

Added in version 4.14.