DesktopAppInfo
Superclasses: Object
Implemented Interfaces: AppInfo
GDesktopAppInfo
is an implementation of AppInfo
based on
desktop files.
Note that <gio/gdesktopappinfo.h>
belongs to the UNIX-specific
GIO interfaces, thus you have to use the gio-unix-2.0.pc
pkg-config
file or the GioUnix-2.0
GIR namespace when using it.
Constructors
- class DesktopAppInfo
- classmethod new(desktop_id: str) DesktopAppInfo | None
Creates a new
DesktopAppInfo
based on a desktop file id.A desktop file id is the basename of the desktop file, including the .desktop extension. GIO is looking for a desktop file with this name in the
applications
subdirectories of the XDG data directories (i.e. the directories specified in theXDG_DATA_HOME
andXDG_DATA_DIRS
environment variables). GIO also supports the prefix-to-subdirectory mapping that is described in the Menu Spec (i.e. a desktop id of kde-foo.desktop will match/usr/share/applications/kde/foo.desktop
).- Parameters:
desktop_id – the desktop file id
- classmethod new_from_filename(filename: str) DesktopAppInfo | None
Creates a new
DesktopAppInfo
.- Parameters:
filename – the path of a desktop file, in the GLib filename encoding
- classmethod new_from_keyfile(key_file: KeyFile) DesktopAppInfo | None
Creates a new
DesktopAppInfo
.Added in version 2.18.
- Parameters:
key_file – an opened
KeyFile
Methods
- class DesktopAppInfo
- get_action_name(action_name: str) str
Gets the user-visible display name of the “additional application action” specified by
action_name
.This corresponds to the “Name” key within the keyfile group for the action.
Added in version 2.38.
- Parameters:
action_name – the name of the action as from
list_actions()
- get_boolean(key: str) bool
Looks up a boolean value in the keyfile backing
info
.The
key
is looked up in the “Desktop Entry” group.Added in version 2.36.
- Parameters:
key – the key to look up
- get_filename() str | None
When
info
was created from a known filename, return it. In some situations such as theDesktopAppInfo
returned fromnew_from_keyfile()
, this function will returnNone
.Added in version 2.24.
- get_implementations(interface: str) list[DesktopAppInfo]
Gets all applications that implement
interface
.An application implements an interface if that interface is listed in the Implements= line of the desktop file of the application.
Added in version 2.42.
- Parameters:
interface – the name of the interface
A desktop file is hidden if the Hidden key in it is set to True.
- get_locale_string(key: str) str | None
Looks up a localized string value in the keyfile backing
info
translated to the current locale.The
key
is looked up in the “Desktop Entry” group.Added in version 2.56.
- Parameters:
key – the key to look up
- get_nodisplay() bool
Gets the value of the NoDisplay key, which helps determine if the application info should be shown in menus. See
%G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY
andshould_show()
.Added in version 2.30.
- get_show_in(desktop_env: str | None = None) bool
Checks if the application info should be shown in menus that list available applications for a specific name of the desktop, based on the
OnlyShowIn
andNotShowIn
keys.desktop_env
should typically be given asNone
, in which case theXDG_CURRENT_DESKTOP
environment variable is consulted. If you want to override the default mechanism then you may specifydesktop_env
, but this is not recommended.Note that
should_show()
forinfo
will include this check (withNone
fordesktop_env
) as well as additional checks.Added in version 2.30.
- Parameters:
desktop_env – a string specifying a desktop name
- get_startup_wm_class() str | None
Retrieves the StartupWMClass field from
info
. This represents the WM_CLASS property of the main window of the application, if launched throughinfo
.Added in version 2.34.
- get_string(key: str) str | None
Looks up a string value in the keyfile backing
info
.The
key
is looked up in the “Desktop Entry” group.Added in version 2.36.
- Parameters:
key – the key to look up
- get_string_list(key: str) list[str]
Looks up a string list value in the keyfile backing
info
.The
key
is looked up in the “Desktop Entry” group.Added in version 2.60.
- Parameters:
key – the key to look up
- has_key(key: str) bool
Returns whether
key
exists in the “Desktop Entry” group of the keyfile backinginfo
.Added in version 2.36.
- Parameters:
key – the key to look up
- launch_action(action_name: str, launch_context: AppLaunchContext | None = None) None
Activates the named application action.
You may only call this function on action names that were returned from
list_actions()
.Note that if the main entry of the desktop file indicates that the application supports startup notification, and
launch_context
is non-None
, then startup notification will be used when activating the action (and as such, invocation of the action on the receiving side must signal the end of startup notification when it is completed). This is the expected behaviour of applications declaring additional actions, as per the desktop file specification.As with
launch()
there is no way to detect failures that occur while using this function.Added in version 2.38.
- Parameters:
action_name – the name of the action as from
list_actions()
launch_context – a
AppLaunchContext
- launch_uris_as_manager(uris: list[str], launch_context: AppLaunchContext | None, spawn_flags: SpawnFlags, user_setup: Callable[[...], None] | None = None, pid_callback: Callable[[...], None] | None = None, *pid_callback_data: Any) bool
This function performs the equivalent of
launch_uris()
, but is intended primarily for operating system components that launch applications. Ordinary applications should uselaunch_uris()
.If the application is launched via GSpawn, then
spawn_flags
,user_setup
anduser_setup_data
are used for the call tospawn_async()
. Additionally,pid_callback
(withpid_callback_data
) will be called to inform about the PID of the created process. Seespawn_async_with_pipes()
for information on certain parameter conditions that can enable an optimized posix_spawn() codepath to be used.If application launching occurs via some other mechanism (eg: D-Bus activation) then
spawn_flags
,user_setup
,user_setup_data
,pid_callback
andpid_callback_data
are ignored.- Parameters:
uris – List of URIs
launch_context – a
AppLaunchContext
spawn_flags –
SpawnFlags
, used for each processuser_setup – a
SpawnChildSetupFunc
, used once for each process.pid_callback – Callback for child processes
pid_callback_data – User data for
callback
- launch_uris_as_manager_with_fds(uris: list[str], launch_context: AppLaunchContext | None, spawn_flags: SpawnFlags, user_setup: Callable[[...], None] | None, pid_callback: Callable[[...], None] | None, stdin_fd: int, stdout_fd: int, stderr_fd: int, *pid_callback_data: Any) bool
Equivalent to
launch_uris_as_manager()
but allows you to pass in file descriptors for the stdin, stdout and stderr streams of the launched process.If application launching occurs via some non-spawn mechanism (e.g. D-Bus activation) then
stdin_fd
,stdout_fd
andstderr_fd
are ignored.Added in version 2.58.
- Parameters:
uris – List of URIs
launch_context – a
AppLaunchContext
spawn_flags –
SpawnFlags
, used for each processuser_setup – a
SpawnChildSetupFunc
, used once for each process.pid_callback – Callback for child processes
stdin_fd – file descriptor to use for child’s stdin, or -1
stdout_fd – file descriptor to use for child’s stdout, or -1
stderr_fd – file descriptor to use for child’s stderr, or -1
pid_callback_data – User data for
callback
- list_actions() list[str]
Returns the list of “additional application actions” supported on the desktop file, as per the desktop file specification.
As per the specification, this is the list of actions that are explicitly listed in the “Actions” key of the [Desktop Entry] group.
Added in version 2.38.
- search(search_string: str) list[Sequence[str]]
Searches desktop files for ones that match
search_string
.The return value is an array of strvs. Each strv contains a list of applications that matched
search_string
with an equal score. The outer list is sorted by score so that the first strv contains the best-matching applications, and so on. The algorithm for determining matches is undefined and may change at any time.None of the search results are subjected to the normal validation checks performed by
new()
(for example, checking that the executable referenced by a result exists), and so it is possible fornew()
to returnNone
when passed an app ID returned by this function. It is expected that calling code will do this when subsequently creating aDesktopAppInfo
for each result.- Parameters:
search_string – the search string to use
- set_desktop_env(desktop_env: str) None
Sets the name of the desktop that the application is running in. This is used by
should_show()
andget_show_in()
to evaluate theOnlyShowIn
andNotShowIn
desktop entry fields.Should be called only once; subsequent calls are ignored.
Deprecated since version 2.42: do not use this API. Since 2.42 the value of the
XDG_CURRENT_DESKTOP
environment variable will be used.- Parameters:
desktop_env – a string specifying what desktop this is
Properties
- class DesktopAppInfo
- props.filename: str
The origin filename of this
DesktopAppInfo