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.

connect.py 1.5KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. """Utilities for working with Connections"""
  2. import pythoncom
  3. import win32com.server.util
  4. class SimpleConnection:
  5. "A simple, single connection object"
  6. def __init__(self, coInstance=None, eventInstance=None, eventCLSID=None, debug=0):
  7. self.cp = None
  8. self.cookie = None
  9. self.debug = debug
  10. if not coInstance is None:
  11. self.Connect(coInstance, eventInstance, eventCLSID)
  12. def __del__(self):
  13. try:
  14. self.Disconnect()
  15. except pythoncom.error:
  16. # Ignore disconnection as we are torn down.
  17. pass
  18. def _wrap(self, obj):
  19. useDispatcher = None
  20. if self.debug:
  21. from win32com.server import dispatcher
  22. useDispatcher = dispatcher.DefaultDebugDispatcher
  23. return win32com.server.util.wrap(obj, useDispatcher=useDispatcher)
  24. def Connect(self, coInstance, eventInstance, eventCLSID=None):
  25. try:
  26. oleobj = coInstance._oleobj_
  27. except AttributeError:
  28. oleobj = coInstance
  29. cpc = oleobj.QueryInterface(pythoncom.IID_IConnectionPointContainer)
  30. if eventCLSID is None:
  31. eventCLSID = eventInstance.CLSID
  32. comEventInstance = self._wrap(eventInstance)
  33. self.cp = cpc.FindConnectionPoint(eventCLSID)
  34. self.cookie = self.cp.Advise(comEventInstance)
  35. def Disconnect(self):
  36. if not self.cp is None:
  37. if self.cookie:
  38. self.cp.Unadvise(self.cookie)
  39. self.cookie = None
  40. self.cp = None