本文整理汇总了Python中pyqtgraph.flowchart.Node.restoreState方法的典型用法代码示例。如果您正苦于以下问题:Python Node.restoreState方法的具体用法?Python Node.restoreState怎么用?Python Node.restoreState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyqtgraph.flowchart.Node
的用法示例。
在下文中一共展示了Node.restoreState方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Flowchart
# 需要导入模块: from pyqtgraph.flowchart import Node [as 别名]
# 或者: from pyqtgraph.flowchart.Node import restoreState [as 别名]
#.........这里部分代码省略.........
def listConnections(self):
conn = set()
for n in self._nodes.values():
terms = n.outputs()
for n, t in terms.items():
for c in t.connections():
conn.add((t, c))
return conn
def saveState(self):
state = Node.saveState(self)
state['nodes'] = []
state['connects'] = []
#state['terminals'] = self.saveTerminals()
for name, node in self._nodes.items():
cls = type(node)
if hasattr(cls, 'nodeName'):
clsName = cls.nodeName
pos = node.graphicsItem().pos()
ns = {'class': clsName, 'name': name, 'pos': (pos.x(), pos.y()), 'state': node.saveState()}
state['nodes'].append(ns)
conn = self.listConnections()
for a, b in conn:
state['connects'].append((a.node().name(), a.name(), b.node().name(), b.name()))
state['inputNode'] = self.inputNode.saveState()
state['outputNode'] = self.outputNode.saveState()
return state
def restoreState(self, state, clear=False):
self.blockSignals(True)
try:
if clear:
self.clear()
Node.restoreState(self, state)
nodes = state['nodes']
nodes.sort(lambda a, b: cmp(a['pos'][0], b['pos'][0]))
for n in nodes:
if n['name'] in self._nodes:
#self._nodes[n['name']].graphicsItem().moveBy(*n['pos'])
self._nodes[n['name']].restoreState(n['state'])
continue
try:
node = self.createNode(n['class'], name=n['name'])
node.restoreState(n['state'])
except:
printExc("Error creating node %s: (continuing anyway)" % n['name'])
#node.graphicsItem().moveBy(*n['pos'])
self.inputNode.restoreState(state.get('inputNode', {}))
self.outputNode.restoreState(state.get('outputNode', {}))
#self.restoreTerminals(state['terminals'])
for n1, t1, n2, t2 in state['connects']:
try:
self.connectTerminals(self._nodes[n1][t1], self._nodes[n2][t2])
except:
print(self._nodes[n1].terminals)
print(self._nodes[n2].terminals)
printExc("Error connecting terminals %s.%s - %s.%s:" % (n1, t1, n2, t2))
示例2: restoreState
# 需要导入模块: from pyqtgraph.flowchart import Node [as 别名]
# 或者: from pyqtgraph.flowchart.Node import restoreState [as 别名]
def restoreState(self, state):
Node.restoreState(self, state)
if self.stateGroup is not None:
self.stateGroup.setState(state.get('ctrl', {}))