ITransferAdviseSink.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # ITransferAdviseSink implementation template
  2. import pythoncom
  3. from win32com.shell import shell, shellcon
  4. from win32com.server.policy import DesignatedWrapPolicy
  5. tsf_flags = list((k,v) for k,v in list(shellcon.__dict__.items()) if k.startswith('TSF_'))
  6. def decode_flags(flags):
  7. if flags == 0:
  8. return 'TSF_NORMAL'
  9. flag_txt = ''
  10. for k,v in tsf_flags:
  11. if flags & v:
  12. if flag_txt:
  13. flag_txt = flag_txt + '|' + k
  14. else:
  15. flag_txt = k
  16. return flag_txt
  17. TRANSFER_ADVISE_STATES = {}
  18. for k,v in list(shellcon.__dict__.items()):
  19. if k.startswith('TS_'):
  20. TRANSFER_ADVISE_STATES[v] = k
  21. def decode_flags(flags):
  22. if flags == 0:
  23. return 'TSF_NORMAL'
  24. flag_txt = ''
  25. for k,v in tsf_flags:
  26. if flags & v:
  27. if flag_txt:
  28. flag_txt = flag_txt + '|' + k
  29. else:
  30. flag_txt = k
  31. return flag_txt
  32. class TransferAdviseSink(DesignatedWrapPolicy):
  33. _com_interfaces_ = [shell.IID_ITransferAdviseSink]
  34. _public_methods_ = [
  35. "UpdateProgress", "UpdateTransferState", "ConfirmOverwrite",
  36. "ConfirmEncryptionLoss", "FileFailure", "SubStreamFailure", "PropertyFailure"
  37. ]
  38. def __init__(self):
  39. self._wrap_(self)
  40. def UpdateProgress(self, SizeCurrent, SizeTotal, FilesCurrent, FilesTotal, FoldersCurrent, FoldersTotal):
  41. print('UpdateProgress - processed so far:')
  42. print('\t %s out of %s bytes' %(SizeCurrent, SizeTotal))
  43. print('\t %s out of %s files' %(FilesCurrent, FilesTotal))
  44. print('\t %s out of %s folders' %(FoldersCurrent, FoldersTotal))
  45. def UpdateTransferState(self, State):
  46. print('Current state: ', TRANSFER_ADVISE_STATES.get(State, '??? Unknown state %s ???' %State))
  47. def ConfirmOverwrite(self, Source, DestParent , Name):
  48. print('ConfirmOverwrite: ', Source.GetDisplayName(shellcon.SHGDN_FORPARSING),
  49. DestParent.GetDisplayName(shellcon.SHGDN_FORPARSING),
  50. Name)
  51. def ConfirmEncryptionLoss(self, Source):
  52. print('ConfirmEncryptionLoss:', Source.GetDisplayName(shellcon.SHGDN_FORPARSING))
  53. def FileFailure(self, Item, ItemName , Error):
  54. print('FileFailure:', Item.GetDisplayName(shellcon.SHGDN_FORPARSING), ItemName)
  55. def SubStreamFailure(self, Item, StreamName , Error):
  56. print('SubStreamFailure:\n')
  57. def PropertyFailure(self, Item, key , Error):
  58. print('PropertyFailure:\n')
  59. def CreateSink():
  60. return pythoncom.WrapObject(TransferAdviseSink(), shell.IID_ITransferAdviseSink, shell.IID_ITransferAdviseSink)