qgis_deployment_toolbelt.shortcuts.shortcuts_handler module

Cross-platform shortcuts manager. Derived from pycrosskit, by Jiri Otoupal. See also: https://github.com/newville/pyshortcuts/ Author: Julien Moura (https://github.com/guts)

class qgis_deployment_toolbelt.shortcuts.shortcuts_handler.ApplicationShortcut(name: str, exec_path: str | Path, exec_arguments: Iterable[str] | None = None, description: str | None = None, icon_path: str | Path | None = None, work_dir: str | Path | None = None)

Bases: object

__init__(name: str, exec_path: str | Path, exec_arguments: Iterable[str] | None = None, description: str | None = None, icon_path: str | Path | None = None, work_dir: str | Path | None = None)

Initialize a shortcut object.

Parameters:
  • name (str) – name of the shortcut that will be created

  • exec_path (str | Path) – path to the executable (which should exist)

  • exec_arguments (Iterable[str] | None, optional) – list of arguments and options to pass to the executable. Defaults to None.

  • description (str | None, optional) – shortcut description. Defaults to None.

  • icon_path (str | Path | None, optional) – path to icon file. Defaults to None.

  • work_dir (str | Path | None, optional) – current folder where to start the executable. Defaults to None. In QDT, it’s the profile folder.

Raises:

ValueError – if shortcut name contains invalid characters (depending on operating system)

check_exec_arguments(exec_arguments: Iterable[str] | None) str | None

Check if exec_arguments are valid.

Parameters:

exec_arguments (Iterable[str] | None) – input executable arguments to check

Returns:

str of arguments

Return type:

str | None

check_icon_path(icon_path: str | Path | None) Path | None

Check icon path and return full path if it exists.

Parameters:

icon_path (str | Path | None) – input icon path to check

Returns:

icon path as Path if str or Path, else None

Return type:

Path | None

check_work_dir(work_dir: str | Path | None) Path | None

Check work dir and return full path if it exists.

Parameters:

work_dir (str | Path | None) – input work dir to check

Returns:

work dir as Path if str or Path, else None

Return type:

Path | None

create(desktop: bool = False, start_menu: bool = False) tuple[Path | None, Path | None]

Creates shortcuts.

Parameters:
  • desktop (bool, optional) – True to generate a Desktop shortcut. Defaults to False.

  • start_menu (bool, optional) – True to generate a ‘Start Menu’ shortcut. Defaults to False.

Raises:

TypeError – if options are not booleans

Returns:

desktop and startmenu path

Return type:

tuple[Path, Path]

property desktop_path: Path

Return the user Desktop folder.

Partly inspired from https://stackoverflow.com/a/13742626/2556577.

Returns:

path to the current user Desktop folder.

Return type:

Path

freedesktop_create() tuple[Path | None, Path | None]

Creates shortcut on distributions using FreeDesktop.

Returns:

desktop and startmenu path

Return type:

tuple[Path | None, Path | None]

property homedir_path: Path | None

Return home directory.

For Windows, note that we return CSIDL_PROFILE, not CSIDL_APPDATA, CSIDL_LOCAL_APPDATA or CSIDL_COMMON_APPDATA. See: https://www.nirsoft.net/articles/find_special_folder_location.html TODO: evaluate use of platformdirs

Returns:

path to the user home

Return type:

Path | None

property startmenu_path: Path | None

Return user Start Menu Programs folder.

For Windows, note that we return CSIDL_PROGRAMS not CSIDL_COMMON_PROGRAMS.

Returns:

path to the Start Menu Programs folder

Return type:

Path

win32_create() tuple[Path | None, Path | None]

Creates shortcut on Windows.

Returns:

desktop and startmenu path

Return type:

tuple[Path | None, Path | None]