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.

testHost4Dbg.py 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import os
  2. import sys
  3. import traceback
  4. import pythoncom
  5. import win32ui
  6. from win32com.axscript import axscript
  7. from win32com.axscript.server import axsite
  8. from win32com.axscript.server.error import Exception
  9. from win32com.server import util
  10. version = "0.0.1"
  11. class MySite(axsite.AXSite):
  12. def OnScriptError(self, error):
  13. print("An error occurred in the Script Code")
  14. exc = error.GetExceptionInfo()
  15. try:
  16. text = error.GetSourceLineText()
  17. except:
  18. text = "<unknown>"
  19. context, line, char = error.GetSourcePosition()
  20. print(
  21. "Exception: %s (line %d)\n%s\n%s^\n%s"
  22. % (exc[1], line, text, " " * (char - 1), exc[2])
  23. )
  24. class ObjectModel:
  25. _public_methods_ = ["echo", "msgbox"]
  26. def echo(self, *args):
  27. print("".join(map(str, args)))
  28. def msgbox(self, *args):
  29. msg = "".join(map(str, args))
  30. win32ui.MessageBox(msg)
  31. def TestEngine():
  32. model = {"Test": util.wrap(ObjectModel())}
  33. scriptDir = "."
  34. site = MySite(model)
  35. pyEngine = site._AddEngine("Python")
  36. # pyEngine2 = site._AddEngine("Python")
  37. vbEngine = site._AddEngine("VBScript")
  38. # forthEngine = site._AddEngine("ForthScript")
  39. try:
  40. # code = open(os.path.join(scriptDir, "debugTest.4ths"),"rb").read()
  41. # forthEngine.AddCode(code)
  42. code = open(os.path.join(scriptDir, "debugTest.pys"), "rb").read()
  43. pyEngine.AddCode(code)
  44. code = open(os.path.join(scriptDir, "debugTest.vbs"), "rb").read()
  45. vbEngine.AddCode(code)
  46. # code = open(os.path.join(scriptDir, "debugTestFail.pys"),"rb").read()
  47. # pyEngine2.AddCode(code)
  48. # from win32com.axdebug import axdebug
  49. # sessionProvider=pythoncom.CoCreateInstance(axdebug.CLSID_DefaultDebugSessionProvider,None,pythoncom.CLSCTX_ALL, axdebug.IID_IDebugSessionProvider)
  50. # sessionProvider.StartDebugSession(None)
  51. input("Press enter to continue")
  52. # forthEngine.Start()
  53. pyEngine.Start() # Actually run the Python code
  54. vbEngine.Start() # Actually run the VB code
  55. except pythoncom.com_error as details:
  56. print("Script failed: %s (0x%x)" % (details[1], details[0]))
  57. # Now run the code expected to fail!
  58. # try:
  59. # pyEngine2.Start() # Actually run the Python code that fails!
  60. # print "Script code worked when it should have failed."
  61. # except pythoncom.com_error:
  62. # pass
  63. site._Close()
  64. if __name__ == "__main__":
  65. import win32com.axdebug.util
  66. try:
  67. TestEngine()
  68. except:
  69. traceback.print_exc()
  70. win32com.axdebug.util._dump_wrapped()
  71. sys.exc_type = sys.exc_value = sys.exc_traceback = None
  72. print(pythoncom._GetInterfaceCount(), "com objects still alive")