Explorar o código

Add try/catch block to handle situations when the editor is not involved (#17707)

Signed-off-by: Steve Pham <[email protected]>
Steve Pham hai 1 ano
pai
achega
7f7c925b15
Modificáronse 1 ficheiros con 11 adicións e 6 borrados
  1. 11 6
      Templates/PythonToolGem/Template/Editor/Scripts/bootstrap.py

+ 11 - 6
Templates/PythonToolGem/Template/Editor/Scripts/bootstrap.py

@@ -9,14 +9,19 @@ SPDX-License-Identifier: Apache-2.0 OR MIT
 Generated from O3DE PythonToolGem Template"""
 
 import az_qt_helpers
-import azlmbr.editor as editor
 from ${SanitizedNameLower}_dialog import ${SanitizedCppName}Dialog
 
 if __name__ == "__main__":
     print("${SanitizedCppName}.boostrap, Generated from O3DE PythonToolGem Template")
 
-    # Register our custom widget as a dockable tool with the Editor under an Examples sub-menu
-    options = editor.ViewPaneOptions()
-    options.showOnToolsToolbar = True
-    options.toolbarIcon = ":/${Name}/toolbar_icon.svg"
-    az_qt_helpers.register_view_pane('${SanitizedCppName}', ${SanitizedCppName}Dialog, category="Examples", options=options)
+    try:
+        import azlmbr.editor as editor
+        # Register our custom widget as a dockable tool with the Editor under an Examples sub-menu
+        options = editor.ViewPaneOptions()
+        options.showOnToolsToolbar = True
+        options.toolbarIcon = ":/${Name}/toolbar_icon.svg"
+        az_qt_helpers.register_view_pane('${SanitizedCppName}', ${SanitizedCppName}Dialog, category="Examples", options=options)
+    except:
+        # If the editor is not available (in the cases where this gem is activated outside of the Editor), then just 
+        # report it and continue.
+        print(f'Skipping registering view pane ${SanitizedCppName}, Editor is not available.')