Skip to content

Commit d275183

Browse files
authored
Merge pull request #13 from weijer/nuke13
Nuke13
2 parents 0fd25d8 + e9a0c7f commit d275183

File tree

15 files changed

+2136
-63
lines changed

15 files changed

+2136
-63
lines changed

Qt.py

Lines changed: 67 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,17 @@
4242
import types
4343
import shutil
4444
import importlib
45+
import json
4546

4647

47-
__version__ = "1.2.3"
48+
__version__ = "1.3.2"
4849

4950
# Enable support for `from Qt import *`
5051
__all__ = []
5152

5253
# Flags from environment variables
5354
QT_VERBOSE = bool(os.getenv("QT_VERBOSE"))
55+
QT_PREFERRED_BINDING_JSON = os.getenv("QT_PREFERRED_BINDING_JSON", "")
5456
QT_PREFERRED_BINDING = os.getenv("QT_PREFERRED_BINDING", "")
5557
QT_SIP_API_HINT = os.getenv("QT_SIP_API_HINT")
5658

@@ -777,19 +779,25 @@ def _wrapinstance(ptr, base=None):
777779
raise AttributeError("'module' has no attribute 'wrapInstance'")
778780

779781
if base is None:
780-
q_object = func(long(ptr), Qt.QtCore.QObject)
781-
meta_object = q_object.metaObject()
782-
class_name = meta_object.className()
783-
super_class_name = meta_object.superClass().className()
782+
if Qt.IsPyQt4 or Qt.IsPyQt5:
783+
base = Qt.QtCore.QObject
784+
else:
785+
q_object = func(long(ptr), Qt.QtCore.QObject)
786+
meta_object = q_object.metaObject()
784787

785-
if hasattr(Qt.QtWidgets, class_name):
786-
base = getattr(Qt.QtWidgets, class_name)
788+
while True:
789+
class_name = meta_object.className()
787790

788-
elif hasattr(Qt.QtWidgets, super_class_name):
789-
base = getattr(Qt.QtWidgets, super_class_name)
791+
try:
792+
base = getattr(Qt.QtWidgets, class_name)
793+
except AttributeError:
794+
try:
795+
base = getattr(Qt.QtCore, class_name)
796+
except AttributeError:
797+
meta_object = meta_object.superClass()
798+
continue
790799

791-
else:
792-
base = Qt.QtCore.QObject
800+
break
793801

794802
return func(long(ptr), base)
795803

@@ -969,7 +977,7 @@ def createWidget(self, class_name, parent=None, name=""):
969977
parent,
970978
name)
971979
elif class_name in self.custom_widgets:
972-
widget = self.custom_widgets[class_name](parent)
980+
widget = self.custom_widgets[class_name](parent=parent)
973981
else:
974982
raise Exception("Custom widget '%s' not supported"
975983
% class_name)
@@ -1251,16 +1259,24 @@ def _setup(module, extras):
12511259

12521260
Qt.__binding__ = module.__name__
12531261

1262+
def _warn_import_error(exc, module):
1263+
msg = str(exc)
1264+
if "No module named" in msg:
1265+
return
1266+
_warn("ImportError(%s): %s" % (module, msg))
1267+
12541268
for name in list(_common_members) + extras:
12551269
try:
12561270
submodule = _import_sub_module(
12571271
module, name)
1258-
except ImportError:
1272+
except ImportError as e:
12591273
try:
12601274
# For extra modules like sip and shiboken that may not be
12611275
# children of the binding.
12621276
submodule = __import__(name)
1263-
except ImportError:
1277+
except ImportError as e2:
1278+
_warn_import_error(e, name)
1279+
_warn_import_error(e2, name)
12641280
continue
12651281

12661282
setattr(Qt, "_" + name, submodule)
@@ -1508,13 +1524,13 @@ def _pyqt5():
15081524
extras = ["uic"]
15091525

15101526
try:
1511-
import sip
1527+
# Relevant to PyQt5 5.11 and above
1528+
from PyQt5 import sip
15121529
extras += ["sip"]
15131530
except ImportError:
15141531

1515-
# Relevant to PyQt5 5.11 and above
15161532
try:
1517-
from PyQt5 import sip
1533+
import sip
15181534
extras += ["sip"]
15191535
except ImportError:
15201536
sip = None
@@ -1662,7 +1678,11 @@ def _none():
16621678

16631679
def _log(text):
16641680
if QT_VERBOSE:
1665-
sys.stdout.write(text + "\n")
1681+
sys.stdout.write("Qt.py [info]: %s\n" % text)
1682+
1683+
1684+
def _warn(text):
1685+
sys.stderr.write("Qt.py [warning]: %s\n" % text)
16661686

16671687

16681688
def _convert(lines):
@@ -1781,11 +1801,36 @@ def __call__(self, *a, **kw):
17811801

17821802

