Docking_BasicDockedTools.py 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. SPDX-License-Identifier: Apache-2.0 OR MIT
  5. C6376081: Basic Function: Docked/Undocked Tools
  6. """
  7. class Tests:
  8. all_tools_docked = (
  9. "The tools are all docked together in a tabbed widget",
  10. "Failed to dock all tools together"
  11. )
  12. docked_outliner_works = (
  13. "Entity Outliner works when docked, can select an Entity",
  14. "Failed to select an Entity in the Outliner while docked"
  15. )
  16. docked_inspector_works = (
  17. "Entity Inspector works when docked, Entity name changed",
  18. "Failed to change Entity name in the Inspector while docked"
  19. )
  20. docked_console_works = (
  21. "Console works when docked, sent a Console Command",
  22. "Failed to send Console Command in the Console while docked"
  23. )
  24. def Docking_BasicDockedTools():
  25. import pyside_utils
  26. @pyside_utils.wrap_async
  27. async def run_test():
  28. """
  29. Summary:
  30. Test that tools still work as expected when docked together.
  31. Expected Behavior:
  32. Multiple tools can be docked together.
  33. Tools function while docked together and the main editor responds appropriately.
  34. Test Steps:
  35. 1) Open the tools and dock them together in a floating tabbed widget.
  36. 2) Perform actions in the docked tools to verify they still work as expected.
  37. 2.1) Select the Entity Outliner in the floating window.
  38. 2.2) Select an Entity in the Entity Outliner.
  39. 2.3) Select the Entity Inspector in the floating window.
  40. 2.4) Change the name of the selected Entity via the Entity Inspector.
  41. 2.5) Select the Console inside the floating window.
  42. 2.6) Send a console command.
  43. 2.7) Check the Editor to verify all changes were made.
  44. :return: None
  45. """
  46. from PySide2 import QtWidgets, QtTest, QtCore
  47. import azlmbr.legacy.general as general
  48. import azlmbr.bus as bus
  49. import azlmbr.editor as editor
  50. import azlmbr.entity as entity
  51. import editor_python_test_tools.hydra_editor_utils as hydra
  52. from editor_python_test_tools.utils import Report
  53. # Open an existing simple level
  54. hydra.open_base_level()
  55. # Make sure the Entity Outliner, Entity Inspector and Console tools are open
  56. general.open_pane("Entity Outliner (PREVIEW)")
  57. general.open_pane("Inspector")
  58. general.open_pane("Console")
  59. # Create an Entity to test with
  60. entity_original_name = 'MyTestEntity'
  61. entity_id = editor.ToolsApplicationRequestBus(bus.Broadcast, 'CreateNewEntity', entity.EntityId())
  62. editor.EditorEntityAPIBus(bus.Event, 'SetName', entity_id, entity_original_name)
  63. editor_window = pyside_utils.get_editor_main_window()
  64. entity_outliner = editor_window.findChild(QtWidgets.QDockWidget, "Entity Outliner")
  65. # 1) Open the tools and dock them together in a floating tabbed widget.
  66. # We drag/drop it over the viewport since it doesn't allow docking, so this will undock it
  67. render_overlay = editor_window.findChild(QtWidgets.QWidget, "renderOverlay")
  68. pyside_utils.drag_and_drop(entity_outliner, render_overlay)
  69. # We need to grab a new reference to the Entity Outliner QDockWidget because when it gets moved
  70. # to the floating window, its parent changes so the wrapped instance we had becomes invalid
  71. entity_outliner = editor_window.findChild(QtWidgets.QDockWidget, "Entity Outliner")
  72. # Dock the Entity Inspector tabbed with the floating Entity Outliner
  73. entity_inspector = editor_window.findChild(QtWidgets.QDockWidget, "Inspector")
  74. pyside_utils.drag_and_drop(entity_inspector, entity_outliner)
  75. # We need to grab a new reference to the Entity Inspector QDockWidget because when it gets moved
  76. # to the floating window, its parent changes so the wrapped instance we had becomes invalid
  77. entity_inspector = editor_window.findChild(QtWidgets.QDockWidget, "Inspector")
  78. # Dock the Console tabbed with the floating Entity Inspector
  79. console = editor_window.findChild(QtWidgets.QDockWidget, "Console")
  80. pyside_utils.drag_and_drop(console, entity_inspector)
  81. # Check to ensure all the tools are parented to the same QStackedWidget
  82. def check_all_panes_tabbed():
  83. entity_inspector = editor_window.findChild(QtWidgets.QDockWidget, "Inspector")
  84. entity_outliner = editor_window.findChild(QtWidgets.QDockWidget, "Entity Outliner")
  85. console = editor_window.findChild(QtWidgets.QDockWidget, "Console")
  86. entity_inspector_parent = entity_inspector.parentWidget()
  87. entity_outliner_parent = entity_outliner.parentWidget()
  88. console_parent = console.parentWidget()
  89. Report.info(f"Entity Inspector parent = {entity_inspector_parent}, Entity Outliner parent = "
  90. f"{entity_outliner_parent}, Console parent = {console_parent}")
  91. return isinstance(entity_inspector_parent, QtWidgets.QStackedWidget) and \
  92. (entity_inspector_parent == entity_outliner_parent) and \
  93. (entity_outliner_parent == console_parent)
  94. success = await pyside_utils.wait_for_condition(lambda: check_all_panes_tabbed, timeout=5.0)
  95. Report.result(Tests.all_tools_docked, success)
  96. # 2.1,2) Select an Entity in the Entity Outliner.
  97. entity_inspector = editor_window.findChild(QtWidgets.QDockWidget, "Inspector")
  98. entity_outliner = editor_window.findChild(QtWidgets.QDockWidget, "Entity Outliner")
  99. console = editor_window.findChild(QtWidgets.QDockWidget, "Console")
  100. object_tree = entity_outliner.findChild(QtWidgets.QTreeView, "m_objectTree")
  101. test_entity_index = pyside_utils.find_child_by_pattern(object_tree, entity_original_name)
  102. object_tree.clearSelection()
  103. object_tree.setCurrentIndex(test_entity_index)
  104. Report.result(Tests.docked_outliner_works, object_tree.currentIndex() == test_entity_index)
  105. # 2.3,4) Change the name of the selected Entity via the Entity Inspector.
  106. entity_inspector_name_field = entity_inspector.findChild(QtWidgets.QLineEdit, "m_entityNameEditor")
  107. expected_new_name = "DifferentName"
  108. entity_inspector_name_field.setText(expected_new_name)
  109. QtTest.QTest.keyClick(entity_inspector_name_field, QtCore.Qt.Key_Enter)
  110. entity_new_name = editor.EditorEntityInfoRequestBus(bus.Event, "GetName", entity_id)
  111. Report.result(Tests.docked_inspector_works, entity_new_name == expected_new_name)
  112. # 2.5,6) Send a console command.
  113. console_line_edit = console.findChild(QtWidgets.QLineEdit, "lineEdit")
  114. console_line_edit.setText("t_simulationTickScale 2")
  115. QtTest.QTest.keyClick(console_line_edit, QtCore.Qt.Key_Enter)
  116. general.get_cvar("t_simulationTickScale")
  117. Report.result(Tests.docked_console_works, general.get_cvar("t_simulationTickScale") == "2")
  118. # Reset the altered cvar
  119. console_line_edit.setText("t_simulationTickScale 1")
  120. QtTest.QTest.keyClick(console_line_edit, QtCore.Qt.Key_Enter)
  121. run_test()
  122. if __name__ == "__main__":
  123. from editor_python_test_tools.utils import Report
  124. Report.start_test(Docking_BasicDockedTools)