API#

desktop_entry_lib.__init__.get_xdg_data_dirs() list[str]#

Get all XDG DATA DIRS

Returns:

The list of XDG data Dirs

Return type:

list[str]

desktop_entry_lib.__init__.get_icon_path(icon_name: str) Optional[str]#

Get the path of a Icon

Parameters:

icon_name (str) – The name of the Icon as found in the desktop entry

Returns:

The full pßath to the Icon. none if the Icon was not found.

Return type:

Optional[str]

desktop_entry_lib.__init__.is_action_identifier_valid(identifier: str) bool#

Checks if a Action identifier is valid

Parameters:

identifier (str) – The Identifier

Returns:

If the identifier is valid

Return type:

bool

desktop_entry_lib.__init__.is_custom_key_name_valid(name: str) bool#

Checks if the given name can be used for a custom key

Parameters:
  • identifier – The name

  • name (str) –

Returns:

If the name can be used

Return type:

bool

class desktop_entry_lib.__init__.ValidationMessageDict#

Defines the return type for get_validation_messages()

Error: list[str]#
FutureError: list[str]#
Warning: list[str]#
Hint: list[str]#
exception desktop_entry_lib.__init__.InvalidDesktopEntry#

This Exception is raised, when a invalid Desktop Entry is loaded

Return type:

None

class desktop_entry_lib.__init__.TranslatableKey#

Represents a Key in a Desktop Entry, that can be translated into different languages

default_text: str#

The untranslated text

translations: dict[str, str]#

The translations

get_translated_text() str#

Returns the text for the current system language

Returns:

The text

Return type:

str

load_section(section: dict[str, str], search_key: str) None#

Loads a section from a Desktop Entry. Only for internal use.

Parameters:
  • section (dict[str, str]) –

  • search_key (str) –

Return type:

None

get_text(entry_key: str) str#

Returns the text for saving a Desktop Entry. only for internal use.

Parameters:

entry_key (str) –

Return type:

str

clear() None#

Clear

Return type:

None

class desktop_entry_lib.__init__.TranslatableListKey#

Represents a List in a Desktop Entry, that can be translated into different languages

default_list: list[str]#

The unstranslated list

translations: dict[str, list[str]]#

The translated lists

load_section(section: dict[str, str], search_key: str) None#

Loads a section from a Desktop Entry. Only for internal use.

Parameters:
  • section (dict[str, str]) –

  • search_key (str) –

Return type:

None

get_text(entry_key: str) str#

Returns the text for saving a Desktop Entry. only for internal use.

Parameters:

entry_key (str) –

Return type:

str

clear() None#

Clear

Return type:

None

class desktop_entry_lib.__init__.DesktopAction#

Represents a Action in a Desktop Entry

Name: TranslatableKey#

The Name Key

Icon: Optional[str]#

The Icon Key

Exec: Optional[str]#

The Exec Key

classmethod from_dict(action_section: dict[str, str])#

Load the Action from a Dict. Onyl used internaly.

Parameters:

action_section (dict[str, str]) –

get_text() str#

Converts the Action into a String

Return type:

str

get_icon_path() Optional[str]#

Returns full Path to the Icon

Returns:

The full Path or None, if the Icon can’t be found

Return type:

Optional[str]

class desktop_entry_lib.__init__.DesktopEntry#

Represents a Desktop Entry

Type: Literal['Application', 'Link', 'Directory']#

The Type Key

Version: Optional[Literal['1.0', '1.1', '1.2', '1.3', '1.4', '1.5']]#

The Version Key

Name: TranslatableKey#

The Name Key

GenericName: TranslatableKey#

The GenericName Key

NoDisplay: Optional[bool]#

The NoDisplay Key

Comment: TranslatableKey#

The Comment Key

Icon: Optional[str]#

The Icon Key

Hidden: Optional[bool]#

The Hidden Key

OnlyShowIn: list[str]#

The OnlyShowIn Key

NotShowIn: list[str]#

The NotShowIn Key

DBusActivatable: Optional[bool]#

The DBusActivatable Key

TryExec: Optional[str]#

The TryExec Key

Exec: Optional[str]#

The Exec Key

Path: Optional[str]#

The Path Key

Terminal: Optional[bool]#

The Terminal Key

MimeType: list[str]#

The MimeType Key

Categories: list[str]#

The Categories Key

Implements: list[str]#

The Implements Key

Keywords: TranslatableListKey#

The Keywords Key

StartupNotify: Optional[bool]#

The StartupNotify Key

StartupWMClass: Optional[str]#

