From 7e6af882bd42a24cd8b438f7d091a4e2c2c080fe Mon Sep 17 00:00:00 2001 From: MustafaJafar Date: Fri, 21 Jun 2024 22:13:06 +0300 Subject: [PATCH 1/4] support_opening_workfile_on_launching_houdini --- .../houdini/client/ayon_houdini/api/lib.py | 50 ++++++++++++++++++- .../client/ayon_houdini/api/pipeline.py | 5 +- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/server_addon/houdini/client/ayon_houdini/api/lib.py b/server_addon/houdini/client/ayon_houdini/api/lib.py index 671265fae9..eefe895b8f 100644 --- a/server_addon/houdini/client/ayon_houdini/api/lib.py +++ b/server_addon/houdini/client/ayon_houdini/api/lib.py @@ -8,6 +8,7 @@ import json from contextlib import contextmanager import six +from qtpy import QtCore, QtWidgets import ayon_api from ayon_core.lib import StringTemplate @@ -23,7 +24,11 @@ from ayon_core.pipeline import ( from ayon_core.pipeline.create import CreateContext from ayon_core.pipeline.template_data import get_template_data from ayon_core.pipeline.context_tools import get_current_folder_entity -from ayon_core.tools.utils import PopupUpdateKeys, SimplePopup +from ayon_core.tools.utils import ( + PopupUpdateKeys, + SimplePopup, + host_tools +) from ayon_core.tools.utils.host_tools import get_tool_by_name import hou @@ -1193,3 +1198,46 @@ def prompt_reset_context(): update_content_on_context_change() dialog.deleteLater() + + +def wait_startup_launch_workfiles_app(): + """Show workfiles tool on Houdini launch. + + Trigger to show workfiles tool on application launch. Can be executed only + once all other calls are ignored. + + Workfiles tool show is deferred after application initialization using + QTimer. + + Basically, it should wait till the app finish starting up. + """ + + # Show workfiles tool using timer + # - this will be probably triggered during initialization in that case + # the application is not be able to show uis so it must be + # deferred using timer + # - timer should be processed when initialization ends + # When applications starts to process events. + timer = QtCore.QTimer() + timer.timeout.connect(lambda: _launch_workfile_app(timer)) + timer.setInterval(100) + timer.start() + + +def _launch_workfile_app(timer): + # Safeguard to not show window when application is still starting up + # or is already closing down. + closing_down = QtWidgets.QApplication.closingDown() + starting_up = QtWidgets.QApplication.startingUp() + + # Stop the timer if application finished start up of is closing down + if closing_down or not starting_up: + timer.stop() + + # Skip if application is starting up or closing down + if starting_up or closing_down: + return + + # Make sure on top is enabled on first show so the window is not hidden + # under main nuke window + host_tools.show_workfiles(parent=hou.qt.mainWindow(), on_top=True) diff --git a/server_addon/houdini/client/ayon_houdini/api/pipeline.py b/server_addon/houdini/client/ayon_houdini/api/pipeline.py index 6af4993d25..9d420a92d3 100644 --- a/server_addon/houdini/client/ayon_houdini/api/pipeline.py +++ b/server_addon/houdini/client/ayon_houdini/api/pipeline.py @@ -85,10 +85,9 @@ class HoudiniHost(HostBase, IWorkfileHost, ILoadHost, IPublishHost): # initialization during start up delays Houdini UI by minutes # making it extremely slow to launch. hdefereval.executeDeferred(shelves.generate_shelves) - - if not IS_HEADLESS: - import hdefereval # noqa, hdefereval is only available in ui mode hdefereval.executeDeferred(creator_node_shelves.install) + if os.environ.get("AYON_WORKFILE_TOOL_ON_START"): + hdefereval.executeDeferred(lib.wait_startup_launch_workfiles_app) def workfile_has_unsaved_changes(self): return hou.hipFile.hasUnsavedChanges() From e6bb56b088ba001859ff02b61d577638f8d61ce1 Mon Sep 17 00:00:00 2001 From: MustafaJafar Date: Fri, 21 Jun 2024 22:56:53 +0300 Subject: [PATCH 2/4] refactor launching the workfile - remove redundant code --- .../houdini/client/ayon_houdini/api/lib.py | 50 +------------------ .../client/ayon_houdini/api/pipeline.py | 11 +++- 2 files changed, 10 insertions(+), 51 deletions(-) diff --git a/server_addon/houdini/client/ayon_houdini/api/lib.py b/server_addon/houdini/client/ayon_houdini/api/lib.py index eefe895b8f..671265fae9 100644 --- a/server_addon/houdini/client/ayon_houdini/api/lib.py +++ b/server_addon/houdini/client/ayon_houdini/api/lib.py @@ -8,7 +8,6 @@ import json from contextlib import contextmanager import six -from qtpy import QtCore, QtWidgets import ayon_api from ayon_core.lib import StringTemplate @@ -24,11 +23,7 @@ from ayon_core.pipeline import ( from ayon_core.pipeline.create import CreateContext from ayon_core.pipeline.template_data import get_template_data from ayon_core.pipeline.context_tools import get_current_folder_entity -from ayon_core.tools.utils import ( - PopupUpdateKeys, - SimplePopup, - host_tools -) +from ayon_core.tools.utils import PopupUpdateKeys, SimplePopup from ayon_core.tools.utils.host_tools import get_tool_by_name import hou @@ -1198,46 +1193,3 @@ def prompt_reset_context(): update_content_on_context_change() dialog.deleteLater() - - -def wait_startup_launch_workfiles_app(): - """Show workfiles tool on Houdini launch. - - Trigger to show workfiles tool on application launch. Can be executed only - once all other calls are ignored. - - Workfiles tool show is deferred after application initialization using - QTimer. - - Basically, it should wait till the app finish starting up. - """ - - # Show workfiles tool using timer - # - this will be probably triggered during initialization in that case - # the application is not be able to show uis so it must be - # deferred using timer - # - timer should be processed when initialization ends - # When applications starts to process events. - timer = QtCore.QTimer() - timer.timeout.connect(lambda: _launch_workfile_app(timer)) - timer.setInterval(100) - timer.start() - - -def _launch_workfile_app(timer): - # Safeguard to not show window when application is still starting up - # or is already closing down. - closing_down = QtWidgets.QApplication.closingDown() - starting_up = QtWidgets.QApplication.startingUp() - - # Stop the timer if application finished start up of is closing down - if closing_down or not starting_up: - timer.stop() - - # Skip if application is starting up or closing down - if starting_up or closing_down: - return - - # Make sure on top is enabled on first show so the window is not hidden - # under main nuke window - host_tools.show_workfiles(parent=hou.qt.mainWindow(), on_top=True) diff --git a/server_addon/houdini/client/ayon_houdini/api/pipeline.py b/server_addon/houdini/client/ayon_houdini/api/pipeline.py index 9d420a92d3..2c28e33929 100644 --- a/server_addon/houdini/client/ayon_houdini/api/pipeline.py +++ b/server_addon/houdini/client/ayon_houdini/api/pipeline.py @@ -6,7 +6,7 @@ import logging import hou # noqa from ayon_core.host import HostBase, IWorkfileHost, ILoadHost, IPublishHost - +from ayon_core.tools.utils import host_tools import pyblish.api from ayon_core.pipeline import ( @@ -25,6 +25,13 @@ from ayon_core.lib import ( emit_event, ) +def show_workfiles_tool(): + # Make sure on top is enabled on first show so the + # window is not hidden under main nuke window + print("showing workfiles tool..") + from ayon_core.tools.utils import host_tools + host_tools.show_workfiles(parent=hou.qt.mainWindow(), + on_top=True) log = logging.getLogger("ayon_houdini") @@ -87,7 +94,7 @@ class HoudiniHost(HostBase, IWorkfileHost, ILoadHost, IPublishHost): hdefereval.executeDeferred(shelves.generate_shelves) hdefereval.executeDeferred(creator_node_shelves.install) if os.environ.get("AYON_WORKFILE_TOOL_ON_START"): - hdefereval.executeDeferred(lib.wait_startup_launch_workfiles_app) + hdefereval.executeDeferred(lambda: host_tools.show_workfiles(parent=hou.qt.mainWindow())) def workfile_has_unsaved_changes(self): return hou.hipFile.hasUnsavedChanges() From d88c36b01ec50a706bb544f09574dadc963e762e Mon Sep 17 00:00:00 2001 From: Mustafa Taher Date: Fri, 21 Jun 2024 23:05:34 +0300 Subject: [PATCH 3/4] remove redundant code Co-authored-by: Roy Nieterau --- server_addon/houdini/client/ayon_houdini/api/pipeline.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/server_addon/houdini/client/ayon_houdini/api/pipeline.py b/server_addon/houdini/client/ayon_houdini/api/pipeline.py index 2c28e33929..463191f787 100644 --- a/server_addon/houdini/client/ayon_houdini/api/pipeline.py +++ b/server_addon/houdini/client/ayon_houdini/api/pipeline.py @@ -25,13 +25,6 @@ from ayon_core.lib import ( emit_event, ) -def show_workfiles_tool(): - # Make sure on top is enabled on first show so the - # window is not hidden under main nuke window - print("showing workfiles tool..") - from ayon_core.tools.utils import host_tools - host_tools.show_workfiles(parent=hou.qt.mainWindow(), - on_top=True) log = logging.getLogger("ayon_houdini") From 583bc8f86b596ed0e6fc27b97e46b20d5b9929b5 Mon Sep 17 00:00:00 2001 From: MustafaJafar Date: Fri, 21 Jun 2024 23:07:52 +0300 Subject: [PATCH 4/4] use env_value_to_bool instead of os.environ.get --- server_addon/houdini/client/ayon_houdini/api/pipeline.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server_addon/houdini/client/ayon_houdini/api/pipeline.py b/server_addon/houdini/client/ayon_houdini/api/pipeline.py index 463191f787..22a15605c7 100644 --- a/server_addon/houdini/client/ayon_houdini/api/pipeline.py +++ b/server_addon/houdini/client/ayon_houdini/api/pipeline.py @@ -23,6 +23,7 @@ from ayon_houdini.api import lib, shelves, creator_node_shelves from ayon_core.lib import ( register_event_callback, emit_event, + env_value_to_bool, ) @@ -86,7 +87,7 @@ class HoudiniHost(HostBase, IWorkfileHost, ILoadHost, IPublishHost): # making it extremely slow to launch. hdefereval.executeDeferred(shelves.generate_shelves) hdefereval.executeDeferred(creator_node_shelves.install) - if os.environ.get("AYON_WORKFILE_TOOL_ON_START"): + if env_value_to_bool("AYON_WORKFILE_TOOL_ON_START"): hdefereval.executeDeferred(lambda: host_tools.show_workfiles(parent=hou.qt.mainWindow())) def workfile_has_unsaved_changes(self):