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.

documents.py 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. """ Management of documents for AXDebugging.
  2. """
  3. import pythoncom
  4. import win32api
  5. from win32com.server.exception import Exception
  6. from win32com.server.util import unwrap
  7. from . import axdebug, codecontainer, contexts, gateways
  8. from .util import RaiseNotImpl, _wrap, _wrap_remove, trace
  9. # def trace(*args):
  10. # pass
  11. def GetGoodFileName(fname):
  12. if fname[0] != "<":
  13. return win32api.GetFullPathName(fname)
  14. return fname
  15. class DebugDocumentProvider(gateways.DebugDocumentProvider):
  16. def __init__(self, doc):
  17. self.doc = doc
  18. def GetName(self, dnt):
  19. return self.doc.GetName(dnt)
  20. def GetDocumentClassId(self):
  21. return self.doc.GetDocumentClassId()
  22. def GetDocument(self):
  23. return self.doc
  24. class DebugDocumentText(
  25. gateways.DebugDocumentInfo, gateways.DebugDocumentText, gateways.DebugDocument
  26. ):
  27. _com_interfaces_ = (
  28. gateways.DebugDocumentInfo._com_interfaces_
  29. + gateways.DebugDocumentText._com_interfaces_
  30. + gateways.DebugDocument._com_interfaces_
  31. )
  32. _public_methods_ = (
  33. gateways.DebugDocumentInfo._public_methods_
  34. + gateways.DebugDocumentText._public_methods_
  35. + gateways.DebugDocument._public_methods_
  36. )
  37. # A class which implements a DebugDocumentText, using the functionality
  38. # provided by a codeContainer
  39. def __init__(self, codeContainer):
  40. gateways.DebugDocumentText.__init__(self)
  41. gateways.DebugDocumentInfo.__init__(self)
  42. gateways.DebugDocument.__init__(self)
  43. self.codeContainer = codeContainer
  44. def _Close(self):
  45. self.docContexts = None
  46. # self.codeContainer._Close()
  47. self.codeContainer = None
  48. # IDebugDocumentInfo
  49. def GetName(self, dnt):
  50. return self.codeContainer.GetName(dnt)
  51. def GetDocumentClassId(self):
  52. return "{DF630910-1C1D-11d0-AE36-8C0F5E000000}"
  53. # IDebugDocument has no methods!
  54. #
  55. # IDebugDocumentText methods.
  56. # def GetDocumentAttributes
  57. def GetSize(self):
  58. # trace("GetSize")
  59. return self.codeContainer.GetNumLines(), self.codeContainer.GetNumChars()
  60. def GetPositionOfLine(self, cLineNumber):
  61. return self.codeContainer.GetPositionOfLine(cLineNumber)
  62. def GetLineOfPosition(self, charPos):
  63. return self.codeContainer.GetLineOfPosition(charPos)
  64. def GetText(self, charPos, maxChars, wantAttr):
  65. # Get all the attributes, else the tokenizer will get upset.
  66. # XXX - not yet!
  67. # trace("GetText", charPos, maxChars, wantAttr)
  68. cont = self.codeContainer
  69. attr = cont.GetSyntaxColorAttributes()
  70. return cont.GetText(), attr
  71. def GetPositionOfContext(self, context):
  72. trace("GetPositionOfContext", context)
  73. context = unwrap(context)
  74. return context.offset, context.length
  75. # Return a DebugDocumentContext.
  76. def GetContextOfPosition(self, charPos, maxChars):
  77. # Make one
  78. doc = _wrap(self, axdebug.IID_IDebugDocument)
  79. rc = self.codeContainer.GetCodeContextAtPosition(charPos)
  80. return rc.QueryInterface(axdebug.IID_IDebugDocumentContext)
  81. class CodeContainerProvider:
  82. """An abstract Python class which provides code containers!
  83. Given a Python file name (as the debugger knows it by) this will
  84. return a CodeContainer interface suitable for use.
  85. This provides a simple base imlpementation that simply supports
  86. a dictionary of nodes and providers.
  87. """
  88. def __init__(self):
  89. self.ccsAndNodes = {}
  90. def AddCodeContainer(self, cc, node=None):
  91. fname = GetGoodFileName(cc.fileName)
  92. self.ccsAndNodes[fname] = cc, node
  93. def FromFileName(self, fname):
  94. cc, node = self.ccsAndNodes.get(GetGoodFileName(fname), (None, None))
  95. # if cc is None:
  96. # print "FromFileName for %s returning None" % fname
  97. return cc
  98. def Close(self):
  99. for cc, node in self.ccsAndNodes.values():
  100. try:
  101. # Must close the node before closing the provider
  102. # as node may make calls on provider (eg Reset breakpoints etc)
  103. if node is not None:
  104. node.Close()
  105. cc._Close()
  106. except pythoncom.com_error:
  107. pass
  108. self.ccsAndNodes = {}