The StartupWMClass Key

URL: Optional[str]#

The URL Key

PrefersNonDefaultGPU: Optional[bool]#

The PrefersNonDefaultGPU Key

SingleMainWindow: Optional[bool]#

The SingleMainWindow Key

Actions: dict[str, desktop_entry_lib.__init__.DesktopAction]#

The Actions

CustomKeys: dict[str, str]#

The Keys starting with X-

file_path: Optional[str]#

The path to the .desktop file

desktop_id: Optional[str]#

The ID of the .desktop file

leading_comment: Optional[str]#

If you set this, the given Comment will be added at the top of the Desktop Entry. You can use it for stuff like ‘Created with foo’.

is_valid() bool#

Returns, if the Desktop Entry is valid. desktop-file-validate needs to be installed.

Returns:

If the entry is valid

Return type:

bool

get_validation_messages() ValidationMessageDict#

Returns all messages from desktop-file-validate

Returns:

A dict which contains the validation messages

Return type:

ValidationMessageDict

should_show() bool#

Returns if Desktop Entry should be showed

Return type:

bool

should_show_in_menu() bool#

Returns if a dektop entry should be displayed in the menu

Return type:

bool

get_icon_path() Optional[str]#

Returns the full path to the Icon

Return type:

Optional[str]

is_empty() bool#

Checks if the Desktop Entry is empty

Return type:

bool

get_text() str#

Returns the content of the Desktop Entry

Return type:

str

write_file(path: Union[str, PathLike]) None#

Writes a .desktop file

Parameters:

path (Union[str, PathLike]) –

Return type:

None

classmethod from_string(text: str) DesktopEntry#

Loads the content of a .desktop file from a string

Parameters:

text (str) –

Return type:

DesktopEntry

classmethod from_file(path: Union[str, PathLike]) DesktopEntry#

Returns a Desktop Entry from the given file

Parameters:

path (Union[str, PathLike]) –

Return type:

DesktopEntry

classmethod from_id(desktop_id: str) Optional[DesktopEntry]#

Returns a Desktop Entry from the given id

Parameters:

desktop_id (str) –

Return type:

Optional[DesktopEntry]

static get_keywords() list[str]#

Returns the list of Keywords of a Desktop Entry

Returns:

The list of Keys

Return type:

list[str]

class desktop_entry_lib.__init__.DesktopEntryCollection#

Represents a Collection of multiple Desktop Entries

desktop_entries: dict[str, desktop_entry_lib.__init__.DesktopEntry]#

The desktop entries

load_file(path: Union[str, PathLike]) None#

Lods the given desktop entry file and adds it to the collection

Parameters:

path (Union[str, PathLike]) – The path to the desktop entry

Return type:

None

load_directory(path: Union[str, PathLike]) bool#

Loads all desktop entries from the given directory

Parameters:

path (Union[str, PathLike]) – The directory

Returns:

True if all desktop entries could be loaded, False if some couldn’t be loaded

Return type:

bool

load_menu() bool#

Loads all desktop entries from the menu

Returns:

True if all desktop entries could be loaded, False if some couldn’t be loaded

Return type:

bool

load_desktop() bool#

Loads all desktop entries files from the Desktop

Returns:

True if all desktop etntries could be loaded, False if some couldn’t be loaded

Return type:

bool

load_autostart() bool#

Loads all autostart entries

Returns:

True if all desktop etntries could be loaded, False if some couldn’t be loaded

Return type:

bool

get_entries_by_category(category: str) list[desktop_entry_lib.__init__.DesktopEntry]#

Returns a list of all desktop entries that have the given category

Parameters:

category (str) – The category

Returns:

The list of desktop entries

Return type:

list[desktop_entry_lib.__init__.DesktopEntry]

get_entries_by_mime_type(mime_type: str) list[desktop_entry_lib.__init__.DesktopEntry]#

Returns a list of all desktop entries that can open the given MimeType

Parameters:

mime_type (str) – The MimeType

Returns:

The list of desktop entries

Return type:

list[desktop_entry_lib.__init__.DesktopEntry]

get_visible_entries() list[desktop_entry_lib.__init__.DesktopEntry]#

Returns a list of all desktop enties that should be shown to the User

Returns:

The list of desktop entries

Return type:

list[desktop_entry_lib.__init__.DesktopEntry]

get_menu_entries() list[desktop_entry_lib.__init__.DesktopEntry]#

Returns a list of all desktop enties that should be shown in the Menu

Returns:

The list of desktop entries

Return type:

list[desktop_entry_lib.__init__.DesktopEntry]