Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

shortcut.py 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. Creation of Windows shortcuts.
  5. Requires win32all.
  6. """
  7. import os
  8. import pythoncom # type: ignore[import]
  9. from win32com.shell import shell # type: ignore[import]
  10. def open(filename):
  11. """
  12. Open an existing shortcut for reading.
  13. @return: The shortcut object
  14. @rtype: Shortcut
  15. """
  16. sc = Shortcut()
  17. sc.load(filename)
  18. return sc
  19. class Shortcut:
  20. """
  21. A shortcut on Win32.
  22. """
  23. def __init__(
  24. self,
  25. path=None,
  26. arguments=None,
  27. description=None,
  28. workingdir=None,
  29. iconpath=None,
  30. iconidx=0,
  31. ):
  32. """
  33. @param path: Location of the target
  34. @param arguments: If path points to an executable, optional arguments
  35. to pass
  36. @param description: Human-readable description of target
  37. @param workingdir: Directory from which target is launched
  38. @param iconpath: Filename that contains an icon for the shortcut
  39. @param iconidx: If iconpath is set, optional index of the icon desired
  40. """
  41. self._base = pythoncom.CoCreateInstance(
  42. shell.CLSID_ShellLink,
  43. None,
  44. pythoncom.CLSCTX_INPROC_SERVER,
  45. shell.IID_IShellLink,
  46. )
  47. if path is not None:
  48. self.SetPath(os.path.abspath(path))
  49. if arguments is not None:
  50. self.SetArguments(arguments)
  51. if description is not None:
  52. self.SetDescription(description)
  53. if workingdir is not None:
  54. self.SetWorkingDirectory(os.path.abspath(workingdir))
  55. if iconpath is not None:
  56. self.SetIconLocation(os.path.abspath(iconpath), iconidx)
  57. def load(self, filename):
  58. """
  59. Read a shortcut file from disk.
  60. """
  61. self._base.QueryInterface(pythoncom.IID_IPersistFile).Load(
  62. os.path.abspath(filename)
  63. )
  64. def save(self, filename):
  65. """
  66. Write the shortcut to disk.
  67. The file should be named something.lnk.
  68. """
  69. self._base.QueryInterface(pythoncom.IID_IPersistFile).Save(
  70. os.path.abspath(filename), 0
  71. )
  72. def __getattr__(self, name):
  73. return getattr(self._base, name)