|
13 | 13 |
|
14 | 14 | log = logging.getLogger(__name__) |
15 | 15 |
|
| 16 | +self = sys.modules[__name__] |
| 17 | +self._parent = None # Main Window cache |
| 18 | + |
16 | 19 | AVALON_CONFIG = os.environ["AVALON_CONFIG"] |
17 | 20 |
|
18 | 21 |
|
@@ -76,6 +79,18 @@ def containerise(node, |
76 | 79 | node (obj): containerised nuke's node object |
77 | 80 |
|
78 | 81 | """ |
| 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 | + ) |
79 | 94 |
|
80 | 95 | data_imprint = OrderedDict({ |
81 | 96 | "schema": "avalon-core:container-2.0", |
@@ -126,34 +141,30 @@ def parse_container(node, validate=True): |
126 | 141 |
|
127 | 142 | # Store the node's name |
128 | 143 | container["objectName"] = node["name"].value() |
129 | | - |
130 | 144 | # Store reference to the node object |
131 | 145 | container["_node"] = node |
132 | 146 |
|
133 | 147 | return container |
134 | 148 |
|
135 | 149 |
|
136 | | -def update_container(node, keys=dict()): |
| 150 | +def update_container(node, keys=None): |
137 | 151 | """Returns node with updateted containder data |
138 | 152 |
|
139 | 153 | Arguments: |
140 | | - node (object): The node in Nuke to imprint as container, |
141 | | - keys (dict): data which should be updated |
| 154 | + node (nuke.Node): The node in Nuke to imprint as container, |
| 155 | + keys (dict, optional): data which should be updated |
142 | 156 |
|
143 | 157 | Returns: |
144 | | - node (object): nuke node with updated container data |
145 | | - """ |
| 158 | + node (nuke.Node): nuke node with updated container data |
146 | 159 |
|
147 | 160 | data = lib.get_avalon_knob_data(node) |
148 | 161 |
|
149 | 162 | container = dict() |
150 | 163 | container = {key: data[key] for key in data} |
151 | 164 |
|
152 | | - for key, value in container.items(): |
153 | | - try: |
154 | | - container[key] = keys[key] |
155 | | - except KeyError: |
156 | | - pass |
| 165 | + container = parse_container(node) |
| 166 | + if not container: |
| 167 | + raise TypeError("Not a valid container node.") |
157 | 168 |
|
158 | 169 | node = lib.set_avalon_knob_data(node, container) |
159 | 170 |
|
@@ -272,6 +283,18 @@ def find_host_config(config): |
272 | 283 | return config |
273 | 284 |
|
274 | 285 |
|
| 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 | +
|
275 | 298 | def uninstall(config): |
276 | 299 | """Uninstall all that was previously installed |
277 | 300 |
|
@@ -312,13 +335,26 @@ def _install_menu(): |
312 | 335 | api.Session["AVALON_ASSET"], api.Session["AVALON_TASK"] |
313 | 336 | ) |
314 | 337 | context_menu = menu.addMenu(label) |
315 | | - context_menu.addCommand("Set Context", contextmanager.show) |
| 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())) |
316 | 352 |
|
317 | 353 | menu.addSeparator() |
318 | 354 | menu.addCommand("Work Files...", |
319 | 355 | lambda: workfiles.show( |
320 | | - os.environ["AVALON_WORKDIR"] |
321 | | - ) |
| 356 | + os.environ["AVALON_WORKDIR"], |
| 357 | + parent=get_main_window()) |
322 | 358 | ) |
323 | 359 | menu.addSeparator() |
324 | 360 | menu.addCommand("Create...", creator.show) |
|
0 commit comments