Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,6 @@ dmypy.json

# Intermediate Markdown generated from the README for the User Guide PDF
docs/.build/

# Local profiling harness (lives on the profiling-harness branch)
.profiling/
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,9 @@ If this bothers you, enable **Always Show All Labels** in the preferences. Nodes

## Performance

Labelmaker has been used on production scripts of substantial size without issue. The autolabel routine runs as a low-priority idle process. If you do encounter performance problems, please open a GitHub issue and include the approximate node count and any node class that seems to be the culprit.
Labelmaker has been used on production scripts of substantial size without issue. Two things keep it responsive on large scripts:

- Nuke periodically asks for every node's label again even though nothing changed (after connecting a Viewer, for example). Labelmaker answers those passes from a cache instead of rebuilding each label.
- Every time a node's label text changes, Nuke re-lays out the whole Node Graph, which on a 10 000-node script takes a noticeable fraction of a second. Labelmaker therefore never updates label text *while* you are dragging a slider or scrubbing the timeline: the readouts catch up once you pause (about half a second; a little longer on very large scripts). Labels that were answered from the cache are re-checked in the background afterwards, so anything else that changes many labels at once — a script or tool editing every selected node, say — is caught up the same way. Nodes you edit indirectly (through an expression link, or by wiring a mask input) update the next time Nuke asks for their label, as does any TCL or `[python …]` in a node's *label* knob: that code runs only when Nuke asks for the label for real (once, as it does without Labelmaker), never during the background re-check, so a label whose only change is what its TCL now evaluates to catches up on the next real request.

If you do encounter performance problems, please open a GitHub issue and include the approximate node count and any node class that seems to be the culprit.
Binary file modified docs/user-guide.pdf
Binary file not shown.
403 changes: 381 additions & 22 deletions labelmaker.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions labelmaker_config_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ def _on_save(self):
labelmaker.autolabeller_singleton.config = (
labelmaker_config.composed_config_singleton
)
labelmaker.autolabeller_singleton.refresh_all_labels()

saved_layer_name = self._layer_name
saved_class = self._current_class
Expand Down
24 changes: 13 additions & 11 deletions labelmaker_deoverlap.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def deoverlap_from_nodes(source_node_names):

for node_name in sorted_node_names:
node_bbox = position_cache[node_name]
max_pusher_bottom = None
pushers = []
for pusher_name in dirty_names:
if pusher_name == node_name:
continue
Expand All @@ -76,17 +76,19 @@ def deoverlap_from_nodes(source_node_names):
# No actual overlap: the pusher's bottom is above this node.
if pusher_bbox[3] < node_bbox[1]:
continue
# No actual overlap: the pusher was pushed entirely below
# this node earlier in the sweep.
if pusher_bbox[1] > node_bbox[3]:
continue
if max_pusher_bottom is None or pusher_bbox[3] > max_pusher_bottom:
max_pusher_bottom = pusher_bbox[3]

if max_pusher_bottom is None:
continue
pushers.append((pusher_bbox[1], pusher_bbox[3]))

# Pushers are taken top-down against where the node will land,
# not where it started: a pusher already pushed entirely below
# the node's original slot still pushes it if the other pushers
# would land the node on top of it.
height = node_bbox[3] - node_bbox[1]
required_top = node_bbox[1]
for pusher_top, pusher_bottom in sorted(pushers):
if pusher_top > required_top + height:
break
required_top = max(required_top, pusher_bottom + MINIMUM_GAP)

required_top = max_pusher_bottom + MINIMUM_GAP
if required_top > node_bbox[1]:
push_amount = required_top - node_bbox[1]
node_bbox[1] += push_amount
Expand Down
31 changes: 26 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@


class _StubUndoManager:
def __init__(self):
self.depth = 0
self.calls = []

def disable(self):
pass
self.calls.append("disable")
self.depth += 1

def enable(self):
pass
self.calls.append("enable")
self.depth = max(0, self.depth - 1)

def disabled(self):
return self.depth > 0


class _StubMenu:
Expand All @@ -30,9 +39,16 @@ class _StubMenuItem:
_nuke_stub.warning = lambda msg: None
_nuke_stub.addAutolabel = lambda fn: None
_nuke_stub.removeAutolabel = lambda fn: None
_nuke_stub.allNodes = lambda: []
_nuke_stub.allNodes = lambda recurseGroups=False: []
_nuke_stub.thisNode = lambda: None
_nuke_stub.expression = lambda expr: 0
_nuke_stub.toNode = lambda name: None
_nuke_stub.frame = lambda: 1
_nuke_stub.activeViewer = lambda: None
_nuke_stub.addOnCreate = lambda fn: None
_nuke_stub.removeOnCreate = lambda fn: None
_nuke_stub.addOnDestroy = lambda fn: None
_nuke_stub.removeOnDestroy = lambda fn: None
_nuke_stub.expression = lambda expr: 0.0
_nuke_stub.numvalue = lambda knob, default=0: default
_nuke_stub.knob = lambda path, value=None: None
_nuke_stub.value = lambda path, default="": default
Expand Down Expand Up @@ -99,7 +115,7 @@ def setSingleShot(self, value):
def setInterval(self, value):
pass

