IFileOperationProgressSink.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Sample implementation of IFileOperationProgressSink that just prints
  2. # some basic info
  3. import pythoncom
  4. from win32com.shell import shell, shellcon
  5. from win32com.server.policy import DesignatedWrapPolicy
  6. class FileOperationProgressSink(DesignatedWrapPolicy):
  7. _com_interfaces_ = [shell.IID_IFileOperationProgressSink]
  8. _public_methods_ = [
  9. "StartOperations",
  10. "FinishOperations",
  11. "PreRenameItem",
  12. "PostRenameItem",
  13. "PreMoveItem",
  14. "PostMoveItem",
  15. "PreCopyItem",
  16. "PostCopyItem",
  17. "PreDeleteItem",
  18. "PostDeleteItem",
  19. "PreNewItem",
  20. "PostNewItem",
  21. "UpdateProgress",
  22. "ResetTimer",
  23. "PauseTimer",
  24. "ResumeTimer",
  25. ]
  26. def __init__(self):
  27. self._wrap_(self)
  28. self.newItem = None
  29. def PreDeleteItem(self, flags, item):
  30. # Can detect cases where to stop via flags and condition below, however the operation
  31. # does not actual stop, we can resort to raising an exception as that does stop things
  32. # but that may need some additional considerations before implementing.
  33. return 0 if flags & shellcon.TSF_DELETE_RECYCLE_IF_POSSIBLE else 0x80004005 # S_OK, or E_FAIL
  34. def PostDeleteItem(self, flags, item, hr_delete, newly_created):
  35. if newly_created:
  36. self.newItem = newly_created.GetDisplayName(shellcon.SHGDN_FORPARSING)
  37. def create_sink():
  38. return pythoncom.WrapObject(FileOperationProgressSink(), shell.IID_IFileOperationProgressSink)