Skip to content

Commit

Permalink
feat(nuke): add python2 project warning
Browse files Browse the repository at this point in the history
  • Loading branch information
NateScarlet committed Mar 29, 2024
1 parent 52979cf commit fc7ac0e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions wulifang/nuke/_init_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
_preference,
_project_settings,
_prune_node,
_python2_project_warning,
_random_gl_color,
_remove_duplicated_read,
_rename_channels,
Expand Down Expand Up @@ -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
41 changes: 41 additions & 0 deletions wulifang/nuke/_python2_project_warning.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit fc7ac0e

Please sign in to comment.