Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Tools: Parenting of tools in Nuke and Hiero #2266

Merged
merged 4 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions openpype/hosts/hiero/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
self._has_been_setup = False
self._has_menu = False
self._registered_gui = None
self._parent = None
self.pype_tag_name = "openpypeData"
self.default_sequence_name = "openpypeSequence"
self.default_bin_name = "openpypeBin"
Expand Down Expand Up @@ -1029,3 +1030,15 @@ def before_project_save(event):

# also mark old versions of loaded containers
check_inventory_versions()


def get_main_window():
"""Acquire Nuke's main window"""
if self._parent is None:
top_widgets = QtWidgets.QApplication.topLevelWidgets()
name = "Foundry::UI::DockMainWindow"
main_window = next(widget for widget in top_widgets if
widget.inherits("QMainWindow") and
widget.metaObject().className() == name)
self._parent = main_window
return self._parent
18 changes: 14 additions & 4 deletions openpype/hosts/hiero/api/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@ def menu_install():
Installing menu into Hiero

"""
from Qt import QtGui
from . import (
publish, launch_workfiles_app, reload_config,
apply_colorspace_project, apply_colorspace_clips
)
from .lib import get_main_window

main_window = get_main_window()

# here is the best place to add menu
from avalon.vendor.Qt import QtGui

menu_name = os.environ['AVALON_LABEL']

Expand Down Expand Up @@ -86,15 +90,21 @@ def menu_install():

creator_action = menu.addAction("Create ...")
creator_action.setIcon(QtGui.QIcon("icons:CopyRectangle.png"))
creator_action.triggered.connect(host_tools.show_creator)
creator_action.triggered.connect(
lambda: host_tools.show_creator(parent=main_window)
)

loader_action = menu.addAction("Load ...")
loader_action.setIcon(QtGui.QIcon("icons:CopyRectangle.png"))
loader_action.triggered.connect(host_tools.show_loader)
loader_action.triggered.connect(
lambda: host_tools.show_loader(parent=main_window)
)

sceneinventory_action = menu.addAction("Manage ...")
sceneinventory_action.setIcon(QtGui.QIcon("icons:CopyRectangle.png"))
sceneinventory_action.triggered.connect(host_tools.show_scene_inventory)
sceneinventory_action.triggered.connect(
lambda: host_tools.show_scene_inventory(parent=main_window)
)
menu.addSeparator()

if os.getenv("OPENPYPE_DEVELOP"):
Expand Down
4 changes: 3 additions & 1 deletion openpype/hosts/hiero/api/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,11 @@ def update_container(track_item, data=None):

def launch_workfiles_app(*args):
''' Wrapping function for workfiles launcher '''
from .lib import get_main_window

main_window = get_main_window()
# show workfile gui
host_tools.show_workfiles()
host_tools.show_workfiles(parent=main_window)


def publish(parent):
Expand Down
5 changes: 4 additions & 1 deletion openpype/hosts/nuke/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1654,6 +1654,8 @@ def launch_workfiles_app():
from openpype.lib import (
env_value_to_bool
)
from avalon.nuke.pipeline import get_main_window

# get all imortant settings
open_at_start = env_value_to_bool(
env_key="OPENPYPE_WORKFILE_TOOL_ON_START",
Expand All @@ -1665,7 +1667,8 @@ def launch_workfiles_app():

if not opnl.workfiles_launched:
opnl.workfiles_launched = True
host_tools.show_workfiles()
main_window = get_main_window()
host_tools.show_workfiles(parent=main_window)


def process_workfile_builder():
Expand Down
8 changes: 6 additions & 2 deletions openpype/hosts/nuke/api/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
from openpype.api import Logger, BuildWorkfile, get_current_project_settings
from openpype.tools.utils import host_tools

from avalon.nuke.pipeline import get_main_window

log = Logger().get_logger(__name__)

menu_label = os.environ["AVALON_LABEL"]


def install():
main_window = get_main_window()
menubar = nuke.menu("Nuke")
menu = menubar.findItem(menu_label)

Expand All @@ -25,7 +29,7 @@ def install():
menu.removeItem(rm_item[1].name())
menu.addCommand(
name,
host_tools.show_workfiles,
lambda: host_tools.show_workfiles(parent=main_window),
index=2
)
menu.addSeparator(index=3)
Expand Down Expand Up @@ -88,7 +92,7 @@ def install():
menu.addSeparator()
menu.addCommand(
"Experimental tools...",
host_tools.show_experimental_tools_dialog
lambda: host_tools.show_experimental_tools_dialog(parent=main_window)
)

# adding shortcuts
Expand Down