Skip to content

Commit

Permalink
Merge pull request #472 from davidlatwe/parenting-tools
Browse files Browse the repository at this point in the history
Parenting tools
  • Loading branch information
davidlatwe authored Nov 7, 2019
2 parents 54af4a6 + 49687fe commit 815aa55
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 42 deletions.
13 changes: 9 additions & 4 deletions avalon/houdini/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ def find_host_config(config):
return config


def get_main_window():
"""Acquire Houdini's main window"""
if self._parent is None:
self._parent = hou.ui.mainQtWindow()
return self._parent


def reload_pipeline(*args):
"""Attempt to reload pipeline at run-time.
Expand Down Expand Up @@ -116,7 +123,7 @@ def reload_pipeline(*args):
module = importlib.import_module(module)
reload(module)

self._parent = {hou.ui.mainQtWindow().objectName(): hou.ui.mainQtWindow()}
get_main_window()

import avalon.houdini
api.install(avalon.houdini)
Expand Down Expand Up @@ -317,9 +324,7 @@ def on_file_event_callback(event):


def on_houdini_initialize():

main_window = hou.qt.mainWindow()
self._parent = {main_window.objectName(): main_window}
get_main_window()


def _register_callbacks():
Expand Down
23 changes: 14 additions & 9 deletions avalon/maya/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -203,7 +213,8 @@ def launch_workfiles_app(*args):
os.path.join(
cmds.workspace(query=True, rootDirectory=True),
cmds.workspace(fileRuleEntry="scene")
)
),
parent=self._parent
)


Expand Down Expand Up @@ -249,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)
Expand Down Expand Up @@ -624,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):
Expand Down
40 changes: 32 additions & 8 deletions avalon/nuke/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys
import importlib
import contextlib
import logging
Expand All @@ -10,10 +11,14 @@
from . import lib
from .. import api, io
from ..vendor import toml
from ..vendor.Qt import QtWidgets
from ..pipeline import AVALON_CONTAINER_ID

log = logging.getLogger(__name__)

self = sys.modules[__name__]
self._parent = None # Main Window cache

AVALON_CONFIG = os.environ["AVALON_CONFIG"]


Expand Down Expand Up @@ -215,6 +220,18 @@ def find_host_config(config):
return config


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


def uninstall(config):
"""Uninstall all tha was installed
Expand Down Expand Up @@ -253,19 +270,26 @@ def _install_menu():
api.Session["AVALON_ASSET"], api.Session["AVALON_TASK"]
)
context_menu = menu.addMenu(label)
context_menu.addCommand("Set Context", contextmanager.show)

context_menu.addCommand("Set Context",
lambda: contextmanager.show(
parent=get_main_window())
)
menu.addSeparator()
menu.addCommand("Create...", creator.show)
menu.addCommand("Load...", loader.show)
menu.addCommand("Publish...", publish.show)
menu.addCommand("Manage...", sceneinventory.show)
menu.addCommand("Create...",
lambda: creator.show(parent=get_main_window()))
menu.addCommand("Load...",
lambda: loader.show(parent=get_main_window(),
use_context=True))
menu.addCommand("Publish...",
lambda: publish.show(parent=get_main_window()))
menu.addCommand("Manage...",
lambda: sceneinventory.show(parent=get_main_window()))

menu.addSeparator()
menu.addCommand("Work Files...",
lambda: workfiles.show(
os.environ["AVALON_WORKDIR"]
)
os.environ["AVALON_WORKDIR"],
parent=get_main_window())
)

menu.addSeparator()
Expand Down
13 changes: 13 additions & 0 deletions avalon/style/style.qss
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ QWidget
background-clip: border;
border-image: none;
outline: 0;
font-size: 12px;
}

