Docking_BasicDockedTools.py 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. """
  2. All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
  3. its licensors.
  4. For complete copyright and license terms please see the LICENSE at the root of this
  5. distribution (the "License"). All use of this software is governed by the License,
  6. or, if provided, by the license below or the license accompanying this file. Do not
  7. remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. C6376081: Basic Function: Docked/Undocked Tools
  10. """
  11. import os
  12. import sys
  13. from PySide2 import QtWidgets, QtTest, QtCore
  14. import azlmbr.legacy.general as general
  15. import azlmbr.bus as bus
  16. import azlmbr.editor as editor
  17. import azlmbr.entity as entity
  18. import azlmbr.paths
  19. sys.path.append(os.path.join(azlmbr.paths.devroot, 'AutomatedTesting', 'Gem', 'PythonTests'))
  20. from automatedtesting_shared.editor_test_helper import EditorTestHelper
  21. import automatedtesting_shared.pyside_utils as pyside_utils
  22. class TestDockingBasicDockedTools(EditorTestHelper):
  23. def __init__(self):
  24. EditorTestHelper.__init__(self, log_prefix="Docking_BasicDockedTools", args=["level"])
  25. @pyside_utils.wrap_async
  26. async def run_test(self):
  27. """
  28. Summary:
  29. Test that tools still work as expected when docked together.
  30. Expected Behavior:
  31. Multiple tools can be docked together.
  32. Tools function while docked together and the main editor responds appropriately.
  33. Test Steps:
  34. 1) Open the tools and dock them together in a floating tabbed widget.
  35. 2) Perform actions in the docked tools to verify they still work as expected.
  36. 2.1) Select the Entity Outliner in the floating window.
  37. 2.2) Select an Entity in the Entity Outliner.
  38. 2.3) Select the Entity Inspector in the floating window.
  39. 2.4) Change the name of the selected Entity via the Entity Inspector.
  40. 2.5) Select the Console inside the floating window.
  41. 2.6) Send a console command.
  42. 2.7) Check the Editor to verify all changes were made.
  43. :return: None
  44. """
  45. # Create a level since we are going to be dealing with an Entity.
  46. self.create_level(
  47. self.args["level"],
  48. heightmap_resolution=1024,
  49. heightmap_meters_per_pixel=1,
  50. terrain_texture_resolution=4096,
  51. use_terrain=False,
  52. )
  53. # Make sure the Entity Outliner, Entity Inspector and Console tools are open
  54. general.open_pane("Entity Outliner (PREVIEW)")
  55. general.open_pane("Entity Inspector")
  56. general.open_pane("Console")
  57. # Create an Entity to test with
  58. entity_original_name = 'MyTestEntity'
  59. entity_id = editor.ToolsApplicationRequestBus(bus.Broadcast, 'CreateNewEntity', entity.EntityId())
  60. editor.EditorEntityAPIBus(bus.Event, 'SetName', entity_id, entity_original_name)
  61. editor_window = pyside_utils.get_editor_main_window()
  62. entity_outliner = editor_window.findChild(QtWidgets.QDockWidget, "Entity Outliner (PREVIEW)")
  63. # 1) Open the tools and dock them together in a floating tabbed widget.
  64. # We drag/drop it over the viewport since it doesn't allow docking, so this will undock it
  65. render_overlay = editor_window.findChild(QtWidgets.QWidget, "renderOverlay")
  66. pyside_utils.drag_and_drop(entity_outliner, render_overlay)
  67. # We need to grab a new reference to the Entity Outliner QDockWidget because when it gets moved
  68. # to the floating window, its parent changes so the wrapped intance we had becomes invalid
  69. entity_outliner = editor_window.findChild(QtWidgets.QDockWidget, "Entity Outliner (PREVIEW)")
  70. # Dock the Entity Inspector tabbed with the floating Entity Outliner
  71. entity_inspector = editor_window.findChild(QtWidgets.QDockWidget, "Entity Inspector")
  72. pyside_utils.drag_and_drop(entity_inspector, entity_outliner)
  73. # We need to grab a new reference to the Entity Inspector QDockWidget because when it gets moved
  74. # to the floating window, its parent changes so the wrapped intance we had becomes invalid
  75. entity_inspector = editor_window.findChild(QtWidgets.QDockWidget, "Entity Inspector")
  76. # Dock the Console tabbed with the floating Entity Inspector
  77. console = editor_window.findChild(QtWidgets.QDockWidget, "Console")
  78. pyside_utils.drag_and_drop(console, entity_inspector)
  79. # Check to ensure all the tools are parented to the same QStackedWidget
  80. def check_all_panes_tabbed():
  81. entity_inspector = editor_window.findChild(QtWidgets.QDockWidget, "Entity Inspector")
  82. entity_outliner = editor_window.findChild(QtWidgets.QDockWidget, "Entity Outliner (PREVIEW)")
  83. console = editor_window.findChild(QtWidgets.QDockWidget, "Console")
  84. entity_inspector_parent = entity_inspector.parentWidget()
  85. entity_outliner_parent = entity_outliner.parentWidget()
  86. console_parent = console.parentWidget()
  87. print(f"Entity Inspector parent = {entity_inspector_parent}, Entity Outliner parent = {entity_outliner_parent}, Console parent = {console_parent}")
  88. return isinstance(entity_inspector_parent, QtWidgets.QStackedWidget) and (entity_inspector_parent == entity_outliner_parent) and (entity_outliner_parent == console_parent)
  89. success = await pyside_utils.wait_for(check_all_panes_tabbed, timeout=3.0)
  90. if success:
  91. print("The tools are all docked together in a tabbed widget")
  92. # 2.1,2) Select an Entity in the Entity Outliner.
  93. entity_inspector = editor_window.findChild(QtWidgets.QDockWidget, "Entity Inspector")
  94. entity_outliner = editor_window.findChild(QtWidgets.QDockWidget, "Entity Outliner (PREVIEW)")
  95. console = editor_window.findChild(QtWidgets.QDockWidget, "Console")
  96. object_tree = entity_outliner.findChild(QtWidgets.QTreeView, "m_objectTree")
  97. test_entity_index = pyside_utils.find_child_by_pattern(object_tree, entity_original_name)
  98. object_tree.clearSelection()
  99. object_tree.setCurrentIndex(test_entity_index)
  100. if object_tree.currentIndex():
  101. print("Entity Outliner works when docked, can select an Entity")
  102. # 2.3,4) Change the name of the selected Entity via the Entity Inspector.
  103. entity_inspector_name_field = entity_inspector.findChild(QtWidgets.QLineEdit, "m_entityNameEditor")
  104. expected_new_name = "DifferentName"
  105. entity_inspector_name_field.setText(expected_new_name)
  106. QtTest.QTest.keyClick(entity_inspector_name_field, QtCore.Qt.Key_Enter)
  107. entity_new_name = editor.EditorEntityInfoRequestBus(bus.Event, "GetName", entity_id)
  108. if entity_new_name == expected_new_name:
  109. print(f"Entity Inspector works when docked, Entity name changed to {entity_new_name}")
  110. # 2.5,6) Send a console command.
  111. console_line_edit = console.findChild(QtWidgets.QLineEdit, "lineEdit")
  112. console_line_edit.setText("Hello, world!")
  113. QtTest.QTest.keyClick(console_line_edit, QtCore.Qt.Key_Enter)
  114. test = TestDockingBasicDockedTools()
  115. test.run()