EvalNode: add method to set code

This commit is contained in:
Luke Campagnola 2017-09-15 08:54:50 -07:00
parent 9d0779cc32
commit d081e54956

View File

@ -189,31 +189,36 @@ class EvalNode(Node):
self.ui = QtGui.QWidget() self.ui = QtGui.QWidget()
self.layout = QtGui.QGridLayout() self.layout = QtGui.QGridLayout()
#self.addInBtn = QtGui.QPushButton('+Input')
#self.addOutBtn = QtGui.QPushButton('+Output')
self.text = QtGui.QTextEdit() self.text = QtGui.QTextEdit()
self.text.setTabStopWidth(30) self.text.setTabStopWidth(30)
self.text.setPlainText("# Access inputs as args['input_name']\nreturn {'output': None} ## one key per output terminal") self.text.setPlainText("# Access inputs as args['input_name']\nreturn {'output': None} ## one key per output terminal")
#self.layout.addWidget(self.addInBtn, 0, 0)
#self.layout.addWidget(self.addOutBtn, 0, 1)
self.layout.addWidget(self.text, 1, 0, 1, 2) self.layout.addWidget(self.text, 1, 0, 1, 2)
self.ui.setLayout(self.layout) self.ui.setLayout(self.layout)
#QtCore.QObject.connect(self.addInBtn, QtCore.SIGNAL('clicked()'), self.addInput)
#self.addInBtn.clicked.connect(self.addInput)
#QtCore.QObject.connect(self.addOutBtn, QtCore.SIGNAL('clicked()'), self.addOutput)
#self.addOutBtn.clicked.connect(self.addOutput)
self.text.focusOutEvent = self.focusOutEvent self.text.focusOutEvent = self.focusOutEvent
self.lastText = None self.lastText = None
def ctrlWidget(self): def ctrlWidget(self):
return self.ui return self.ui
#def addInput(self): def setCode(self, code):
#Node.addInput(self, 'input', renamable=True) # unindent code; this allows nicer inline code specification when
# calling this method.
ind = []
lines = code.split('\n')
for line in lines:
stripped = line.lstrip()
if len(stripped) > 0:
ind.append(len(line) - len(stripped))
if len(ind) > 0:
ind = min(ind)
code = '\n'.join([line[ind:] for line in lines])
#def addOutput(self): self.text.clear()
#Node.addOutput(self, 'output', renamable=True) self.text.insertPlainText(code)
def code(self):
return self.text.toPlainText()
def focusOutEvent(self, ev): def focusOutEvent(self, ev):
text = str(self.text.toPlainText()) text = str(self.text.toPlainText())
@ -247,10 +252,10 @@ class EvalNode(Node):
def restoreState(self, state): def restoreState(self, state):
Node.restoreState(self, state) Node.restoreState(self, state)
self.text.clear() self.setCode(state['text'])
self.text.insertPlainText(state['text'])
self.restoreTerminals(state['terminals']) self.restoreTerminals(state['terminals'])
self.update() self.update()
class ColumnJoinNode(Node): class ColumnJoinNode(Node):
"""Concatenates record arrays and/or adds new columns""" """Concatenates record arrays and/or adds new columns"""