diff --git a/engine.py b/engine.py index 8f1d322..a7ea2c4 100644 --- a/engine.py +++ b/engine.py @@ -241,41 +241,42 @@ def pre_app_init(self): ) if self.has_ui: - sgtk.platform.qt.QtGui.QMessageBox.warning( - # Use QMessageBox instead of nuke.message because: - # - nuke.message is not available in Hiero - # - nuke.message doesn't allow to set the title - # Overall, this is a better user experience - None, # parent - "Warning - Flow Production Tracking Compatibility!".ljust( - # Padding to try to prevent the dialog being insanely narrow - 70 - ), - """ -Flow Production Tracking no longer supports {product} versions older than -{version}. -You can continue to use Toolkit but you may experience bugs or instabilities. - -For information regarding support engine versions, please visit this page: -{url_doc_supported_versions} - """.strip() - .replace( - # Presence of \n breaks the Rich Text Format - "\n", - "
", - ) - .format( - product="Nuke", - url_doc_supported_versions='{u}'.format( - u=url_doc_supported_versions, - color=sgtk.platform.constants.SG_STYLESHEET_CONSTANTS.get( - "SG_HIGHLIGHT_COLOR", - "#18A7E3", + if self.get_setting("display_min_supported_version_warning_dialog"): + sgtk.platform.qt.QtGui.QMessageBox.warning( + # Use QMessageBox instead of nuke.message because: + # - nuke.message is not available in Hiero + # - nuke.message doesn't allow to set the title + # Overall, this is a better user experience + None, # parent + "Warning - Flow Production Tracking Compatibility!".ljust( + # Padding to try to prevent the dialog being insanely narrow + 70 + ), + """ + Flow Production Tracking no longer supports {product} versions older than + {version}. + You can continue to use Toolkit but you may experience bugs or instabilities. + + For information regarding support engine versions, please visit this page: + {url_doc_supported_versions} + """.strip() + .replace( + # Presence of \n breaks the Rich Text Format + "\n", + "
", + ) + .format( + product="Nuke", + url_doc_supported_versions='{u}'.format( + u=url_doc_supported_versions, + color=sgtk.platform.constants.SG_STYLESHEET_CONSTANTS.get( + "SG_HIGHLIGHT_COLOR", + "#18A7E3", + ), ), + version=self.version_str(VERSION_OLDEST_SUPPORTED), ), - version=self.version_str(VERSION_OLDEST_SUPPORTED), - ), - ) + ) elif nuke_version <= VERSION_NEWEST_SUPPORTED: # Within the range of supported versions diff --git a/info.yml b/info.yml index 4f535a6..58e3d3a 100644 --- a/info.yml +++ b/info.yml @@ -159,6 +159,13 @@ configuration: value to the current major version + 1." default_value: 16 + display_min_supported_version_warning_dialog: + type: bool + description: "Controls whether a warning should display if the nuke version is below the minimum supported, + but above the minimum required, version. Defaults to True. Set to False to disable the GUI + warning so this doesn't interrupt the loading of the application." + default_value: True + # the Shotgun fields that this engine needs in order to operate correctly requires_shotgun_fields: diff --git a/python/tk_nuke/__init__.py b/python/tk_nuke/__init__.py index 0716e35..eadd646 100644 --- a/python/tk_nuke/__init__.py +++ b/python/tk_nuke/__init__.py @@ -155,11 +155,53 @@ def __sgtk_on_save_callback(): # now restart the engine with the new context __engine_refresh(new_ctx) + # Ensure that the sgtk tab and sgtk_context knob exist on the root node. + __ensure_sgtk_tab_and_context() + + # save the context into the sgtk_context knob + root = nuke.root() + if "sgtk_context" in root.knobs(): + context_knob = root.knob("sgtk_context") + context_str = new_ctx.serialize(with_user_credentials=False, use_json=False) + context_knob.setValue(context_str) + logger.debug("Updated 'sgtk_context' knob with value: %s" % context_str) + except Exception: logger.exception("An exception was raised during addOnScriptSave callback.") __create_tank_error_menu() +def __ensure_sgtk_tab_and_context(): + """ + Ensure that the sgtk tab and sgtk_context knob exist on the root node. + 1. If the "sgtk" tab does not exist, create it. + 2. If the "sgtk_context" knob does not exist, create it. + 3. Log actions taken. + """ + logger.debug("Ensuring 'sgtk' tab and 'sgtk_context' knob exist on root node.") + + try: + root = nuke.root() + + # Check if the "sgtk" tab exists + if "sgtk" not in root.knobs(): + sgtk_tab = nuke.Tab_Knob("sgtk", "sgtk") + root.addKnob(sgtk_tab) + logger.debug("Created 'sgtk' tab on root.") + else: + logger.debug("'sgtk' tab already exists.") + + # Check if the sgtk_context knob exists + if "sgtk_context" not in root.knobs(): + context_knob = nuke.String_Knob("sgtk_context", "ShotGrid Context") + root.addKnob(context_knob) + logger.debug("Created 'sgtk_context' knob.") + else: + logger.debug("'sgtk_context' knob already exists.") + except Exception as e: + logger.exception("Failed to ensure 'sgtk' tab and 'sgtk_context' knob: %s", e) + + def sgtk_on_load_callback(): """ Callback that fires every time a script is loaded. @@ -217,7 +259,26 @@ def sgtk_on_load_callback(): if sgtk.platform.current_engine(): curr_ctx = sgtk.platform.current_engine().context - logger.debug("") + logger.debug("Trying to get the context from the root.sgtk_context knob if it exists...") + # Try to get the context from the root.sgtk_context knob if it exists + root = nuke.root() + if "sgtk_context" in root.knobs(): + context_knob = root.knob("sgtk_context") + context_str_serialized = context_knob.value() + if context_str_serialized: + logger.debug("Found serialized context in knob: %s" % context_str_serialized) + try: + new_ctx = sgtk.Context.deserialize(context_str_serialized) + logger.debug("Deserialized context from knob: %r" % (new_ctx,)) + # Now switch to the context appropriate for the file + __engine_refresh(new_ctx) + return + except Exception as e: + logger.debug( + "Could not deserialize context from knob: %s" % (e,) + ) + + logger.debug("Computing new context from file path...") new_ctx = tk.context_from_path(file_name, curr_ctx) logger.debug("Current context: %r" % (curr_ctx,)) logger.debug("New context: %r" % (new_ctx,)) @@ -274,3 +335,4 @@ def tank_ensure_callbacks_registered(engine=None): nuke.removeOnScriptLoad(sgtk_on_load_callback) nuke.removeOnScriptSave(__sgtk_on_save_callback) g_tank_callbacks_registered = False +