diff --git a/wulifang/nuke/_init_gui.py b/wulifang/nuke/_init_gui.py index f9a70a34..98ef6340 100644 --- a/wulifang/nuke/_init_gui.py +++ b/wulifang/nuke/_init_gui.py @@ -57,6 +57,7 @@ _preference, _project_settings, _prune_node, + _python2_project_warning, _random_gl_color, _remove_duplicated_read, _rename_channels, @@ -603,5 +604,6 @@ def init_gui(): _node_suggestion.init_gui() _fix_unicode_decode_error.init_gui() _fix_cryptomatte_name_lost.init_gui() + _python2_project_warning.init_gui() _init_cgtw() _g.init_once = True diff --git a/wulifang/nuke/_python2_project_warning.py b/wulifang/nuke/_python2_project_warning.py new file mode 100644 index 00000000..0efe146f --- /dev/null +++ b/wulifang/nuke/_python2_project_warning.py @@ -0,0 +1,41 @@ +# -*- coding=UTF-8 -*- +# pyright: strict, reportTypeCommentUsage=none + +from __future__ import absolute_import, division, print_function, unicode_literals + +TYPE_CHECKING = False +if TYPE_CHECKING: + from typing import Any + + +import sys +import wulifang +import nuke +from wulifang._util import cast_str + + +def init_gui(): + if sys.version_info.major == 2: + return + + raw_hook = sys.excepthook + + def hook(type, value, traceback): + # type: (type[BaseException], BaseException, Any) -> None + if raw_hook: # type: ignore + raw_hook(type, value, traceback) + if ( + isinstance(value, NameError) + and value.args == ("name 'unicode' is not defined",) + and nuke.value(cast_str("root.name"), cast_str("")) + ): + wulifang.message.info( + "脚本出错,python 版本不兼容。当前工程需使用 Nuke12 以下版本。" + ) + + def cleanup(): + if sys.excepthook == hook: + sys.excepthook = raw_hook + + sys.excepthook = hook + wulifang.cleanup.add(cleanup)