Files
o3de/Templates/PythonGem/Template/Editor/Scripts/bootstrap.py
T
Jonny Galloway d7045f4c31 Scaffold PythonGem template (#4888)
* Renamed ctest_pytest.ini to pytest.ini so it is used by default, added TestSuite_ as collection file (#4822)

* Fixed warnings of unused marks, renamed ctest_pytest.ini to pytest.ini to better consistency on runs

* Fixed some test suites to run propertly

* Fix missing arguments

* Fixed missing cmakelists and renamed missing file

* Temp disable editor_testing_tests as timeout in jenkins

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* scaffold PythonGem template

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* CustomTool was not added to CMakeLists

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* Update Templates/PythonGem/Template/Code/CMakeLists.txt

makes sense thank you for the help

Co-authored-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* Update Templates/PythonGem/Template/Code/CMakeLists.txt

Co-authored-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* Delete  ${NameLower}_tests_files.cmake

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* suggested changes made

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* cleanup not needed files

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* fix up template.json

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* made a correction

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* made a correction

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* fixes

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* fixes

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* more fixes, fixed a file name

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* Added helper method to az_qt_helpers for retrieving the main window instance.

Signed-off-by: Chris Galvan <chgalvan@amazon.com>

* additional fixes

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* Fix for AP trowing errors at boot (can not get mainwindow)

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* Added missing EBus connect/disconnect calls in the EditorSystemComponent


Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* additional fix up

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* adding dialog internals

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

Co-authored-by: AMZN-AlexOteiza <82234181+AMZN-AlexOteiza@users.noreply.github.com>
Co-authored-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
Co-authored-by: Chris Galvan <chgalvan@amazon.com>
2021-10-25 18:18:27 -05:00

117 lines
4.8 KiB
Python

"""
Copyright (c) Contributors to the Open 3D Engine Project.
For complete copyright and license terms please see the LICENSE at the root of this distribution.
SPDX-License-Identifier: Apache-2.0 OR MIT
"""
# -------------------------------------------------------------------------
"""${SanitizedCppName}\\editor\\scripts\\boostrap.py
Generated from O3DE PythonGem Template"""
import azlmbr
import az_qt_helpers
from PySide2 import QtCore, QtWidgets, QtGui
from PySide2.QtCore import QEvent, Qt
from PySide2.QtWidgets import QMainWindow, QAction, QDialog, QHeaderView, QLabel, QLineEdit, QPushButton, QSplitter, QTreeWidget, QTreeWidgetItem, QWidget, QAbstractButton
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
class SampleUI(QtWidgets.QDialog):
"""Lightweight UI Test Class created a button"""
def __init__(self, parent, title='Not Set'):
super(SampleUI, self).__init__(parent)
self.setWindowTitle(title)
self.initUI()
def initUI(self):
mainLayout = QtWidgets.QHBoxLayout()
testBtn = QtWidgets.QPushButton("I am just a Button man!")
mainLayout.addWidget(testBtn)
self.setLayout(mainLayout)
# -------------------------------------------------------------------------
if __name__ == "__main__":
print("${SanitizedCppName}.boostrap, Generated from O3DE PythonGem Template")
# ---------------------------------------------------------------------
# validate pyside before continuing
try:
azlmbr.qt.QtForPythonRequestBus(azlmbr.bus.Broadcast, 'IsActive')
params = azlmbr.qt.QtForPythonRequestBus(azlmbr.bus.Broadcast, 'GetQtBootstrapParameters')
params is not None and params.mainWindowId is not 0
from PySide2 import QtWidgets
except Exception as e:
_LOGGER.error(f'Pyside not available, exception: {e}')
raise e
# keep going, import the other PySide2 bits we will use
from PySide2 import QtGui
from PySide2.QtCore import Slot
from shiboken2 import wrapInstance, getCppPointer
# Get our Editor main window
_widget_main_window = None
try:
_widget_main_window = az_qt_helpers.get_editor_main_window()
except:
pass # may be booting in the AP?
# ---------------------------------------------------------------------
# ---------------------------------------------------------------------
if _widget_main_window:
# creat a custom menu
_tag_str = '${SanitizedCppName}'
# create our own menuBar
${SanitizedCppName}_menu = _widget_main_window.menuBar().addMenu(f"&{_tag_str}")
# nest a menu for util/tool launching
${SanitizedCppName}_launch_menu = ${SanitizedCppName}_menu.addMenu("examples")
else:
print('No O3DE MainWindow')
# ---------------------------------------------------------------------
# ---------------------------------------------------------------------
if _widget_main_window:
# (1) add the first SampleUI
action_launch_sample_ui = ${SanitizedCppName}_launch_menu.addAction("O3DE:SampleUI")
@Slot()
def clicked_sample_ui():
while 1: # simple PySide2 test, set to 0 to disable
ui = SampleUI(parent=_widget_main_window, title='O3DE:SampleUI')
ui.show()
break
return
# Add click event to menu bar
action_launch_sample_ui.triggered.connect(clicked_sample_ui)
# ---------------------------------------------------------------------
# ---------------------------------------------------------------------
if _widget_main_window:
# (1) and custom external module Qwidget
action_launch_${SanitizedCppName}_dialog = ${SanitizedCppName}_launch_menu.addAction("O3DE:${SanitizedCppName}_dialog")
@Slot()
def clicked_${SanitizedCppName}_dialog():
while 1: # simple PySide2 test, set to 0 to disable
try:
import az_qt_helpers
from ${NameLower}_dialog import ${SanitizedCppName}Dialog
az_qt_helpers.register_view_pane('${SanitizedCppName} Popup', ${SanitizedCppName}Dialog)
except Exception as e:
print(f'Error: {e}')
print('Skipping register our ${SanitizedCppName}Dialog with the Editor.')
${SanitizedCppName}_dialog = ${SanitizedCppName}Dialog(parent=_widget_main_window)
${SanitizedCppName}_dialog.show()
break
return
# Add click event to menu bar
action_launch_${SanitizedCppName}_dialog.triggered.connect(clicked_${SanitizedCppName}_dialog)
# ---------------------------------------------------------------------
# end