17831803
def _install():
1784-
# Default order (customise order and content via QT_PREFERRED_BINDING)
1804+
# Default order (customize order and content via QT_PREFERRED_BINDING)
17851805
default_order = ("PySide2", "PyQt5", "PySide", "PyQt4")
1786-
preferred_order = list(
1787-
b for b in QT_PREFERRED_BINDING.split(os.pathsep) if b
1788-
)
1806+
preferred_order = None
1807+
if QT_PREFERRED_BINDING_JSON:
1808+
# A per-vendor preferred binding customization was defined
1809+
# This should be a dictionary of the full Qt.py module namespace to
1810+
# apply binding settings to. The "default" key can be used to apply
1811+
# custom bindings to all modules not explicitly defined. If the json
1812+
# data is invalid this will raise a exception.
1813+
# Example:
1814+
# {"mylibrary.vendor.Qt": ["PySide2"], "default":["PyQt5","PyQt4"]}
1815+
try:
1816+
preferred_bindings = json.loads(QT_PREFERRED_BINDING_JSON)
1817+
except ValueError:
1818+
# Python 2 raises ValueError, Python 3 raises json.JSONDecodeError
1819+
# a subclass of ValueError
1820+
_warn("Failed to parse QT_PREFERRED_BINDING_JSON='%s'"
1821+
% QT_PREFERRED_BINDING_JSON)
1822+
_warn("Falling back to default preferred order")
1823+
else:
1824+
preferred_order = preferred_bindings.get(__name__)
1825+
# If no matching binding was used, optionally apply a default.
1826+
if preferred_order is None:
1827+
preferred_order = preferred_bindings.get("default", None)
1828+
if preferred_order is None:
1829+
# If a json preferred binding was not used use, respect the
1830+
# QT_PREFERRED_BINDING environment variable if defined.
1831+
preferred_order = list(
1832+
b for b in QT_PREFERRED_BINDING.split(os.pathsep) if b
1833+
)
17891834

17901835
order = preferred_order or default_order
17911836

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
### Nuke工具集说明
33
大部分都是这几年干合成用到的,有些自己写的,有些朋友写的,有些网上down的!现在免费开源共享,希望大家都来共享自己的nuke插件!
44

5+
### 更新说明
6+
2021-5-12
7+
8+
支持Nuke 13
9+
510
### 更新说明
611
2017-7-27
712

menu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def add_bar_tools(self):
110110
else:
111111
tools_icon = ""
112112

