add headless abstraction into command.py

This commit is contained in:
Kayla Man 2023-06-23 00:10:34 +08:00
parent 5c399cbc17
commit 22ee8e1f93
3 changed files with 12 additions and 11 deletions

View file

@ -2,6 +2,8 @@ import logging
import contextlib
import nuke
from qtpy import QtWidgets
log = logging.getLogger(__name__)
@ -19,3 +21,11 @@ def viewer_update_and_undo_stop():
yield
finally:
nuke.Undo.enable()
def is_headless():
"""
Returns:
bool: headless
"""
return QtWidgets.QApplication.instance() is None

View file

@ -3155,11 +3155,3 @@ def get_viewer_config_from_string(input_string):
).format(input_string))
return (display, viewer)
def is_headless():
"""
Returns:
bool: headless
"""
return QtWidgets.QApplication.instance() is None

View file

@ -1,7 +1,7 @@
"""Host API required Work Files tool"""
import os
import nuke
from qtpy import QtWidgets
from .command import is_headless
def file_extensions():
@ -26,8 +26,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
if not headless:
if not is_headless():
autosave = nuke.toNode("preferences")["AutoSaveName"].evaluate()
autosave_prmpt = "Autosave detected.\nWould you like to load the autosave file?" # noqa
if os.path.isfile(autosave) and nuke.ask(autosave_prmpt):