Application.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/Debug/TraceMessageBus.h>
  10. #include <AzToolsFramework/Application/ToolsApplication.h>
  11. #include <AzToolsFramework/API/EditorPythonConsoleBus.h>
  12. namespace PythonBindingsExample
  13. {
  14. struct ApplicationParameters;
  15. class Application
  16. : public AzToolsFramework::ToolsApplication
  17. , protected AZ::Debug::TraceMessageBus::Handler
  18. , protected AzToolsFramework::EditorPythonConsoleNotificationBus::Handler
  19. {
  20. public:
  21. AZ_CLASS_ALLOCATOR(Application, AZ::SystemAllocator)
  22. Application(int* argc, char*** argv);
  23. ~Application();
  24. void SetUp();
  25. bool Run();
  26. void TearDown();
  27. bool RunWithParameters(const ApplicationParameters& params);
  28. inline void GetErrorCount(int& exceptionCount, int& errorCount)
  29. {
  30. exceptionCount = m_pythonExceptionCount;
  31. errorCount = m_pythonErrorCount;
  32. }
  33. inline void ResetErrorCount()
  34. {
  35. m_pythonExceptionCount = 0;
  36. m_pythonErrorCount = 0;
  37. }
  38. protected:
  39. ////////////////////////////////////////////////////////////////////////////////////////////
  40. // TraceMessageBus
  41. bool OnPreError(const char* window, const char* fileName, int line, const char* func, const char* message) override;
  42. bool OnPreWarning(const char* window, const char* fileName, int line, const char* func, const char* message) override;
  43. bool OnPrintf(const char* window, const char* message) override;
  44. ////////////////////////////////////////////////////////////////////////////////////////////
  45. // AzToolsFramework::EditorPythonConsoleNotifications
  46. void OnTraceMessage(AZStd::string_view message) override;
  47. void OnErrorMessage(AZStd::string_view message) override;
  48. void OnExceptionMessage(AZStd::string_view message) override;
  49. bool RunFileWithArgs(const ApplicationParameters& params);
  50. void StartPythonVM();
  51. void StopPythonVM();
  52. protected:
  53. bool m_showVerboseOutput = false;
  54. bool m_startedPython = false;
  55. int m_pythonExceptionCount = 0;
  56. int m_pythonErrorCount = 0;
  57. };
  58. }