From 09ef82cfd2e1b7c53c0f19010d7371b8b36dfe5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= Date: Wed, 26 Feb 2020 16:05:33 +0100 Subject: [PATCH 1/3] switching context will now change content to new asset --- pype/maya/__init__.py | 1 + pype/maya/lib.py | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/pype/maya/__init__.py b/pype/maya/__init__.py index f027893a0e..726fd14faa 100644 --- a/pype/maya/__init__.py +++ b/pype/maya/__init__.py @@ -218,3 +218,4 @@ def on_task_changed(*args): # Run maya.pipeline._on_task_changed() + lib.update_content_on_context_change() diff --git a/pype/maya/lib.py b/pype/maya/lib.py index dafc281903..5333b75359 100644 --- a/pype/maya/lib.py +++ b/pype/maya/lib.py @@ -2452,3 +2452,29 @@ class shelf(): cmds.deleteUI(each) else: cmds.shelfLayout(self.name, p="ShelfLayout") + + +def update_content_on_context_change(): + """ + This will update scene content to match new asset on context change + """ + scene_sets = cmds.listSets(allSets=True) + new_asset = api.Session["AVALON_ASSET"] + new_data = lib.get_asset()["data"] + for s in scene_sets: + try: + if cmds.getAttr("{}.id".format(s)) == "pyblish.avalon.instance": + attr = cmds.listAttr(s) + print(s) + if "asset" in attr: + print(" - setting asset to: [ {} ]".format(new_asset)) + cmds.setAttr("{}.asset".format(s), + new_asset, type="string") + if "frameStart" in attr: + cmds.setAttr("{}.frameStart".format(s), + new_data["frameStart"]) + if "frameEnd" in attr: + cmds.setAttr("{}.frameEnd".format(s), + new_data["frameEnd"],) + except ValueError: + pass From 856f67e113df2cbc13450123e8aadc83c2522e5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= Date: Wed, 26 Feb 2020 21:17:12 +0100 Subject: [PATCH 2/3] added reset frame range on task change --- pype/maya/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pype/maya/__init__.py b/pype/maya/__init__.py index cbdd3696be..417f617784 100644 --- a/pype/maya/__init__.py +++ b/pype/maya/__init__.py @@ -229,4 +229,6 @@ def on_task_changed(*args): # Run maya.pipeline._on_task_changed() - lib.update_content_on_context_change() + with maya.suspended_refresh(): + lib.set_context_settings() + lib.update_content_on_context_change() From 69ca74f27bb5c6c47af5e227c7310e166f862fbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= Date: Wed, 26 Feb 2020 21:47:17 +0100 Subject: [PATCH 3/3] added info message on context change --- pype/maya/__init__.py | 4 ++++ pype/maya/lib.py | 15 +++++++++++++++ pype/widgets/message_window.py | 9 +++++---- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/pype/maya/__init__.py b/pype/maya/__init__.py index 417f617784..fdc061f069 100644 --- a/pype/maya/__init__.py +++ b/pype/maya/__init__.py @@ -232,3 +232,7 @@ def on_task_changed(*args): with maya.suspended_refresh(): lib.set_context_settings() lib.update_content_on_context_change() + + lib.show_message("Context was changed", + ("Context was changed to {}".format( + avalon.Session["AVALON_ASSET"]))) diff --git a/pype/maya/lib.py b/pype/maya/lib.py index 470b9b4167..6ea108e801 100644 --- a/pype/maya/lib.py +++ b/pype/maya/lib.py @@ -2611,3 +2611,18 @@ def update_content_on_context_change(): new_data["frameEnd"],) except ValueError: pass + + +def show_message(title, msg): + from avalon.vendor.Qt import QtWidgets + from ..widgets import message_window + + # Find maya main window + top_level_widgets = {w.objectName(): w for w in + QtWidgets.QApplication.topLevelWidgets()} + + parent = top_level_widgets.get("MayaWindow", None) + if parent is None: + pass + else: + message_window.message(title=title, message=msg, parent=parent) diff --git a/pype/widgets/message_window.py b/pype/widgets/message_window.py index 72e655cf5c..3532d2df44 100644 --- a/pype/widgets/message_window.py +++ b/pype/widgets/message_window.py @@ -7,7 +7,7 @@ log = logging.getLogger(__name__) class Window(QtWidgets.QWidget): def __init__(self, parent, title, message, level): - super().__init__() + super(Window, self).__init__() self.parent = parent self.title = title self.message = message @@ -48,9 +48,10 @@ class Window(QtWidgets.QWidget): return -def message(title=None, message=None, level="info"): - global app - app = QtWidgets.QApplication(sys.argv) +def message(title=None, message=None, level="info", parent=None): + app = parent + if not app: + app = QtWidgets.QApplication(sys.argv) ex = Window(app, title, message, level) ex.show() # sys.exit(app.exec_())