def start(self):
def start(self, interval=None):
pass


Expand Down Expand Up @@ -131,6 +147,11 @@ def start(self):
sys.modules["PySide6.QtGui"] = _qtgui


@pytest.fixture(autouse=True)
def _reset_undo_stub():
_nuke_stub.Undo = _StubUndoManager()


@pytest.fixture
def tmp_prefs_file(tmp_path):
return str(tmp_path / "labelmaker_prefs.json")
Expand Down
9 changes: 9 additions & 0 deletions tests/stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def getValue(self):
def Class(self):
return self._class

def setValue(self, value):
self._value = value


class StubNode:
def __init__(self, class_name, knobs=None, xpos=0, ypos=0, width=80, height=28):
Expand Down Expand Up @@ -62,5 +65,11 @@ def name(self):
return name_knob.value()
return self._class

def fullName(self):
return self.name()

def knob(self, knob_name):
return self._knobs.get(knob_name)

def setYpos(self, value):
self._ypos = value
118 changes: 117 additions & 1 deletion tests/test_deoverlap.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@

from labelmaker_deoverlap import MINIMUM_GAP, _bboxes_overlap, _bboxes_overlap_horizontally
import nuke

from labelmaker_deoverlap import (
MINIMUM_GAP,
_bboxes_overlap,
_bboxes_overlap_horizontally,
deoverlap_from_nodes,
)

# --- _bboxes_overlap ---
# bbox format: [left, top, right, bottom]
Expand Down Expand Up @@ -86,3 +93,112 @@ def test_horizontal_overlap_ignores_y():

def test_minimum_gap_is_positive():
assert MINIMUM_GAP > 0


# --- deoverlap_from_nodes ---


class _FakeNode:
def __init__(self, name, x, y, width, height, node_class="Blur"):
self._name = name
self._x = x
self._y = y
self._width = width
self._height = height
self._class = node_class

def name(self):
return self._name

def Class(self):
return self._class

def xpos(self):
return self._x

def ypos(self):
return self._y

def screenWidth(self):
return self._width

def screenHeight(self):
return self._height

def setYpos(self, y):
self._y = y

def set_height(self, height):
self._height = height


def _bbox(node):
return [
node.xpos(),
node.ypos(),
node.xpos() + node.screenWidth(),
node.ypos() + node.screenHeight(),
]


def _no_overlaps(nodes):
return all(
not _bboxes_overlap(_bbox(a), _bbox(b))
for i, a in enumerate(nodes)
for b in nodes[i + 1:]
)


def test_cascade_does_not_land_a_short_node_on_the_last_pusher(monkeypatch):
grown = [_FakeNode(f"grown_{i}", 0, i * 90, 100, 110) for i in range(8)]
dot = _FakeNode("dot", 0, 720, 100, 12, node_class="Dot")
nodes = grown + [dot]
monkeypatch.setattr(nuke, "allNodes", lambda: nodes)

deoverlap_from_nodes([n.name() for n in grown])

assert _no_overlaps(nodes)
last = grown[-1]
assert dot.ypos() == last.ypos() + last.screenHeight() + MINIMUM_GAP


def test_two_fires_leave_no_overlap(monkeypatch):
nodes = [_FakeNode(f"n{i}", 0, i * 90, 100, 30) for i in range(8)]
monkeypatch.setattr(nuke, "allNodes", lambda: nodes)

for node in nodes[:4]:
node.set_height(110)
deoverlap_from_nodes([n.name() for n in nodes[:4]])

for node in nodes[4:]:
node.set_height(110)
deoverlap_from_nodes([n.name() for n in nodes[4:]])

assert _no_overlaps(nodes)


def test_pusher_that_jumped_past_a_bystander_leaves_it_alone(monkeypatch):
pusher = _FakeNode("P", 0, 0, 50, 200)
wide = _FakeNode("X", 0, 10, 300, 20)
dot = _FakeNode("Dot", 100, 50, 50, 10)
nodes = [pusher, wide, dot]
monkeypatch.setattr(nuke, "allNodes", lambda: nodes)

deoverlap_from_nodes(["P"])

assert dot.ypos() == 50


def test_side_by_side_and_preexisting_overlaps_untouched(monkeypatch):
grown = _FakeNode("G", 0, 0, 50, 110)
side = _FakeNode("Side", 200, 20, 50, 50)
a = _FakeNode("A", 500, 1000, 50, 50)
b = _FakeNode("B", 500, 1020, 50, 50)
nodes = [grown, side, a, b]
monkeypatch.setattr(nuke, "allNodes", lambda: nodes)

deoverlap_from_nodes(["G"])

assert side.ypos() == 20
assert a.ypos() == 1000
assert b.ypos() == 1020
Loading
Loading