gateways.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. # Classes which describe interfaces.
  2. from win32com.server.exception import Exception
  3. from win32com.server.util import ListEnumeratorGateway
  4. from win32com.axdebug import axdebug
  5. from win32com.axdebug.util import RaiseNotImpl, _wrap
  6. import pythoncom
  7. import win32com.server.connect
  8. import winerror
  9. class EnumDebugCodeContexts(ListEnumeratorGateway):
  10. """A class to expose a Python sequence as an EnumDebugCodeContexts
  11. Create an instance of this class passing a sequence (list, tuple, or
  12. any sequence protocol supporting object) and it will automatically
  13. support the EnumDebugCodeContexts interface for the object.
  14. """
  15. _com_interfaces_ = [ axdebug.IID_IEnumDebugCodeContexts ]
  16. class EnumDebugStackFrames(ListEnumeratorGateway):
  17. """A class to expose a Python sequence as an EnumDebugStackFrames
  18. Create an instance of this class passing a sequence (list, tuple, or
  19. any sequence protocol supporting object) and it will automatically
  20. support the EnumDebugStackFrames interface for the object.
  21. """
  22. _com_interfaces_ = [ axdebug.IID_IEnumDebugStackFrames ]
  23. class EnumDebugApplicationNodes(ListEnumeratorGateway):
  24. """A class to expose a Python sequence as an EnumDebugStackFrames
  25. Create an instance of this class passing a sequence (list, tuple, or
  26. any sequence protocol supporting object) and it will automatically
  27. support the EnumDebugApplicationNodes interface for the object.
  28. """
  29. _com_interfaces_ = [ axdebug.IID_IEnumDebugApplicationNodes ]
  30. class EnumRemoteDebugApplications(ListEnumeratorGateway):
  31. _com_interfaces_ = [ axdebug.IID_IEnumRemoteDebugApplications ]
  32. class EnumRemoteDebugApplicationThreads(ListEnumeratorGateway):
  33. _com_interfaces_ = [ axdebug.IID_IEnumRemoteDebugApplicationThreads ]
  34. class DebugDocumentInfo:
  35. _public_methods_ = ["GetName", "GetDocumentClassId"]
  36. _com_interfaces_ = [axdebug.IID_IDebugDocumentInfo]
  37. def __init__(self):
  38. pass
  39. def GetName(self, dnt):
  40. """ Get the one of the name of the document
  41. dnt -- int DOCUMENTNAMETYPE
  42. """
  43. RaiseNotImpl("GetName")
  44. def GetDocumentClassId(self):
  45. """
  46. Result must be an IID object (or string representing one).
  47. """
  48. RaiseNotImpl("GetDocumentClassId")
  49. class DebugDocumentProvider(DebugDocumentInfo):
  50. _public_methods_ = DebugDocumentInfo._public_methods_ + ["GetDocument"]
  51. _com_interfaces_ = DebugDocumentInfo._com_interfaces_ + [axdebug.IID_IDebugDocumentProvider]
  52. def GetDocument(self):
  53. RaiseNotImpl("GetDocument")
  54. class DebugApplicationNode(DebugDocumentProvider):
  55. """Provides the functionality of IDebugDocumentProvider, plus a context within a project tree.
  56. """
  57. _public_methods_ = """EnumChildren GetParent SetDocumentProvider
  58. Close Attach Detach""".split() + \
  59. DebugDocumentProvider._public_methods_
  60. _com_interfaces_ = [axdebug.IID_IDebugDocumentProvider] + \
  61. DebugDocumentProvider._com_interfaces_
  62. def __init__(self):
  63. DebugDocumentProvider.__init__(self)
  64. def EnumChildren(self):
  65. # Result is type PyIEnumDebugApplicationNodes
  66. RaiseNotImpl("EnumChildren")
  67. def GetParent(self):
  68. # result is type PyIDebugApplicationNode
  69. RaiseNotImpl("GetParent")
  70. def SetDocumentProvider(self, pddp): # PyIDebugDocumentProvider pddp
  71. # void result.
  72. RaiseNotImpl("SetDocumentProvider")
  73. def Close(self):
  74. # void result.
  75. RaiseNotImpl("Close")
  76. def Attach(self, parent): # PyIDebugApplicationNode
  77. # void result.
  78. RaiseNotImpl("Attach")
  79. def Detach(self):
  80. # void result.
  81. RaiseNotImpl("Detach")
  82. class DebugApplicationNodeEvents:
  83. """Event interface for DebugApplicationNode object.
  84. """
  85. _public_methods_ = "onAddChild onRemoveChild onDetach".split()
  86. _com_interfaces_ = [axdebug.IID_IDebugApplicationNodeEvents]
  87. def __init__(self):
  88. pass
  89. def onAddChild(self, child): # PyIDebugApplicationNode
  90. # void result.
  91. RaiseNotImpl("onAddChild")
  92. def onRemoveChild(self, child): # PyIDebugApplicationNode
  93. # void result.
  94. RaiseNotImpl("onRemoveChild")
  95. def onDetach(self):
  96. # void result.
  97. RaiseNotImpl("onDetach")
  98. def onAttach(self, parent): # PyIDebugApplicationNode
  99. # void result.
  100. RaiseNotImpl("onAttach")
  101. class DebugDocument(DebugDocumentInfo):
  102. """The base interface to all debug documents.
  103. """
  104. _public_methods_ = DebugDocumentInfo._public_methods_
  105. _com_interfaces_ = [axdebug.IID_IDebugDocument] + DebugDocumentInfo._com_interfaces_
  106. class DebugDocumentText(DebugDocument):
  107. """The interface to a text only debug document.
  108. """
  109. _com_interfaces_ = [axdebug.IID_IDebugDocumentText] + \
  110. DebugDocument._com_interfaces_
  111. _public_methods_ = ["GetDocumentAttributes", "GetSize",
  112. "GetPositionOfLine", "GetLineOfPosition", "GetText",
  113. "GetPositionOfContext", "GetContextOfPosition"] + \
  114. DebugDocument._public_methods_
  115. def __init__(self):
  116. pass
  117. # IDebugDocumentText
  118. def GetDocumentAttributes(self):
  119. # Result is int (TEXT_DOC_ATTR)
  120. RaiseNotImpl("GetDocumentAttributes")
  121. def GetSize(self):
  122. # Result is (numLines, numChars)
  123. RaiseNotImpl("GetSize")
  124. def GetPositionOfLine(self, cLineNumber):
  125. # Result is int char position
  126. RaiseNotImpl("GetPositionOfLine")
  127. def GetLineOfPosition(self, charPos):
  128. # Result is int, int (lineNo, offset)
  129. RaiseNotImpl("GetLineOfPosition")
  130. def GetText(self, charPos, maxChars, wantAttr):
  131. """Params
  132. charPos -- integer
  133. maxChars -- integer
  134. wantAttr -- Should the function compute attributes.
  135. Return value must be (string, attribtues). attributes may be
  136. None if(not wantAttr)
  137. """
  138. RaiseNotImpl("GetText")
  139. def GetPositionOfContext(self, debugDocumentContext):
  140. """Params
  141. debugDocumentContext -- a PyIDebugDocumentContext object.
  142. Return value must be (charPos, numChars)
  143. """
  144. RaiseNotImpl("GetPositionOfContext")
  145. def GetContextOfPosition(self, charPos, maxChars):
  146. """Params are integers.
  147. Return value must be PyIDebugDocumentContext object
  148. """
  149. print(self)
  150. RaiseNotImpl("GetContextOfPosition")
  151. class DebugDocumentTextExternalAuthor:
  152. """Allow external editors to edit file-based debugger documents, and to notify the document when the source file has been changed.
  153. """
  154. _public_methods_ = ["GetPathName", "GetFileName", "NotifyChanged"]
  155. _com_interfaces_ = [axdebug.IID_IDebugDocumentTextExternalAuthor]
  156. def __init__(self):
  157. pass
  158. def GetPathName(self):
  159. """Return the full path (including file name) to the document's source file.
  160. Result must be (filename, fIsOriginal), where
  161. - if fIsOriginalPath is TRUE if the path refers to the original file for the document.
  162. - if fIsOriginalPath is FALSE if the path refers to a newly created temporary file.
  163. raise Exception(winerror.E_FAIL) if no source file can be created/determined.
  164. """
  165. RaiseNotImpl("GetPathName")
  166. def GetFileName(self):
  167. """Return just the name of the document, with no path information. (Used for "Save As...")
  168. Result is a string
  169. """
  170. RaiseNotImpl("GetFileName")
  171. def NotifyChanged(self):
  172. """ Notify the host that the document's source file has been saved and
  173. that its contents should be refreshed.
  174. """
  175. RaiseNotImpl("NotifyChanged")
  176. class DebugDocumentTextEvents:
  177. _public_methods_ = """onDestroy onInsertText onRemoveText
  178. onReplaceText onUpdateTextAttributes
  179. onUpdateDocumentAttributes""".split()
  180. _com_interfaces_ = [ axdebug.IID_IDebugDocumentTextEvents ]
  181. def __init__(self):
  182. pass
  183. def onDestroy(self):
  184. # Result is void.
  185. RaiseNotImpl("onDestroy")
  186. def onInsertText(self, cCharacterPosition, cNumToInsert):
  187. # Result is void.
  188. RaiseNotImpl("onInsertText")
  189. def onRemoveText(self, cCharacterPosition, cNumToRemove):
  190. # Result is void.
  191. RaiseNotImpl("onRemoveText")
  192. def onReplaceText(self, cCharacterPosition, cNumToReplace):
  193. # Result is void.
  194. RaiseNotImpl("onReplaceText")
  195. def onUpdateTextAttributes(self, cCharacterPosition, cNumToUpdate):
  196. # Result is void.
  197. RaiseNotImpl("onUpdateTextAttributes")
  198. def onUpdateDocumentAttributes(self,textdocattr): # TEXT_DOC_ATTR
  199. # Result is void.
  200. RaiseNotImpl("onUpdateDocumentAttributes")
  201. class DebugDocumentContext:
  202. _public_methods_ = [ 'GetDocument', 'EnumCodeContexts']
  203. _com_interfaces_ = [ axdebug.IID_IDebugDocumentContext ]
  204. def __init__(self):
  205. pass
  206. def GetDocument(self):
  207. """Return value must be a PyIDebugDocument object
  208. """
  209. RaiseNotImpl("GetDocument")
  210. def EnumCodeContexts(self):
  211. """Return value must be a PyIEnumDebugCodeContexts object
  212. """
  213. RaiseNotImpl("EnumCodeContexts")
  214. class DebugCodeContext:
  215. _public_methods_ = [ 'GetDocumentContext', 'SetBreakPoint']
  216. _com_interfaces_ = [ axdebug.IID_IDebugCodeContext ]
  217. def __init__(self):
  218. pass
  219. def GetDocumentContext(self):
  220. """Return value must be a PyIDebugDocumentContext object
  221. """
  222. RaiseNotImpl("GetDocumentContext")
  223. def SetBreakPoint(self, bps):
  224. """bps -- an integer with flags.
  225. """
  226. RaiseNotImpl("SetBreakPoint")
  227. class DebugStackFrame:
  228. """Abstraction representing a logical stack frame on the stack of a thread."""
  229. _public_methods_ = [ 'GetCodeContext', 'GetDescriptionString', 'GetLanguageString', 'GetThread', 'GetDebugProperty']
  230. _com_interfaces_ = [ axdebug.IID_IDebugStackFrame ]
  231. def __init__(self):
  232. pass
  233. def GetCodeContext(self):
  234. """Returns the current code context associated with the stack frame.
  235. Return value must be a IDebugCodeContext object
  236. """
  237. RaiseNotImpl("GetCodeContext")
  238. def GetDescriptionString(self, fLong):
  239. """Returns a textual description of the stack frame.
  240. fLong -- A flag indicating if the long name is requested.
  241. """
  242. RaiseNotImpl("GetDescriptionString")
  243. def GetLanguageString(self):
  244. """Returns a short or long textual description of the language.
  245. fLong -- A flag indicating if the long name is requested.
  246. """
  247. RaiseNotImpl("GetLanguageString")
  248. def GetThread(self):
  249. """ Returns the thread associated with this stack frame.
  250. Result must be a IDebugApplicationThread
  251. """
  252. RaiseNotImpl("GetThread")
  253. def GetDebugProperty(self):
  254. RaiseNotImpl("GetDebugProperty")
  255. class DebugDocumentHost:
  256. """The interface from the IDebugDocumentHelper back to
  257. the smart host or language engine. This interface
  258. exposes host specific functionality such as syntax coloring.
  259. """
  260. _public_methods_ = [ 'GetDeferredText', 'GetScriptTextAttributes', 'OnCreateDocumentContext', 'GetPathName', 'GetFileName', 'NotifyChanged']
  261. _com_interfaces_ = [ axdebug.IID_IDebugDocumentHost ]
  262. def __init__(self):
  263. pass
  264. def GetDeferredText(self, dwTextStartCookie, maxChars, bWantAttr):
  265. RaiseNotImpl("GetDeferredText")
  266. def GetScriptTextAttributes(self, codeText, delimterText, flags):
  267. # Result must be an attribute sequence of same "length" as the code.
  268. RaiseNotImpl("GetScriptTextAttributes")
  269. def OnCreateDocumentContext(self):
  270. # Result must be a PyIUnknown
  271. RaiseNotImpl("OnCreateDocumentContext")
  272. def GetPathName(self):
  273. # Result must be (string, int) where the int is a BOOL
  274. # - TRUE if the path refers to the original file for the document.
  275. # - FALSE if the path refers to a newly created temporary file.
  276. # - raise Exception(scode=E_FAIL) if no source file can be created/determined.
  277. RaiseNotImpl("GetPathName")
  278. def GetFileName(self):
  279. # Result is a string with just the name of the document, no path information.
  280. RaiseNotImpl("GetFileName")
  281. def NotifyChanged(self):
  282. RaiseNotImpl("NotifyChanged")
  283. # Additional gateway related functions.
  284. class DebugDocumentTextConnectServer:
  285. _public_methods_ = win32com.server.connect.IConnectionPointContainer_methods + win32com.server.connect.IConnectionPoint_methods
  286. _com_interfaces_ = [pythoncom.IID_IConnectionPoint, pythoncom.IID_IConnectionPointContainer]
  287. # IConnectionPoint interfaces
  288. def __init__(self):
  289. self.cookieNo = -1
  290. self.connections = {}
  291. def EnumConnections(self):
  292. RaiseNotImpl("EnumConnections")
  293. def GetConnectionInterface(self):
  294. RaiseNotImpl("GetConnectionInterface")
  295. def GetConnectionPointContainer(self):
  296. return _wrap(self)
  297. def Advise(self, pUnk):
  298. # Creates a connection to the client. Simply allocate a new cookie,
  299. # find the clients interface, and store it in a dictionary.
  300. interface = pUnk.QueryInterface(axdebug.IID_IDebugDocumentTextEvents,1)
  301. self.cookieNo = self.cookieNo + 1
  302. self.connections[self.cookieNo] = interface
  303. return self.cookieNo
  304. def Unadvise(self, cookie):
  305. # Destroy a connection - simply delete interface from the map.
  306. try:
  307. del self.connections[cookie]
  308. except KeyError:
  309. return Exception(scode=winerror.E_UNEXPECTED)
  310. # IConnectionPointContainer interfaces
  311. def EnumConnectionPoints(self):
  312. RaiseNotImpl("EnumConnectionPoints")
  313. def FindConnectionPoint(self, iid):
  314. # Find a connection we support. Only support the single event interface.
  315. if iid==axdebug.IID_IDebugDocumentTextEvents:
  316. return _wrap(self)
  317. raise Exception(scode=winerror.E_NOINTERFACE) # ??
  318. class RemoteDebugApplicationEvents:
  319. _public_methods_ = ["OnConnectDebugger","OnDisconnectDebugger","OnSetName","OnDebugOutput","OnClose","OnEnterBreakPoint","OnLeaveBreakPoint","OnCreateThread","OnDestroyThread","OnBreakFlagChange"]
  320. _com_interfaces_ = [axdebug.IID_IRemoteDebugApplicationEvents]
  321. def OnConnectDebugger(self, appDebugger):
  322. """appDebugger -- a PyIApplicationDebugger
  323. """
  324. RaiseNotImpl("OnConnectDebugger")
  325. def OnDisconnectDebugger(self):
  326. RaiseNotImpl("OnDisconnectDebugger")
  327. def OnSetName(self, name):
  328. RaiseNotImpl("OnSetName")
  329. def OnDebugOutput(self, string):
  330. RaiseNotImpl("OnDebugOutput")
  331. def OnClose(self):
  332. RaiseNotImpl("OnClose")
  333. def OnEnterBreakPoint(self, rdat):
  334. """rdat -- PyIRemoteDebugApplicationThread
  335. """
  336. RaiseNotImpl("OnEnterBreakPoint")
  337. def OnLeaveBreakPoint(self, rdat):
  338. """rdat -- PyIRemoteDebugApplicationThread
  339. """
  340. RaiseNotImpl("OnLeaveBreakPoint")
  341. def OnCreateThread(self, rdat):
  342. """rdat -- PyIRemoteDebugApplicationThread
  343. """
  344. RaiseNotImpl("OnCreateThread")
  345. def OnDestroyThread(self, rdat):
  346. """rdat -- PyIRemoteDebugApplicationThread
  347. """
  348. RaiseNotImpl("OnDestroyThread")
  349. def OnBreakFlagChange(self, abf, rdat):
  350. """abf -- int - one of the axdebug.APPBREAKFLAGS constants
  351. rdat -- PyIRemoteDebugApplicationThread
  352. RaiseNotImpl("OnBreakFlagChange")
  353. """
  354. class DebugExpressionContext:
  355. _public_methods_ = ["ParseLanguageText", "GetLanguageInfo"]
  356. _com_interfaces_ = [axdebug.IID_IDebugExpressionContext]
  357. def __init__(self):
  358. pass
  359. def ParseLanguageText(self, code, radix, delim, flags):
  360. """
  361. result is IDebugExpression
  362. """
  363. RaiseNotImpl("ParseLanguageText")
  364. def GetLanguageInfo(self):
  365. """
  366. result is (string langName, iid langId)
  367. """
  368. RaiseNotImpl("GetLanguageInfo")
  369. class DebugExpression:
  370. _public_methods_ = ["Start", "Abort", "QueryIsComplete", "GetResultAsString", "GetResultAsDebugProperty"]
  371. _com_interfaces_ = [axdebug.IID_IDebugExpression]
  372. def Start(self, callback):
  373. """
  374. callback -- an IDebugExpressionCallback
  375. result - void
  376. """
  377. RaiseNotImpl("Start")
  378. def Abort(self):
  379. """
  380. no params
  381. result -- void
  382. """
  383. RaiseNotImpl("Abort")
  384. def QueryIsComplete(self):
  385. """
  386. no params
  387. result -- void
  388. """
  389. RaiseNotImpl("QueryIsComplete")
  390. def GetResultAsString(self):
  391. RaiseNotImpl("GetResultAsString")
  392. def GetResultAsDebugProperty(self):
  393. RaiseNotImpl("GetResultAsDebugProperty")
  394. class ProvideExpressionContexts:
  395. _public_methods_ = ["EnumExpressionContexts"]
  396. _com_interfaces_ = [axdebug.IID_IProvideExpressionContexts]
  397. def EnumExpressionContexts(self):
  398. RaiseNotImpl("EnumExpressionContexts")