Merge pull request #117 from onlyjus/feature-resizeFlowchartNode

Feature: Flow chart nodes resize based on inputs/outputs
This commit is contained in:
Ogi Moore 2020-06-22 22:49:15 -07:00 committed by GitHub
commit 55e89bccef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -510,31 +510,41 @@ class NodeGraphicsItem(GraphicsObject):
def updateTerminals(self): def updateTerminals(self):
bounds = self.bounds
self.terminals = {} self.terminals = {}
inp = self.node.inputs() inp = self.node.inputs()
dy = bounds.height() / (len(inp)+1) out = self.node.outputs()
y = dy
maxNode = max(len(inp), len(out))
titleOffset = 25
nodeOffset = 12
# calculate new height
newHeight = titleOffset+maxNode*nodeOffset
# if current height is not equal to new height, update
if not self.bounds.height() == newHeight:
self.bounds.setHeight(newHeight)
self.update()
# Populate inputs
y = titleOffset
for i, t in inp.items(): for i, t in inp.items():
item = t.graphicsItem() item = t.graphicsItem()
item.setParentItem(self) item.setParentItem(self)
#item.setZValue(self.zValue()+1) #item.setZValue(self.zValue()+1)
br = self.bounds
item.setAnchor(0, y) item.setAnchor(0, y)
self.terminals[i] = (t, item) self.terminals[i] = (t, item)
y += dy y += nodeOffset
out = self.node.outputs() # Populate inputs
dy = bounds.height() / (len(out)+1) y = titleOffset
y = dy
for i, t in out.items(): for i, t in out.items():
item = t.graphicsItem() item = t.graphicsItem()
item.setParentItem(self) item.setParentItem(self)
item.setZValue(self.zValue()) item.setZValue(self.zValue())
br = self.bounds item.setAnchor(self.bounds.width(), y)
item.setAnchor(bounds.width(), y)
self.terminals[i] = (t, item) self.terminals[i] = (t, item)
y += dy y += nodeOffset
#self.buildMenu() #self.buildMenu()