From 49687febcb7cc5072b4203f4ba6f7ecd85d95954 Mon Sep 17 00:00:00 2001 From: David Lai Date: Wed, 6 Nov 2019 19:17:47 +0800 Subject: [PATCH] Add `maya.pipeline.get_main_window` Remove duplicated main window getting code --- avalon/maya/pipeline.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/avalon/maya/pipeline.py b/avalon/maya/pipeline.py index 0266cdb67..f1191b996 100644 --- a/avalon/maya/pipeline.py +++ b/avalon/maya/pipeline.py @@ -94,6 +94,16 @@ def find_host_config(config): return config +def get_main_window(): + """Acquire Maya's main window""" + if self._parent is None: + self._parent = { + widget.objectName(): widget + for widget in QtWidgets.QApplication.topLevelWidgets() + }["MayaWindow"] + return self._parent + + def uninstall(config): """Uninstall Maya-specific functionality of avalon-core. @@ -250,10 +260,7 @@ def reload_pipeline(*args): module = importlib.import_module(module) reload(module) - self._parent = { - widget.objectName(): widget - for widget in QtWidgets.QApplication.topLevelWidgets() - }["MayaWindow"] + get_main_window() import avalon.maya api.install(avalon.maya) @@ -625,10 +632,7 @@ def _on_maya_initialized(*args): return # Keep reference to the main Window, once a main window exists. - self._parent = { - widget.objectName(): widget - for widget in QtWidgets.QApplication.topLevelWidgets() - }["MayaWindow"] + get_main_window() def _on_scene_new(*args):