pyside_auto_menubar_test_case.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. """
  6. # Import the Editor API to test the PySide2 & Qt 5.12.x integration
  7. import azlmbr.bus
  8. import azlmbr.editor as editor
  9. import azlmbr.legacy.general as general
  10. def printOrExcept(expression, message):
  11. if(expression):
  12. print (message)
  13. return
  14. failed = 'FAILED - '.format(message)
  15. print (failed)
  16. general.exit_no_prompt()
  17. raise Exception(failed)
  18. printOrExcept(azlmbr.qt.QtForPythonRequestBus(azlmbr.bus.Broadcast, 'IsActive'), 'QtForPython Is Ready')
  19. # the PySide2 and shiboken2 libraries should import cleanly
  20. try:
  21. from shiboken2 import wrapInstance, getCppPointer
  22. from PySide2 import QtWidgets
  23. from PySide2 import QtGui
  24. except:
  25. printOrExcept(False, 'Importing PySide2 and Shiboken2')
  26. allWindows = QtGui.QGuiApplication.allWindows()
  27. printOrExcept(len(allWindows) > 0, 'Value allWindows greater than zero')
  28. azMainWidgetId = azlmbr.qt.QtForPythonRequestBus(azlmbr.bus.Broadcast, 'GetMainWindowId')
  29. printOrExcept(azMainWidgetId != 0, 'GetMainWindowId')
  30. mainWidgetWindow = QtWidgets.QWidget.find(azMainWidgetId)
  31. mainWindow = wrapInstance(int(getCppPointer(mainWidgetWindow)[0]), QtWidgets.QMainWindow)
  32. printOrExcept(mainWindow is not None, 'Get QtWidgets.QMainWindow')
  33. menuBar = mainWindow.menuBar()
  34. printOrExcept(menuBar is not None, 'Value menuBar is valid')
  35. for action in menuBar.actions():
  36. if("File" in action.text()):
  37. print('Found File action')
  38. elif("Edit" in action.text()):
  39. print('Found Edit action')
  40. elif("Game" in action.text()):
  41. print('Found Game action')
  42. elif("Tools" in action.text()):
  43. print('Found Tools action')
  44. general.exit_no_prompt()