From 2207d3a279a7974d187a43d404861cd68f06c05c Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 27 Oct 2021 18:13:17 +0200 Subject: [PATCH 1/6] use scene inventory from host tools --- openpype/hosts/maya/api/__init__.py | 3 +-- openpype/plugins/publish/validate_containers.py | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/openpype/hosts/maya/api/__init__.py b/openpype/hosts/maya/api/__init__.py index d1c13b04d5..0a8370eafc 100644 --- a/openpype/hosts/maya/api/__init__.py +++ b/openpype/hosts/maya/api/__init__.py @@ -275,8 +275,7 @@ def on_open(_): # Show outdated pop-up def _on_show_inventory(): - import avalon.tools.sceneinventory as tool - tool.show(parent=parent) + host_tools.show_scene_inventory(parent=parent) dialog = popup.Popup(parent=parent) dialog.setWindowTitle("Maya scene has outdated content") diff --git a/openpype/plugins/publish/validate_containers.py b/openpype/plugins/publish/validate_containers.py index 784221c3b6..ce91bd3396 100644 --- a/openpype/plugins/publish/validate_containers.py +++ b/openpype/plugins/publish/validate_containers.py @@ -9,9 +9,9 @@ class ShowInventory(pyblish.api.Action): on = "failed" def process(self, context, plugin): - from avalon.tools import sceneinventory + from openpype.tools.utils import host_tools - sceneinventory.show() + host_tools.show_scene_inventory() class ValidateContainers(pyblish.api.ContextPlugin): From 7c1ad1883de9d8defe2adfcd65d53fd0db61eb66 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 27 Oct 2021 18:14:17 +0200 Subject: [PATCH 2/6] use AssetWidget from openpype.tool --- openpype/hosts/houdini/api/usd.py | 8 +++----- openpype/tools/launcher/window.py | 3 +-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/openpype/hosts/houdini/api/usd.py b/openpype/hosts/houdini/api/usd.py index 850ffb60e5..6f808779ea 100644 --- a/openpype/hosts/houdini/api/usd.py +++ b/openpype/hosts/houdini/api/usd.py @@ -4,8 +4,8 @@ import contextlib import logging from Qt import QtCore, QtGui -from avalon.tools.widgets import AssetWidget -from avalon import style +from openpype.tools.utils.widgets import AssetWidget +from avalon import style, io from pxr import Sdf @@ -31,7 +31,7 @@ def pick_asset(node): # Construct the AssetWidget as a frameless popup so it automatically # closes when clicked outside of it. global tool - tool = AssetWidget(silo_creatable=False) + tool = AssetWidget(io) tool.setContentsMargins(5, 5, 5, 5) tool.setWindowTitle("Pick Asset") tool.setStyleSheet(style.load_stylesheet()) @@ -41,8 +41,6 @@ def pick_asset(node): # Select the current asset if there is any name = parm.eval() if name: - from avalon import io - db_asset = io.find_one({"name": name, "type": "asset"}) if db_asset: silo = db_asset.get("silo") diff --git a/openpype/tools/launcher/window.py b/openpype/tools/launcher/window.py index 9b839fb2bc..9e4af1c89b 100644 --- a/openpype/tools/launcher/window.py +++ b/openpype/tools/launcher/window.py @@ -8,8 +8,7 @@ from avalon.api import AvalonMongoDB from openpype import style from openpype.api import resources -from avalon.tools import lib as tools_lib -from avalon.tools.widgets import AssetWidget +from openpype.tools.utils.widgets import AssetWidget from avalon.vendor import qtawesome from .models import ProjectModel from .lib import get_action_label, ProjectHandler From 0f026551fe436dba388004f8bbea70af0286664d Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 27 Oct 2021 18:14:24 +0200 Subject: [PATCH 3/6] removed dummy context manager --- openpype/tools/utils/lib.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/openpype/tools/utils/lib.py b/openpype/tools/utils/lib.py index d01dbbd169..4b91a5e6dd 100644 --- a/openpype/tools/utils/lib.py +++ b/openpype/tools/utils/lib.py @@ -82,18 +82,6 @@ def schedule(func, time, channel="default"): SharedObjects.jobs[channel] = timer -@contextlib.contextmanager -def dummy(): - """Dummy context manager - - Usage: - >> with some_context() if False else dummy(): - .. pass - - """ - yield - - def iter_model_rows(model, column, include_root=False): """Iterate over all row indices in a model""" indices = [QtCore.QModelIndex()] # start iteration at root From ea30fb1b7395495fded8bff9a749be2f3845b480 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 27 Oct 2021 18:35:57 +0200 Subject: [PATCH 4/6] removed unused defer function --- openpype/tools/utils/lib.py | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/openpype/tools/utils/lib.py b/openpype/tools/utils/lib.py index 4b91a5e6dd..05e8fc4cfb 100644 --- a/openpype/tools/utils/lib.py +++ b/openpype/tools/utils/lib.py @@ -35,26 +35,6 @@ def application(): yield app -def defer(delay, func): - """Append artificial delay to `func` - - This aids in keeping the GUI responsive, but complicates logic - when producing tests. To combat this, the environment variable ensures - that every operation is synchonous. - - Arguments: - delay (float): Delay multiplier; default 1, 0 means no delay - func (callable): Any callable - - """ - - delay *= float(os.getenv("PYBLISH_DELAY", 1)) - if delay > 0: - return QtCore.QTimer.singleShot(delay, func) - else: - return func() - - class SharedObjects: jobs = {} From d311e23165cfef41cbf6477a4c49e34e565dce60 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 27 Oct 2021 18:36:04 +0200 Subject: [PATCH 5/6] removed unused import --- openpype/tools/pyblish_pype/control.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openpype/tools/pyblish_pype/control.py b/openpype/tools/pyblish_pype/control.py index 234135fd9a..1fa3ee657b 100644 --- a/openpype/tools/pyblish_pype/control.py +++ b/openpype/tools/pyblish_pype/control.py @@ -7,7 +7,6 @@ an active window manager; such as via Travis-CI. """ import os import sys -import traceback import inspect import logging From 5c851691966e5806ba9144b8e19fa3d6ffee440e Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 27 Oct 2021 18:53:31 +0200 Subject: [PATCH 6/6] removed unused preserve_states --- openpype/tools/utils/lib.py | 70 ------------------------------------- 1 file changed, 70 deletions(-) diff --git a/openpype/tools/utils/lib.py b/openpype/tools/utils/lib.py index 05e8fc4cfb..aad00f886c 100644 --- a/openpype/tools/utils/lib.py +++ b/openpype/tools/utils/lib.py @@ -79,76 +79,6 @@ def iter_model_rows(model, column, include_root=False): yield index -@contextlib.contextmanager -def preserve_states(tree_view, - column=0, - role=None, - preserve_expanded=True, - preserve_selection=True, - expanded_role=QtCore.Qt.DisplayRole, - selection_role=QtCore.Qt.DisplayRole): - """Preserves row selection in QTreeView by column's data role. - This function is created to maintain the selection status of - the model items. When refresh is triggered the items which are expanded - will stay expanded and vise versa. - tree_view (QWidgets.QTreeView): the tree view nested in the application - column (int): the column to retrieve the data from - role (int): the role which dictates what will be returned - Returns: - None - """ - # When `role` is set then override both expanded and selection roles - if role: - expanded_role = role - selection_role = role - - model = tree_view.model() - selection_model = tree_view.selectionModel() - flags = selection_model.Select | selection_model.Rows - - expanded = set() - - if preserve_expanded: - for index in iter_model_rows( - model, column=column, include_root=False - ): - if tree_view.isExpanded(index): - value = index.data(expanded_role) - expanded.add(value) - - selected = None - - if preserve_selection: - selected_rows = selection_model.selectedRows() - if selected_rows: - selected = set(row.data(selection_role) for row in selected_rows) - - try: - yield - finally: - if expanded: - for index in iter_model_rows( - model, column=0, include_root=False - ): - value = index.data(expanded_role) - is_expanded = value in expanded - # skip if new index was created meanwhile - if is_expanded is None: - continue - tree_view.setExpanded(index, is_expanded) - - if selected: - # Go through all indices, select the ones with similar data - for index in iter_model_rows( - model, column=column, include_root=False - ): - value = index.data(selection_role) - state = value in selected - if state: - tree_view.scrollTo(index) # Ensure item is visible - selection_model.select(index, flags) - - @contextlib.contextmanager def preserve_expanded_rows(tree_view, column=0, role=None): """Preserves expanded row in QTreeView by column's data role.