contexts.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. """ A module for managing the AXDebug I*Contexts
  2. """
  3. import gateways, axdebug
  4. import pythoncom, win32com.server.util
  5. # Utility function for wrapping object created by this module.
  6. from .util import _wrap, _wrap_remove, trace
  7. from . import adb
  8. class DebugCodeContext(gateways.DebugCodeContext, gateways.DebugDocumentContext):
  9. # NOTE: We also implement the IDebugDocumentContext interface for Simple Hosts.
  10. # Thus, debugDocument may be NULL when we have smart hosts - but in that case, we
  11. # wont be called upon to provide it.
  12. _public_methods_ = gateways.DebugCodeContext._public_methods_ + \
  13. gateways.DebugDocumentContext._public_methods_
  14. _com_interfaces_ = gateways.DebugCodeContext._com_interfaces_ + \
  15. gateways.DebugDocumentContext._com_interfaces_
  16. def __init__(self, lineNo, charPos, len, codeContainer, debugSite):
  17. self.debugSite = debugSite
  18. self.offset = charPos
  19. self.length = len
  20. self.breakPointState = 0
  21. self.lineno = lineNo
  22. gateways.DebugCodeContext.__init__(self)
  23. self.codeContainer = codeContainer
  24. def _Close(self):
  25. self.debugSite = None
  26. def GetDocumentContext(self):
  27. if self.debugSite is not None:
  28. # We have a smart host - let him give it to us.
  29. return self.debugSite.GetDocumentContextFromPosition(
  30. self.codeContainer.sourceContext,
  31. self.offset,
  32. self.length)
  33. else:
  34. # Simple host - Fine - Ill do it myself!
  35. return _wrap(self, axdebug.IID_IDebugDocumentContext)
  36. def SetBreakPoint(self, bps):
  37. self.breakPointState = bps
  38. adb.OnSetBreakPoint(self, bps, self.lineno)
  39. # The DebugDocumentContext methods for simple hosts.
  40. def GetDocument(self):
  41. return self.codeContainer.debugDocument
  42. def EnumCodeContexts(self):
  43. return _wrap(EnumDebugCodeContexts([self]), axdebug.IID_IEnumDebugCodeContexts)
  44. class EnumDebugCodeContexts(gateways.EnumDebugCodeContexts):
  45. def _wrap(self, obj):
  46. return _wrap(obj, axdebug.IID_IDebugCodeContext)