QWidget:item:hover
Expand Down Expand Up @@ -1202,8 +1203,20 @@ QSplitter::handle:hover {

QSplitter::handle:horizontal {
width: 1px;
background-color: transparent;
}

QSplitter::handle:vertical {
height: 1px;
background-color: transparent;
}

QSplitter::handle:vertical:hover {
background-color: #787876;
border: 1px solid #3A3939;
}

QSplitter::handle:horizontal:hover {
background-color: #787876;
border: 1px solid #3A3939;
}
6 changes: 3 additions & 3 deletions avalon/tools/contextmanager/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def __init__(self, parent=None):
task_view.setIndentation(0)
task_model = TasksModel()
task_view.setModel(task_model)
task_view_selection = task_view.selectionModel()
tasks_layout.addWidget(task_view)
tasks_layout.addWidget(accept_btn)
task_view.setColumnHidden(1, True)
Expand Down Expand Up @@ -84,8 +85,7 @@ def __init__(self, parent=None):

assets.selection_changed.connect(self.on_asset_changed)
accept_btn.clicked.connect(self.on_accept_clicked)
task_view.selectionModel().selectionChanged.connect(
self.on_task_changed)
task_view_selection.selectionChanged.connect(self.on_task_changed)
assets.assets_refreshed.connect(self.on_task_changed)
assets.refresh()

Expand Down Expand Up @@ -223,7 +223,7 @@ def show(parent=None):

with lib.application():
window = App(parent)
window.setStyleSheet(style.load_stylesheet())
window.show()
window.setStyleSheet(style.load_stylesheet())

module.window = window
2 changes: 1 addition & 1 deletion avalon/tools/creator/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,8 @@ def show(debug=False, parent=None):

with lib.application():
window = Window(parent)
window.setStyleSheet(style.load_stylesheet())
window.refresh()
window.show()
window.setStyleSheet(style.load_stylesheet())

module.window = window
2 changes: 1 addition & 1 deletion avalon/tools/loader/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,8 @@ def show(debug=False, parent=None, use_context=False):
lib.refresh_group_config_cache()

window = Window(parent)
window.setStyleSheet(style.load_stylesheet())
window.show()
window.setStyleSheet(style.load_stylesheet())

if use_context:
context = {"asset": api.Session["AVALON_ASSET"],
Expand Down
2 changes: 1 addition & 1 deletion avalon/tools/projectmanager/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ def show(root=None, debug=False, parent=None):

with tools_lib.application():
window = Window(parent)
window.setStyleSheet(style.load_stylesheet())
window.show()
window.setStyleSheet(style.load_stylesheet())
window.refresh()

module.window = window
Expand Down
2 changes: 1 addition & 1 deletion avalon/tools/sceneinventory/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,8 +934,8 @@ def show(root=None, debug=False, parent=None):

with tools_lib.application():
window = Window(parent)
window.setStyleSheet(style.load_stylesheet())
window.show()
window.setStyleSheet(style.load_stylesheet())
window.refresh()

module.window = window
13 changes: 7 additions & 6 deletions avalon/tools/workfiles/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
module = sys.modules[__name__]
module.window = None


class NameWindow(QtWidgets.QDialog):
"""Name Window"""

Expand Down Expand Up @@ -236,10 +237,10 @@ def setup(self, root):
class Window(QtWidgets.QDialog):
"""Work Files Window"""

def __init__(self, root=None):
super(Window, self).__init__()
def __init__(self, root=None, parent=None):
super(Window, self).__init__(parent)
self.setWindowTitle("Work Files")
self.setWindowFlags(QtCore.Qt.WindowCloseButtonHint)
self.setWindowFlags(QtCore.Qt.Window | QtCore.Qt.WindowCloseButtonHint)

self.root = root

Expand Down Expand Up @@ -457,7 +458,7 @@ def on_save_as_pressed(self):
self.close()


def show(root=None, debug=False):
def show(root=None, debug=False, parent=None):
"""Show Work Files GUI"""

if module.window:
Expand Down Expand Up @@ -499,8 +500,8 @@ def show(root=None, debug=False):
api.Session["AVALON_TASK"] = "Testing"

with tools_lib.application():
window = Window(root)
window.setStyleSheet(style.load_stylesheet())
window = Window(root, parent=parent)
window.show()
window.setStyleSheet(style.load_stylesheet())

module.window = window
21 changes: 13 additions & 8 deletions res/houdini/MainMenuCommon.XML
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ return "%s - %s" % (api.Session["AVALON_ASSET"], api.Session["AVALON_TASK"])
<scriptItem id="avalon_context_switch">
<label>Set Context</label>
<scriptCode><![CDATA[
from avalon.tools import contextmanager; contextmanager.show()
from avalon.tools import contextmanager
from avalon.houdini import pipeline
contextmanager.show(parent=pipeline.get_main_window())
]]></scriptCode>
</scriptItem>
</subMenu>
Expand All @@ -22,23 +24,26 @@ from avalon.tools import contextmanager; contextmanager.show()
<label>Create ..</label>
<scriptCode><![CDATA[
from avalon.tools import creator
creator.show()
from avalon.houdini import pipeline
creator.show(parent=pipeline.get_main_window())
]]></scriptCode>
</scriptItem>

<scriptItem id="avalon_load">
<label>Load ..</label>
<scriptCode><![CDATA[
from avalon.tools import loader
loader.show(use_context=True)
from avalon.houdini import pipeline
loader.show(parent=pipeline.get_main_window(), use_context=True)
]]></scriptCode>
</scriptItem>

<scriptItem id="avalon_manage">
<label>Manage ..</label>
<scriptCode><![CDATA[
from avalon.tools import sceneinventory
sceneinventory.show()
from avalon.houdini import pipeline
sceneinventory.show(parent=pipeline.get_main_window())
]]></scriptCode>
</scriptItem>

Expand All @@ -47,8 +52,8 @@ sceneinventory.show()
<scriptCode><![CDATA[
import hou
from avalon.tools import publish
parent = hou.qt.mainWindow()
publish.show(parent)
from avalon.houdini import pipeline
publish.show(parent=pipeline.get_main_window())
]]></scriptCode>
</scriptItem>

Expand All @@ -59,8 +64,8 @@ publish.show(parent)
<scriptCode><![CDATA[
import hou
from avalon.tools import workfiles
#parent = hou.qt.mainWindow()
workfiles.show()
from avalon.houdini import pipeline
workfiles.show(parent=pipeline.get_main_window())
]]></scriptCode>
</scriptItem>

Expand Down

0 comments on commit 815aa55

Please sign in to comment.