-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathedresponse.py
135 lines (114 loc) · 4.72 KB
/
edresponse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# editor responser
from nged import ImGui, Node
from nged.msghub import trace
from node import MyNode
from dataview import DataView
from nodelib import IONode, InputNode, OutputNode, SubgraphNode, FunctionInputNode, DefineFunction
from evaluation import getContext
def beforeItemRemoved(graph, item):
if isinstance(item, IONode) and item.type in ('input', 'function_input', 'output'):
return False
else:
return True
def beforeItemAdded(graph, item):
if isinstance(item, InputNode) or isinstance(item, FunctionInputNode):
if item.nthInput >= graph.numinputs:
return False
if item.nthInput < len(graph.inputnodes) \
and graph.inputnodes[item.nthInput]:
return graph.inputnodes[item.nthInput] # replacement
elif isinstance(item, OutputNode) and graph.outputnode is not None:
return graph.outputnode
else:
return True
def afterItemAdded(graph, item):
if isinstance(item, Node):
getContext(graph).addDirtySource(item.id)
def onParmModified(node, parms):
f = getattr(node, 'onParmModified', None)
if f:
f(parms)
getContext(node.graph).addDirtySource(node.id)
def onInspect(view, items):
theOnlyNode = None
hasOnlyOneNode = True
for item in items:
if isinstance(item, MyNode):
if theOnlyNode is not None:
hasOnlyOneNode = False
else:
theOnlyNode = item
if hasOnlyOneNode and theOnlyNode is not None:
size = ImGui.GetContentRegionAvail()
ImGui.Dummy(size)
if hasattr(theOnlyNode, 'editingExtraParms'):
if ImGui.CollapsingHeader('Extra Parms'):
ImGui.PushItemWidth(-8)
ImGui.PushMonoFont()
modified, text = ImGui.InputTextMultiline(
'##ParmScript', theOnlyNode.editingExtraParms)
theOnlyNode.editingExtraParms = text
if ImGui.Button('Apply'):
theOnlyNode.setExtraParms(theOnlyNode.editingExtraParms)
ImGui.Dummy(ImGui.ImVec2(20, 20))
ImGui.Text(
"/* See https://github.com/hugeproblem/parmscript\n for details about the syntax */")
ImGui.PopFont()
ImGui.PopItemWidth()
def onSelectionChanged(view):
for otherview in view.editor.views():
if otherview == view:
continue
if otherview.kind == 'data':
assert isinstance(otherview, DataView)
otherview.handleSelectionChangeEvent(view)
def onLinkModified(link):
ctx = getContext(link.graph)
ctx.topoDirty = True
itemid = link.targetItem
ctx.addDirtySource(itemid)
item = link.graph.get(itemid)
if isinstance(item, SubgraphNode):
inputnodes = item.subgraph.inputnodes
inputnode = inputnodes[link.targetPin] \
if link.targetPin >= 0 and link.targetPin < len(inputnodes) \
else None
if inputnode:
trace(
f'marking subgraph input{link.targetPin} ({inputnode}) dirty')
ctx.addDirtySource(inputnode.id)
def resolveInputOutput(graph):
graph.inputnodes = [None] * graph.numinputs
graph.outputnode = None
for item in graph.items():
if isinstance(item, InputNode) or isinstance(item, FunctionInputNode):
assert item.nthInput >= 0 and item.nthInput < graph.numinputs,\
f'input {item.nthInput} out of range [0, {graph.numinputs})'
assert graph.inputnodes[item.nthInput] is None,\
f'input {item.nthInput} already set'
graph.inputnodes[item.nthInput] = item
trace(f'fount new input {item.nthInput} for graph: {item.uid}')
elif isinstance(item, OutputNode):
assert graph.outputnode is None, 'output node already set'
graph.outputnode = item
trace(f'found new output for graph: {item.uid}')
elif isinstance(item, Node):
subgraph = item.asGraph()
if subgraph:
subgraph.resolveInputOutput()
def afterPaste(graph, items):
for item in items:
if isinstance(item, Node):
graph = item.asGraph()
if graph:
resolveInputOutput(graph)
def setupCallbacks(editor):
editor.setOnSelectionChangedCallback(onSelectionChanged)
editor.setBeforeItemRemovedCallback(beforeItemRemoved)
editor.setBeforeItemAddedCallback(beforeItemAdded)
editor.setAfterItemAddedCallback(afterItemAdded)
editor.setOnLinkSetCallback(onLinkModified)
editor.setOnLinkRemovedCallback(onLinkModified)
editor.setOnInspectCallback(onInspect)
editor.setAfterPasteCallback(afterPaste)
editor.setParmModifiedCallback(onParmModified)