Skip to content
This repository was archived by the owner on Oct 10, 2024. It is now read-only.

Commit 95250b3

Browse files
committed
nuke master merge fixes
1 parent 235785b commit 95250b3

File tree

3 files changed

+27
-124
lines changed

3 files changed

+27
-124
lines changed

avalon/nuke/__init__.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from .lib import (
88
add_publish_knob,
9+
ls_img_sequence,
910
maintained_selection,
1011
get_node_path,
1112
get_avalon_knob_data,
@@ -51,13 +52,6 @@
5152

5253
"Creator",
5354

54-
"file_extensions",
55-
"has_unsaved_changes",
56-
"save_file",
57-
"open_file",
58-
"current_file",
59-
"work_root",
60-
6155
"containerise",
6256
"parse_container",
6357
"update_container",
@@ -70,8 +64,17 @@
7064
"get_avalon_knob_data",
7165
"set_avalon_knob_data",
7266
"add_publish_knob",
67+
"ls_img_sequence",
7368
"maintained_selection",
7469
"get_node_path",
70+
71+
# Workfiles API
72+
"open_file",
73+
"save_file",
74+
"current_file",
75+
"has_unsaved_changes",
76+
"file_extensions",
77+
"work_root"
7578
]
7679

7780
# Backwards API compatibility

avalon/nuke/lib.py

Lines changed: 3 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ def reset_selection():
4747
"""
4848
clear_selection_recursive()
4949

50-
Parse user data into Node knobs.
51-
Use `collections.OrderedDict` to ensure knob order.
5250

5351
def select_nodes(nodes):
5452
"""Selects all inputed nodes
@@ -82,46 +80,6 @@ def add_publish_knob(node):
8280
node.addKnob(knob)
8381
return node
8482

85-
Returns:
86-
None
87-
88-
Examples:
89-
```
90-
import nuke
91-
from avalon.nuke import lib
92-
93-
node = nuke.createNode("NoOp")
94-
data = {
95-
# Regular type of attributes
96-
"myList": ["x", "y", "z"],
97-
"myBool": True,
98-
"myFloat": 0.1,
99-
"myInt": 5,
100-
101-
# Creating non-default imprint type of knob
102-
"MyFilePath": lib.Knobby("File_Knob", "/file/path"),
103-
"divider": lib.Knobby("Text_Knob", ""),
104-
105-
# Manual nice knob naming
106-
("my_knob", "Nice Knob Name"): "some text",
107-
108-
# dict type will be created as knob group
109-
"KnobGroup": {
110-
"knob1": 5,
111-
"knob2": "hello",
112-
"knob3": ["a", "b"],
113-
},
114-
115-
# Nested dict will be created as tab group
116-
"TabGroup": {
117-
"tab1": {"count": 5},
118-
"tab2": {"isGood": True},
119-
"tab3": {"direction": ["Left", "Right"]},
120-
},
121-
}
122-
lib.imprint(node, data, tab="Demo")
123-
124-
```
12583

12684
def set_avalon_knob_data(node, data={}, prefix="ak:"):
12785
""" Sets a data into nodes's avalon knob
@@ -268,13 +226,9 @@ def check_subsetname_exists(nodes, subset_name):
268226
return result
269227

270228

271-
class Knobby(object):
272-
"""For creating knob which it's type isn't mapped in `create_knobs`
273-
274-
Args:
275-
type (string): Nuke knob type name
276-
value: Value to be set with `Knob.setValue`, put `None` if not required
277-
*args: Args other than knob name for initializing knob class
229+
def imprint(node, data):
230+
"""Adding `Avalon data` into a node's Avalon Tab/Avalon knob
231+
also including publish knob
278232
279233
Arguments:
280234
node (obj): A nuke's node object
@@ -330,24 +284,6 @@ def ls_img_sequence(path):
330284
return False
331285

332286

333-
def get_avalon_knob_data(node, prefix="avalon:"):
334-
""" Get data from nodes's avalon knob
335-
336-
Arguments:
337-
node (nuke.Node): Nuke node to search for data,
338-
prefix (str, optional): filtering prefix
339-
340-
Returns:
341-
data (dict)
342-
"""
343-
data = {
344-
knob[len(prefix):]: node[knob].value()
345-
for knob in node.knobs().keys()
346-
if knob.startswith(prefix)
347-
}
348-
return data
349-
350-
351287
def fix_data_for_node_create(data):
352288
"""Fixing data to be used for nuke knobs
353289
"""

avalon/nuke/pipeline.py

Lines changed: 14 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313

1414
log = logging.getLogger(__name__)
1515

16-
self = sys.modules[__name__]
17-
self._parent = None # Main Window cache
18-
1916
AVALON_CONFIG = os.environ["AVALON_CONFIG"]
2017

2118

@@ -79,18 +76,6 @@ def containerise(node,
7976
node (obj): containerised nuke's node object
8077
8178
"""
82-
data = OrderedDict(
83-
[
84-
("schema", "avalon-core:container-2.0"),
85-
("id", AVALON_CONTAINER_ID),
86-
("name", name),
87-
("namespace", namespace),
88-
("loader", str(loader)),
89-
("representation", context["representation"]["_id"]),
90-
],
91-
92-
**data or dict()
93-
)
9479

