From 56a90a47f544e5c71e5edefd83d4d224773f08a7 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Thu, 22 Jun 2023 19:02:18 +0800 Subject: [PATCH] abstract the headless command as function in lib.py --- openpype/hosts/nuke/api/lib.py | 9 +++++++++ openpype/hosts/nuke/api/workio.py | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/openpype/hosts/nuke/api/lib.py b/openpype/hosts/nuke/api/lib.py index 4a57bc3165..c469612954 100644 --- a/openpype/hosts/nuke/api/lib.py +++ b/openpype/hosts/nuke/api/lib.py @@ -3116,3 +3116,12 @@ def get_viewer_config_from_string(input_string): ).format(input_string)) return (display, viewer) + + +def is_headless(): + """ + Returns: + bool: headless + """ + headless = QtWidgets.QApplication.instance() is None + return headless diff --git a/openpype/hosts/nuke/api/workio.py b/openpype/hosts/nuke/api/workio.py index 032a9fdda8..8b5bae3b2c 100644 --- a/openpype/hosts/nuke/api/workio.py +++ b/openpype/hosts/nuke/api/workio.py @@ -2,6 +2,7 @@ import os import nuke from qtpy import QtWidgets +from openpype.hosts.nuke.api.lib import is_headless def file_extensions(): @@ -26,7 +27,7 @@ def open_file(filepath): # To remain in the same window, we have to clear the script and read # in the contents of the workfile. nuke.scriptClear() - headless = QtWidgets.QApplication.instance() is None + headless = is_headless() if not headless: autosave = nuke.toNode("preferences")["AutoSaveName"].evaluate() autosave_prmpt = "Autosave detected.\nWould you like to load the autosave file?" # noqa