113-
print tools_icon
113+
print (tools_icon)
114114
self.create_tools(cmenu,
115115
tools["type"],
116116
tools["name"],

python/Channel/autoComper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def getParentNode(layer, compNodes, mergeLayer):
9393

9494
iteration += 1
9595
if iteration > 20:
96-
print "ERROR:\nPLEASE CHECK IF THE NAMES OF THE PARENT-NAMES FIT TO THE LAYER-NAMES"
96+
print ("ERROR:\nPLEASE CHECK IF THE NAMES OF THE PARENT-NAMES FIT TO THE LAYER-NAMES")
9797
parentNode = -1
9898
break
9999

python/CreatePointCloud/CreatedPointCloud.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ def scan_ply_data(path, max_points):
4040
for line in lines:
4141
if "element vertex" in line:
4242
verts_count = int(line.split()[2])
43-
print "%s points detected! " % verts_count
43+
print ("%s points detected! " % verts_count)
4444
if started and total < verts_count:
4545
vert_entries.append(line)
4646
total += 1
4747
if "end_header" in line:
4848
started = True
4949
if max_points <= verts_count:
50-
print "selecting only %s points at random! " % max_points
50+
print ("selecting only %s points at random! ") % max_points
5151
vert_entries = randomSelection(max_points, vert_entries)
5252
for entry in vert_entries:
5353
data_split = entry.split()

python/NukeFXSExporter/NukeFXSExporter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -861,13 +861,13 @@ def silhouetteFxsExporter():
861861
ext = ext + ".fxs"
862862
path = os.path.join(base, ext)
863863
else:
864-
print "Saving file to: %s" % path
864+
print ("Saving file to: %s") % path
865865

866866
indent(fxsExport)
867867
ET.ElementTree(fxsExport).write(path)
868868
nuke.delete(rotoNode)
869869
task.setProgress(100)
870-
print "Time elapsed: %s seconds" % (time.time() - start_time)
870+
print ("Time elapsed: %s seconds") % (time.time() - start_time)
871871

872872

873873
if __name__ == '__main__':

python/ToolSet/__init__.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
# coding=utf-8
22
# author=weijer
33

4-
import presetBackdrop
5-
import browseDir
6-
import ReadAfterRender
7-
import single_to_sequence
8-
import switch_shot
9-
import correct_error_read_node
10-
import ListShuffle
11-
import replace_read_node_path
12-
import toggle_input
13-
import toggle_stamp
14-
4+
from . import presetBackdrop
5+
from . import browseDir
6+
from . import ReadAfterRender
7+
from . import single_to_sequence
8+
from . import switch_shot
9+
from . import correct_error_read_node
10+
from . import ListShuffle
11+
from . import replace_read_node_path
12+
from . import toggle_input
13+
from . import toggle_stamp

python/ToolSet/browseDir.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def browseDirByNode():
6565
regcombile_t = re.compile('(//192.168.0.250/tvcServe/)\S+')
6666
matchgroup_r = regcombile_r.match(dirFromNode)
6767
matchgroup_t = regcombile_t.match(dirFromNode)
68-
print matchgroup_r, matchgroup_t
68+
print (matchgroup_r, matchgroup_t)
6969

7070
if matchgroup_r:
7171
dirFromNode_new = re.sub("//192.168.0.243/nas/", "R:/", dirFromNode)
@@ -74,7 +74,7 @@ def browseDirByNode():
7474
else:
7575
dirFromNode_new = dirFromNode
7676

77-
print dirFromNode
77+
print (dirFromNode)
7878
# selectedNode['file'].setValue(dirFromNode_new)
7979

8080

python/ToolSet/switch_shot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ def import_project_pictures(self, project_dir, sep):
114114
try:
115115
self.import_pictures(sequence_dir, sep)
116116
except Exception as e:
117-
print '[AAs] error:', e
117+
print ('[AAs] error:'), e
118118
value += 1
119119
task.setMessage('Auto Read Successful')
120120
task.setProgress(100)
121121
else:
122-
print '[AAS info]: %s is not an exist folder' % project_dir
122+
print ('[AAS info]: %s is not an exist folder') % project_dir
123123

124124
def get_current_shot_options(self):
125125
all_paths = list()

python/cryptomatte/cryptomatte_utilities.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def setup_cryptomatte():
3535
import mmh3 as mmh3
3636
except ImportError:
3737
# ... otherwise fallback to the pure python version
38-
import pymmh3 as mmh3
38+
from . import pymmh3 as mmh3
3939

4040

4141
def mm3hash_float(name):
@@ -200,7 +200,7 @@ def _identify_channels(self, name):
200200
def resolve_manifest_paths(self, exr_path, sidecar_path):
201201
import os
202202
if "\\" in sidecar_path:
203-
print "Cryptomatte: Invalid sidecar path (Back-slashes not allowed): ", sidecar_path
203+
print ("Cryptomatte: Invalid sidecar path (Back-slashes not allowed): "), sidecar_path
204204
return "" # to enforce the specification.
205205
joined = os.path.join(os.path.dirname(exr_path), sidecar_path)
206206
return os.path.normpath(joined)
@@ -229,9 +229,9 @@ def parse_manifest(self):
229229
with open(manif_file) as json_data:
230230
manifest = json.load(json_data)
231231
except:
232-
print "Cryptomatte: Unable to parse manifest, ", manif_file
232+
print ("Cryptomatte: Unable to parse manifest, "), manif_file
233233
else:
234-
print "Cryptomatte: Unable to find manifest file: ", manif_file
234+
print ("Cryptomatte: Unable to find manifest file: "), manif_file
235235
else:
236236
try:
237237
manifest = json.loads(self.cryptomattes[num].get("manifest", "{}"))
@@ -299,22 +299,22 @@ def test_manifest(self):
299299
collisions.append("colliding: %s %s" % (ids[idvalue], name))
300300
ids[idvalue] = name
301301

302-
print "Tested %s, %s names" % (self.nuke_node.name(), len(manifest))
303-
print " ", len(errors), "non-matching IDs between python and c++."
304-
print " ", len(collisions), "hash collisions in manifest."
302+
print ("Tested %s, %s names") % (self.nuke_node.name(), len(manifest))
303+
print (" "), len(errors), "non-matching IDs between python and c++."
304+
print (" "), len(collisions), "hash collisions in manifest."
305305

306306
return errors, collisions
307307

308308

309309
def print_hash_info(name):
310310
hash_32 = mmh3.hash(name)
311-
print "Name:", name
312-
print "UTF-8 bytes:", " ".join( hex(ord(x))[2:] for x in name)
313-
print "Hash value (signed):", hash_32
311+
print ("Name:"), name
312+
print ("UTF-8 bytes:"), " ".join( hex(ord(x))[2:] for x in name)
313+
print ("Hash value (signed):"), hash_32
314314
if hash_32 < 0:
315315
hash_32 = (-hash_32 - 1) ^ 0xFFFFFFFF
316-
print "Hash value (unsigned):", hash_32
317-
print "Float converted:", mm3hash_float(name)
316+
print ("Hash value (unsigned):"), hash_32
317+
print ("Float converted:"), mm3hash_float(name)
318318

319319

320320
def test_csv_round_trip():
@@ -330,9 +330,9 @@ def test_csv_round_trip():
330330

331331
def check_results(encoded, decoded):
332332
if encoded != csv_str:
333-
print "list: ", decoded
334-
print "orig: ", csv_str
335-
print "encoded:", encoded
333+
print ("list: "), decoded
334+
print ("orig: "), csv_str
335+
print ("encoded:"), encoded
336336
raise RuntimeError("Round trip to str failed: %s != %s" % (csv_str, encoded));
337337
for x, y in zip(name_list, decoded):
338338
if x != y:
@@ -347,7 +347,7 @@ def check_results(encoded, decoded):
347347
encoded = _encode_csv(name_list)
348348
decoded = _decode_csv(encoded)
349349
check_results(encoded, decoded)
350-
print "Success."
350+
print ("Success.")
351351
return True
352352

353353

0 commit comments

Comments
 (0)