From 143148fca0c94954115e1d08ea64bfa078dd6655 Mon Sep 17 00:00:00 2001 From: Toke Stuart Jepsen Date: Mon, 8 Apr 2024 13:51:09 +0100 Subject: [PATCH] Show app in main window. --- openpype/hosts/nuke/api/push_to_project.py | 27 ++++--------- openpype/tools/push_to_project/app.py | 44 +++++++++------------- openpype/tools/push_to_project/window.py | 3 +- 3 files changed, 28 insertions(+), 46 deletions(-) diff --git a/openpype/hosts/nuke/api/push_to_project.py b/openpype/hosts/nuke/api/push_to_project.py index a0d54b91a55..644a7f1973b 100644 --- a/openpype/hosts/nuke/api/push_to_project.py +++ b/openpype/hosts/nuke/api/push_to_project.py @@ -11,6 +11,8 @@ from openpype.pipeline.workfile import get_workdir_with_workdir_data from openpype import PACKAGE_DIR from openpype.lib import get_openpype_execute_args, run_subprocess +from openpype.tools.push_to_project.app import show + from .utils import bake_gizmos_recursively import nuke @@ -47,29 +49,16 @@ def bake_container(container): def main(): - # Get project name, asset id and task name. - push_tool_script_path = os.path.join( - PACKAGE_DIR, - "tools", - "push_to_project", - "app.py" - ) + context = show("", "", False, True) - args = get_openpype_execute_args( - "run", - push_tool_script_path, - "--library_filter", "False", - "--context_only", "True" - ) - output = run_subprocess(args) - dict_string = re.search(r'\{.*\}', output).group() - result = json.loads(dict_string) + if context is None: + return # Get workfile path to save to. - project_name = result["project_name"] + project_name = context["project_name"] project_doc = get_project(project_name) - asset_doc = get_asset_by_id(project_name, result["asset_id"]) - task_name = result["task_name"] + asset_doc = get_asset_by_id(project_name, context["asset_id"]) + task_name = context["task_name"] host = registered_host() system_settings = get_system_settings() project_settings = get_project_settings(project_name) diff --git a/openpype/tools/push_to_project/app.py b/openpype/tools/push_to_project/app.py index 3bac2956360..048cab5b1d1 100644 --- a/openpype/tools/push_to_project/app.py +++ b/openpype/tools/push_to_project/app.py @@ -1,17 +1,29 @@ -import json - import click from openpype.tools.utils import get_openpype_qt_app from openpype.tools.push_to_project.window import PushToContextSelectWindow +def show(project, version, library_filter, context_only): + window = PushToContextSelectWindow( + library_filter=library_filter, context_only=context_only + ) + window.show() + window.controller.set_source(project, version) + + if __name__ == "__main__": + app = get_openpype_qt_app() + app.exec_() + else: + window.exec_() + + return window.context + + @click.command() @click.option("--project", help="Source project name") @click.option("--version", help="Source version id") -@click.option("--library_filter", help="Filter to library projects only.") -@click.option("--context_only", help="Return new context only.") -def main(project, version, library_filter, context_only): +def main(project, version): """Run PushToProject tool to integrate version in different project. Args: @@ -19,27 +31,7 @@ def main(project, version, library_filter, context_only): version (str): Version id. version (bool): Filter to library projects only. """ - app = get_openpype_qt_app() - - if library_filter is None: - library_filter = True - else: - library_filter = library_filter == "True" - - if context_only is None: - context_only = True - else: - context_only = context_only == "True" - - window = PushToContextSelectWindow( - library_filter=library_filter, context_only=context_only - ) - window.show() - window.controller.set_source(project, version) - - app.exec_() - - print(json.dumps(window.context)) + show(project, version, True, False) if __name__ == "__main__": diff --git a/openpype/tools/push_to_project/window.py b/openpype/tools/push_to_project/window.py index bcc5a8dcb95..540614f10e1 100644 --- a/openpype/tools/push_to_project/window.py +++ b/openpype/tools/push_to_project/window.py @@ -367,7 +367,7 @@ def _refresh(self, new_project_name): self.items_changed.emit() -class PushToContextSelectWindow(QtWidgets.QWidget): +class PushToContextSelectWindow(QtWidgets.QDialog): def __init__( self, controller=None, library_filter=True, context_only=False ): @@ -376,6 +376,7 @@ def __init__( controller = PushToContextController(library_filter=library_filter) self._controller = controller self.context_only = context_only + self.context = None self.setWindowTitle("Push to project (select context)") self.setWindowIcon(QtGui.QIcon(get_app_icon_path()))