home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 May / PCWorld_2002-05_cd.bin / Software / TemaCD / activepython / ActivePython-2.1.1.msi / Python21_win32comext_axdebug_documents.py < prev    next >
Encoding:
Python Source  |  2001-07-26  |  3.9 KB  |  125 lines

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