9580
data_imprint = OrderedDict({
9681
"schema": "avalon-core:container-2.0",
@@ -141,30 +126,34 @@ def parse_container(node, validate=True):
141126

142127
# Store the node's name
143128
container["objectName"] = node["name"].value()
129+
144130
# Store reference to the node object
145131
container["_node"] = node
146132

147133
return container
148134

149135

150-
def update_container(node, keys=None):
136+
def update_container(node, keys=dict()):
151137
"""Returns node with updateted containder data
152138
153139
Arguments:
154-
node (nuke.Node): The node in Nuke to imprint as container,
155-
keys (dict, optional): data which should be updated
140+
node (object): The node in Nuke to imprint as container,
141+
keys (dict): data which should be updated
156142
157143
Returns:
158-
node (nuke.Node): nuke node with updated container data
144+
node (object): nuke node with updated container data
145+
"""
159146

160147
data = lib.get_avalon_knob_data(node)
161148

162149
container = dict()
163150
container = {key: data[key] for key in data}
164151

165-
container = parse_container(node)
166-
if not container:
167-
raise TypeError("Not a valid container node.")
152+
for key, value in container.items():
153+
try:
154+
container[key] = keys[key]
155+
except KeyError:
156+
pass
168157

169158
node = lib.set_avalon_knob_data(node, container)
170159

@@ -283,18 +272,6 @@ def find_host_config(config):
283272
return config
284273

285274

286-
def get_main_window():
287-
"""Acquire Nuke's main window"""
288-
if self._parent is None:
289-
top_widgets = QtWidgets.QApplication.topLevelWidgets()
290-
name = "Foundry::UI::DockMainWindow"
291-
main_window = next(widget for widget in top_widgets if
292-
widget.inherits("QMainWindow") and
293-
widget.metaObject().className() == name)
294-
self._parent = main_window
295-
return self._parent
296-
297-
298275
def uninstall(config):
299276
"""Uninstall all that was previously installed
300277
@@ -335,26 +312,13 @@ def _install_menu():
335312
api.Session["AVALON_ASSET"], api.Session["AVALON_TASK"]
336313
)
337314
context_menu = menu.addMenu(label)
338-
context_menu.addCommand("Set Context",
339-
lambda: contextmanager.show(
340-
parent=get_main_window())
341-
)
342-
menu.addSeparator()
343-
menu.addCommand("Create...",
344-
lambda: creator.show(parent=get_main_window()))
345-
menu.addCommand("Load...",
346-
lambda: loader.show(parent=get_main_window(),
347-
use_context=True))
348-
menu.addCommand("Publish...",
349-
lambda: publish.show(parent=get_main_window()))
350-
menu.addCommand("Manage...",
351-
lambda: sceneinventory.show(parent=get_main_window()))
315+
context_menu.addCommand("Set Context", contextmanager.show)
352316

353317
menu.addSeparator()
354318
menu.addCommand("Work Files...",
355319
lambda: workfiles.show(
356-
os.environ["AVALON_WORKDIR"],
357-
parent=get_main_window())
320+
os.environ["AVALON_WORKDIR"]
321+
)
358322
)
359323
menu.addSeparator()
360324
menu.addCommand("Create...", creator.show)

0 commit comments

Comments
 (0)