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.

IFileOperationProgressSink.py 5.0KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. # Sample implementation of IFileOperationProgressSink that just prints
  2. # some basic info
  3. import pythoncom
  4. from win32com.server.policy import DesignatedWrapPolicy
  5. from win32com.shell import shell, shellcon
  6. tsf_flags = list(
  7. (k, v) for k, v in list(shellcon.__dict__.items()) if k.startswith("TSF_")
  8. )
  9. def decode_flags(flags):
  10. if flags == 0:
  11. return "TSF_NORMAL"
  12. flag_txt = ""
  13. for k, v in tsf_flags:
  14. if flags & v:
  15. if flag_txt:
  16. flag_txt = flag_txt + "|" + k
  17. else:
  18. flag_txt = k
  19. return flag_txt
  20. class FileOperationProgressSink(DesignatedWrapPolicy):
  21. _com_interfaces_ = [shell.IID_IFileOperationProgressSink]
  22. _public_methods_ = [
  23. "StartOperations",
  24. "FinishOperations",
  25. "PreRenameItem",
  26. "PostRenameItem",
  27. "PreMoveItem",
  28. "PostMoveItem",
  29. "PreCopyItem",
  30. "PostCopyItem",
  31. "PreDeleteItem",
  32. "PostDeleteItem",
  33. "PreNewItem",
  34. "PostNewItem",
  35. "UpdateProgress",
  36. "ResetTimer",
  37. "PauseTimer",
  38. "ResumeTimer",
  39. ]
  40. def __init__(self):
  41. self._wrap_(self)
  42. def StartOperations(self):
  43. print("StartOperations")
  44. def FinishOperations(self, Result):
  45. print("FinishOperations: HRESULT ", Result)
  46. def PreRenameItem(self, Flags, Item, NewName):
  47. print(
  48. "PreRenameItem: Renaming "
  49. + Item.GetDisplayName(shellcon.SHGDN_FORPARSING)
  50. + " to "
  51. + NewName
  52. )
  53. def PostRenameItem(self, Flags, Item, NewName, hrRename, NewlyCreated):
  54. if NewlyCreated is not None:
  55. newfile = NewlyCreated.GetDisplayName(shellcon.SHGDN_FORPARSING)
  56. else:
  57. newfile = "not renamed, HRESULT " + str(hrRename)
  58. print(
  59. "PostRenameItem: renamed "
  60. + Item.GetDisplayName(shellcon.SHGDN_FORPARSING)
  61. + " to "
  62. + newfile
  63. )
  64. def PreMoveItem(self, Flags, Item, DestinationFolder, NewName):
  65. print(
  66. "PreMoveItem: Moving "
  67. + Item.GetDisplayName(shellcon.SHGDN_FORPARSING)
  68. + " to "
  69. + DestinationFolder.GetDisplayName(shellcon.SHGDN_FORPARSING)
  70. + "\\"
  71. + str(NewName)
  72. )
  73. def PostMoveItem(
  74. self, Flags, Item, DestinationFolder, NewName, hrMove, NewlyCreated
  75. ):
  76. if NewlyCreated is not None:
  77. newfile = NewlyCreated.GetDisplayName(shellcon.SHGDN_FORPARSING)
  78. else:
  79. newfile = "not copied, HRESULT " + str(hrMove)
  80. print(
  81. "PostMoveItem: Moved "
  82. + Item.GetDisplayName(shellcon.SHGDN_FORPARSING)
  83. + " to "
  84. + newfile
  85. )
  86. def PreCopyItem(self, Flags, Item, DestinationFolder, NewName):
  87. if not NewName:
  88. NewName = ""
  89. print(
  90. "PreCopyItem: Copying "
  91. + Item.GetDisplayName(shellcon.SHGDN_FORPARSING)
  92. + " to "
  93. + DestinationFolder.GetDisplayName(shellcon.SHGDN_FORPARSING)
  94. + "\\"
  95. + NewName
  96. )
  97. print("Flags: ", decode_flags(Flags))
  98. def PostCopyItem(
  99. self, Flags, Item, DestinationFolder, NewName, hrCopy, NewlyCreated
  100. ):
  101. if NewlyCreated is not None:
  102. newfile = NewlyCreated.GetDisplayName(shellcon.SHGDN_FORPARSING)
  103. else:
  104. newfile = "not copied, HRESULT " + str(hrCopy)
  105. print(
  106. "PostCopyItem: Copied "
  107. + Item.GetDisplayName(shellcon.SHGDN_FORPARSING)
  108. + " to "
  109. + newfile
  110. )
  111. print("Flags: ", decode_flags(Flags))
  112. def PreDeleteItem(self, Flags, Item):
  113. print(
  114. "PreDeleteItem: Deleting " + Item.GetDisplayName(shellcon.SHGDN_FORPARSING)
  115. )
  116. def PostDeleteItem(self, Flags, Item, hrDelete, NewlyCreated):
  117. print(
  118. "PostDeleteItem: Deleted " + Item.GetDisplayName(shellcon.SHGDN_FORPARSING)
  119. )
  120. if NewlyCreated:
  121. print(
  122. " Moved to recycle bin - "
  123. + NewlyCreated.GetDisplayName(shellcon.SHGDN_FORPARSING)
  124. )
  125. def PreNewItem(self, Flags, DestinationFolder, NewName):
  126. print(
  127. "PreNewItem: Creating "
  128. + DestinationFolder.GetDisplayName(shellcon.SHGDN_FORPARSING)
  129. + "\\"
  130. + NewName
  131. )
  132. def PostNewItem(
  133. self,
  134. Flags,
  135. DestinationFolder,
  136. NewName,
  137. TemplateName,
  138. FileAttributes,
  139. hrNew,
  140. NewItem,
  141. ):
  142. print(
  143. "PostNewItem: Created " + NewItem.GetDisplayName(shellcon.SHGDN_FORPARSING)
  144. )
  145. def UpdateProgress(self, WorkTotal, WorkSoFar):
  146. print("UpdateProgress: ", WorkSoFar, WorkTotal)
  147. def ResetTimer(self):
  148. print("ResetTimer")
  149. def PauseTimer(self):
  150. print("PauseTimer")
  151. def ResumeTimer(self):
  152. print("ResumeTimer")
  153. def CreateSink():
  154. return pythoncom.WrapObject(
  155. FileOperationProgressSink(), shell.IID_IFileOperationProgressSink
  156. )