:right-sidebar: True AppInfo =================================================================== .. currentmodule:: gi.repository.Gio .. class:: AppInfo(*args, **kwargs) :no-contents-entry: Implementations: :class:`~gi.repository.Gio.DesktopAppInfo` Information about an installed application and methods to launch it (with file arguments). ``GAppInfo`` and ``GAppLaunchContext`` are used for describing and launching applications installed on the system. As of GLib 2.20, URIs will always be converted to POSIX paths (using :obj:`~gi.repository.Gio.File.get_path`\) when using :obj:`~gi.repository.Gio.AppInfo.launch` even if the application requested an URI and not a POSIX path. For example for a desktop-file based application with the following Exec key: .. code-block:: :dedent: Exec=totem %U and a single URI, ``sftp://foo/file.avi``\, then ``/home/user/.gvfs/sftp on foo/file.avi`` will be passed. This will only work if a set of suitable GIO extensions (such as GVfs 2.26 compiled with FUSE support), is available and operational; if this is not the case, the URI will be passed unmodified to the application. Some URIs, such as ``mailto:``\, of course cannot be mapped to a POSIX path (in GVfs there’s no FUSE mount for it); such URIs will be passed unmodified to the application. Specifically for GVfs 2.26 and later, the POSIX URI will be mapped back to the GIO URI in the :obj:`~gi.repository.Gio.File` constructors (since GVfs implements the GVfs extension point). As such, if the application needs to examine the URI, it needs to use :obj:`~gi.repository.Gio.File.get_uri` or similar on :obj:`~gi.repository.Gio.File`\. In other words, an application cannot assume that the URI passed to e.g. :obj:`~gi.repository.Gio.File.new_for_commandline_arg` is equal to the result of :obj:`~gi.repository.Gio.File.get_uri`\. The following snippet illustrates this: .. code-block:: c :dedent: GFile *f; char *uri; file = g_file_new_for_commandline_arg (uri_from_commandline); uri = g_file_get_uri (file); strcmp (uri, uri_from_commandline) == 0; g_free (uri); if (g_file_has_uri_scheme (file, "cdda")) { // do something special with uri } g_object_unref (file); This code will work when both ``cdda://sr0/Track 1.wav`` and ``/home/user/.gvfs/cdda on sr0/Track 1.wav`` is passed to the application. It should be noted that it’s generally not safe for applications to rely on the format of a particular URIs. Different launcher applications (e.g. file managers) may have different ideas of what a given URI means. Methods ------- .. rst-class:: interim-class .. class:: AppInfo :no-index: .. method:: add_supports_type(content_type: str) -> bool Adds a content type to the application information to indicate the application is capable of opening files with the given content type. :param content_type: a string. .. method:: can_delete() -> bool Obtains the information whether the :obj:`~gi.repository.Gio.AppInfo` can be deleted. See :obj:`~gi.repository.Gio.AppInfo.delete`\. .. versionadded:: 2.20 .. method:: can_remove_supports_type() -> bool Checks if a supported content type can be removed from an application. .. classmethod:: create_from_commandline(application_name: str | None, flags: ~gi.repository.Gio.AppInfoCreateFlags) -> ~gi.repository.Gio.AppInfo Creates a new :obj:`~gi.repository.Gio.AppInfo` from the given information. Note that for ``commandline``\, the quoting rules of the ``Exec`` key of the `freedesktop.org Desktop Entry Specification `__ are applied. For example, if the ``commandline`` contains percent-encoded URIs, the percent-character must be doubled in order to prevent it from being swallowed by ``Exec`` key unquoting. See `the specification `__ for exact quoting rules. :param application_name: the application name, or ``NULL`` to use ``commandline`` :param flags: flags that can specify details of the created :obj:`~gi.repository.Gio.AppInfo` .. method:: delete() -> bool Tries to delete a :obj:`~gi.repository.Gio.AppInfo`\. On some platforms, there may be a difference between user-defined :obj:`~gi.repository.Gio.AppInfo`\s which can be deleted, and system-wide ones which cannot. See :obj:`~gi.repository.Gio.AppInfo.can_delete`\. .. versionadded:: 2.20 .. method:: dup() -> ~gi.repository.Gio.AppInfo Creates a duplicate of a :obj:`~gi.repository.Gio.AppInfo`\. .. method:: equal(appinfo2: ~gi.repository.Gio.AppInfo) -> bool Checks if two :obj:`~gi.repository.Gio.AppInfo`\s are equal. Note that the check *may not* compare each individual field, and only does an identity check. In case detecting changes in the contents is needed, program code must additionally compare relevant fields. :param appinfo2: the second :obj:`~gi.repository.Gio.AppInfo`\. .. classmethod:: get_all() -> list[~gi.repository.Gio.AppInfo] Gets a list of all of the applications currently registered on this system. For desktop files, this includes applications that have ```NoDisplay=true`` `__ set or are excluded from display by means of ```OnlyShowIn`` `__ or ```NotShowIn`` `__\. See :obj:`~gi.repository.Gio.AppInfo.should_show`\. The returned list does not include applications which have the ```Hidden`` key `__ set. .. classmethod:: get_all_for_type() -> list[~gi.repository.Gio.AppInfo] Gets a list of all :obj:`~gi.repository.Gio.AppInfo`\s for a given content type, including the recommended and fallback :obj:`~gi.repository.Gio.AppInfo`\s. See :obj:`~gi.repository.Gio.AppInfo.get_recommended_for_type` and :obj:`~gi.repository.Gio.AppInfo.get_fallback_for_type`\. .. method:: get_commandline() -> str | None Gets the commandline with which the application will be started. .. versionadded:: 2.20 .. classmethod:: get_default_for_type(must_support_uris: bool) -> ~gi.repository.Gio.AppInfo | None Gets the default :obj:`~gi.repository.Gio.AppInfo` for a given content type. :param must_support_uris: if ``TRUE``\, the :obj:`~gi.repository.Gio.AppInfo` is expected to support URIs .. classmethod:: get_default_for_type_async(must_support_uris: bool, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Asynchronously gets the default :obj:`~gi.repository.Gio.AppInfo` for a given content type. .. versionadded:: 2.74 :param must_support_uris: if ``TRUE``\, the :obj:`~gi.repository.Gio.AppInfo` is expected to support URIs :param cancellable: a :obj:`~gi.repository.Gio.Cancellable` :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to call when the request is done :param user_data: data to pass to ``callback`` .. classmethod:: get_default_for_type_finish() -> ~gi.repository.Gio.AppInfo Finishes a default :obj:`~gi.repository.Gio.AppInfo` lookup started by :obj:`~gi.repository.Gio.AppInfo.get_default_for_type_async`\. If no #:obj:`~gi.repository.Gio.AppInfo` is found, then ``error`` will be set to :obj:`~gi.repository.Gio.IOErrorEnum.NOT_FOUND`\. .. versionadded:: 2.74 .. classmethod:: get_default_for_uri_scheme() -> ~gi.repository.Gio.AppInfo | None Gets the default application for handling URIs with the given URI scheme. A URI scheme is the initial part of the URI, up to but not including the ``:``\. For example, ``http``\, ``ftp`` or ``sip``\. .. classmethod:: get_default_for_uri_scheme_async(cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Asynchronously gets the default application for handling URIs with the given URI scheme. A URI scheme is the initial part of the URI, up to but not including the ``:``\, e.g. ``http``\, ``ftp`` or ``sip``\. .. versionadded:: 2.74 :param cancellable: a :obj:`~gi.repository.Gio.Cancellable` :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to call when the request is done :param user_data: data to pass to ``callback`` .. classmethod:: get_default_for_uri_scheme_finish() -> ~gi.repository.Gio.AppInfo Finishes a default :obj:`~gi.repository.Gio.AppInfo` lookup started by :obj:`~gi.repository.Gio.AppInfo.get_default_for_uri_scheme_async`\. If no :obj:`~gi.repository.Gio.AppInfo` is found, then ``error`` will be set to :obj:`~gi.repository.Gio.IOErrorEnum.NOT_FOUND`\. .. versionadded:: 2.74 .. method:: get_description() -> str | None Gets a human-readable description of an installed application. .. method:: get_display_name() -> str Gets the display name of the application. The display name is often more descriptive to the user than the name itself. .. versionadded:: 2.24 .. method:: get_executable() -> str Gets the executable’s name for the installed application. This is intended to be used for debugging or labelling what program is going to be run. To launch the executable, use :obj:`~gi.repository.Gio.AppInfo.launch` and related functions, rather than spawning the return value from this function. .. classmethod:: get_fallback_for_type() -> list[~gi.repository.Gio.AppInfo] Gets a list of fallback :obj:`~gi.repository.Gio.AppInfo`\s for a given content type, i.e. those applications which claim to support the given content type by MIME type subclassing and not directly. .. versionadded:: 2.28 .. method:: get_icon() -> ~gi.repository.Gio.Icon | None Gets the icon for the application. .. method:: get_id() -> str | None Gets the ID of an application. An id is a string that identifies the application. The exact format of the id is platform dependent. For instance, on Unix this is the desktop file id from the xdg menu specification. Note that the returned ID may be ``NULL``\, depending on how the ``appinfo`` has been constructed. .. method:: get_name() -> str Gets the installed name of the application. .. classmethod:: get_recommended_for_type() -> list[~gi.repository.Gio.AppInfo] Gets a list of recommended :obj:`~gi.repository.Gio.AppInfo`\s for a given content type, i.e. those applications which claim to support the given content type exactly, and not by MIME type subclassing. Note that the first application of the list is the last used one, i.e. the last one for which :obj:`~gi.repository.Gio.AppInfo.set_as_last_used_for_type` has been called. .. versionadded:: 2.28 .. method:: get_supported_types() -> list[str] Retrieves the list of content types that ``app_info`` claims to support. If this information is not provided by the environment, this function will return ``NULL``\. This function does not take in consideration associations added with :obj:`~gi.repository.Gio.AppInfo.add_supports_type`\, but only those exported directly by the application. .. versionadded:: 2.34 .. method:: launch(files: list[~gi.repository.Gio.File] | None = None, context: ~gi.repository.Gio.AppLaunchContext | None = None) -> bool Launches the application. Passes ``files`` to the launched application as arguments, using the optional ``context`` to get information about the details of the launcher (like what screen it is on). On error, ``error`` will be set accordingly. To launch the application without arguments pass a ``NULL`` ``files`` list. Note that even if the launch is successful the application launched can fail to start if it runs into problems during startup. There is no way to detect this. Some URIs can be changed when passed through a GFile (for instance unsupported URIs with strange formats like mailto:), so if you have a textual URI you want to pass in as argument, consider using :obj:`~gi.repository.Gio.AppInfo.launch_uris` instead. The launched application inherits the environment of the launching process, but it can be modified with :obj:`~gi.repository.Gio.AppLaunchContext.setenv` and :obj:`~gi.repository.Gio.AppLaunchContext.unsetenv`\. On UNIX, this function sets the ``GIO_LAUNCHED_DESKTOP_FILE`` environment variable with the path of the launched desktop file and ``GIO_LAUNCHED_DESKTOP_FILE_PID`` to the process id of the launched process. This can be used to ignore ``GIO_LAUNCHED_DESKTOP_FILE``\, should it be inherited by further processes. The ``DISPLAY``\, ``XDG_ACTIVATION_TOKEN`` and ``DESKTOP_STARTUP_ID`` environment variables are also set, based on information provided in ``context``\. :param files: a list of :obj:`~gi.repository.Gio.File` objects :param context: the launch context .. classmethod:: launch_default_for_uri(context: ~gi.repository.Gio.AppLaunchContext | None = None) -> bool Utility function that launches the default application registered to handle the specified uri. Synchronous I/O is done on the uri to detect the type of the file if required. The D-Bus–activated applications don’t have to be started if your application terminates too soon after this function. To prevent this, use :obj:`~gi.repository.Gio.AppInfo.launch_default_for_uri_async` instead. :param context: optional launch context .. classmethod:: launch_default_for_uri_async(context: ~gi.repository.Gio.AppLaunchContext | None = None, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Async version of :obj:`~gi.repository.Gio.AppInfo.launch_default_for_uri`\. This version is useful if you are interested in receiving error information in the case where the application is sandboxed and the portal may present an application chooser dialog to the user. This is also useful if you want to be sure that the D-Bus–activated applications are really started before termination and if you are interested in receiving error information from their activation. .. versionadded:: 2.50 :param context: optional launch context :param cancellable: a :obj:`~gi.repository.Gio.Cancellable` :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to call when the request is done :param user_data: data to pass to ``callback`` .. classmethod:: launch_default_for_uri_finish() -> bool Finishes an asynchronous launch-default-for-uri operation. .. versionadded:: 2.50 .. method:: launch_uris(uris: list[str] | None = None, context: ~gi.repository.Gio.AppLaunchContext | None = None) -> bool Launches the application. This passes the ``uris`` to the launched application as arguments, using the optional ``context`` to get information about the details of the launcher (like what screen it is on). On error, ``error`` will be set accordingly. If the application only supports one URI per invocation as part of their command-line, multiple instances of the application will be spawned. To launch the application without arguments pass a ``NULL`` ``uris`` list. Note that even if the launch is successful the application launched can fail to start if it runs into problems during startup. There is no way to detect this. :param uris: a list of URIs to launch. :param context: the launch context .. method:: launch_uris_async(uris: list[str] | None = None, context: ~gi.repository.Gio.AppLaunchContext | None = None, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Async version of :obj:`~gi.repository.Gio.AppInfo.launch_uris`\. The ``callback`` is invoked immediately after the application launch, but it waits for activation in case of D-Bus–activated applications and also provides extended error information for sandboxed applications, see notes for :obj:`~gi.repository.Gio.AppInfo.launch_default_for_uri_async`\. .. versionadded:: 2.60 :param uris: a list of URIs to launch. :param context: the launch context :param cancellable: a :obj:`~gi.repository.Gio.Cancellable` :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to call when the request is done :param user_data: data to pass to ``callback`` .. method:: launch_uris_finish(result: ~gi.repository.Gio.AsyncResult) -> bool Finishes a :obj:`~gi.repository.Gio.AppInfo.launch_uris_async` operation. .. versionadded:: 2.60 :param result: the async result .. method:: remove_supports_type(content_type: str) -> bool Removes a supported type from an application, if possible. :param content_type: a string. .. classmethod:: reset_type_associations() -> None Removes all changes to the type associations done by :obj:`~gi.repository.Gio.AppInfo.set_as_default_for_type`\, :obj:`~gi.repository.Gio.AppInfo.set_as_default_for_extension`\, :obj:`~gi.repository.Gio.AppInfo.add_supports_type` or :obj:`~gi.repository.Gio.AppInfo.remove_supports_type`\. .. versionadded:: 2.20 .. method:: set_as_default_for_extension(extension: str) -> bool Sets the application as the default handler for the given file extension. :param extension: a string containing the file extension (without the dot). .. method:: set_as_default_for_type(content_type: str) -> bool Sets the application as the default handler for a given type. :param content_type: the content type. .. method:: set_as_last_used_for_type(content_type: str) -> bool Sets the application as the last used application for a given type. This will make the application appear as first in the list returned by :obj:`~gi.repository.Gio.AppInfo.get_recommended_for_type`\, regardless of the default application for that content type. :param content_type: the content type. .. method:: should_show() -> bool Checks if the application info should be shown in menus that list available applications. .. method:: supports_files() -> bool Checks if the application accepts files as arguments. .. method:: supports_uris() -> bool Checks if the application supports reading files and directories from URIs. Virtual Methods --------------- .. rst-class:: interim-class .. class:: AppInfo :no-index: .. method:: do_add_supports_type(content_type: str) -> bool Adds a content type to the application information to indicate the application is capable of opening files with the given content type. :param content_type: a string. .. method:: do_can_delete() -> bool Obtains the information whether the :obj:`~gi.repository.Gio.AppInfo` can be deleted. See :obj:`~gi.repository.Gio.AppInfo.delete`\. .. versionadded:: 2.20 .. method:: do_can_remove_supports_type() -> bool Checks if a supported content type can be removed from an application. .. method:: do_do_delete() -> bool The type of the None singleton. .. versionadded:: 2.20 .. method:: do_dup() -> ~gi.repository.Gio.AppInfo Creates a duplicate of a :obj:`~gi.repository.Gio.AppInfo`\. .. method:: do_equal(appinfo2: ~gi.repository.Gio.AppInfo) -> bool Checks if two :obj:`~gi.repository.Gio.AppInfo`\s are equal. Note that the check *may not* compare each individual field, and only does an identity check. In case detecting changes in the contents is needed, program code must additionally compare relevant fields. :param appinfo2: the second :obj:`~gi.repository.Gio.AppInfo`\. .. method:: do_get_commandline() -> str | None Gets the commandline with which the application will be started. .. versionadded:: 2.20 .. method:: do_get_description() -> str | None Gets a human-readable description of an installed application. .. method:: do_get_display_name() -> str Gets the display name of the application. The display name is often more descriptive to the user than the name itself. .. versionadded:: 2.24 .. method:: do_get_executable() -> str Gets the executable’s name for the installed application. This is intended to be used for debugging or labelling what program is going to be run. To launch the executable, use :obj:`~gi.repository.Gio.AppInfo.launch` and related functions, rather than spawning the return value from this function. .. method:: do_get_icon() -> ~gi.repository.Gio.Icon | None Gets the icon for the application. .. method:: do_get_id() -> str | None Gets the ID of an application. An id is a string that identifies the application. The exact format of the id is platform dependent. For instance, on Unix this is the desktop file id from the xdg menu specification. Note that the returned ID may be ``NULL``\, depending on how the ``appinfo`` has been constructed. .. method:: do_get_name() -> str Gets the installed name of the application. .. method:: do_get_supported_types() -> list[str] Retrieves the list of content types that ``app_info`` claims to support. If this information is not provided by the environment, this function will return ``NULL``\. This function does not take in consideration associations added with :obj:`~gi.repository.Gio.AppInfo.add_supports_type`\, but only those exported directly by the application. .. versionadded:: 2.34 .. method:: do_launch(files: list[~gi.repository.Gio.File] | None = None, context: ~gi.repository.Gio.AppLaunchContext | None = None) -> bool Launches the application. Passes ``files`` to the launched application as arguments, using the optional ``context`` to get information about the details of the launcher (like what screen it is on). On error, ``error`` will be set accordingly. To launch the application without arguments pass a ``NULL`` ``files`` list. Note that even if the launch is successful the application launched can fail to start if it runs into problems during startup. There is no way to detect this. Some URIs can be changed when passed through a GFile (for instance unsupported URIs with strange formats like mailto:), so if you have a textual URI you want to pass in as argument, consider using :obj:`~gi.repository.Gio.AppInfo.launch_uris` instead. The launched application inherits the environment of the launching process, but it can be modified with :obj:`~gi.repository.Gio.AppLaunchContext.setenv` and :obj:`~gi.repository.Gio.AppLaunchContext.unsetenv`\. On UNIX, this function sets the ``GIO_LAUNCHED_DESKTOP_FILE`` environment variable with the path of the launched desktop file and ``GIO_LAUNCHED_DESKTOP_FILE_PID`` to the process id of the launched process. This can be used to ignore ``GIO_LAUNCHED_DESKTOP_FILE``\, should it be inherited by further processes. The ``DISPLAY``\, ``XDG_ACTIVATION_TOKEN`` and ``DESKTOP_STARTUP_ID`` environment variables are also set, based on information provided in ``context``\. :param files: a list of :obj:`~gi.repository.Gio.File` objects :param context: the launch context .. method:: do_launch_uris(uris: list[str] | None = None, context: ~gi.repository.Gio.AppLaunchContext | None = None) -> bool Launches the application. This passes the ``uris`` to the launched application as arguments, using the optional ``context`` to get information about the details of the launcher (like what screen it is on). On error, ``error`` will be set accordingly. If the application only supports one URI per invocation as part of their command-line, multiple instances of the application will be spawned. To launch the application without arguments pass a ``NULL`` ``uris`` list. Note that even if the launch is successful the application launched can fail to start if it runs into problems during startup. There is no way to detect this. :param uris: a list of URIs to launch. :param context: the launch context .. method:: do_launch_uris_async(uris: list[str] | None = None, context: ~gi.repository.Gio.AppLaunchContext | None = None, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Async version of :obj:`~gi.repository.Gio.AppInfo.launch_uris`\. The ``callback`` is invoked immediately after the application launch, but it waits for activation in case of D-Bus–activated applications and also provides extended error information for sandboxed applications, see notes for :obj:`~gi.repository.Gio.AppInfo.launch_default_for_uri_async`\. .. versionadded:: 2.60 :param uris: a list of URIs to launch. :param context: the launch context :param cancellable: a :obj:`~gi.repository.Gio.Cancellable` :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to call when the request is done :param user_data: data to pass to ``callback`` .. method:: do_launch_uris_finish(result: ~gi.repository.Gio.AsyncResult) -> bool Finishes a :obj:`~gi.repository.Gio.AppInfo.launch_uris_async` operation. .. versionadded:: 2.60 :param result: the async result .. method:: do_remove_supports_type(content_type: str) -> bool Removes a supported type from an application, if possible. :param content_type: a string. .. method:: do_set_as_default_for_extension(extension: str) -> bool Sets the application as the default handler for the given file extension. :param extension: a string containing the file extension (without the dot). .. method:: do_set_as_default_for_type(content_type: str) -> bool Sets the application as the default handler for a given type. :param content_type: the content type. .. method:: do_set_as_last_used_for_type(content_type: str) -> bool Sets the application as the last used application for a given type. This will make the application appear as first in the list returned by :obj:`~gi.repository.Gio.AppInfo.get_recommended_for_type`\, regardless of the default application for that content type. :param content_type: the content type. .. method:: do_should_show() -> bool Checks if the application info should be shown in menus that list available applications. .. method:: do_supports_files() -> bool Checks if the application accepts files as arguments. .. method:: do_supports_uris() -> bool Checks if the application supports reading files and directories from URIs.