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
|
import logging
from qtpy import QtWidgets
import qtpynodeeditor
from qtpynodeeditor import NodeData, NodeDataModel, NodeDataType, PortType
class MyNodeData(NodeData):
data_type = NodeDataType(id='MyNodeData', name='My Node Data')
class SimpleNodeData(NodeData):
data_type = NodeDataType(id='SimpleData', name='Simple Data')
class NaiveDataModel(NodeDataModel):
name = 'NaiveDataModel'
caption = 'Caption'
caption_visible = True
num_ports = {PortType.input: 2,
PortType.output: 2,
}
data_type = {
PortType.input: {
0: MyNodeData.data_type,
1: SimpleNodeData.data_type
},
PortType.output: {
0: MyNodeData.data_type,
1: SimpleNodeData.data_type
},
}
def out_data(self, port_index):
if port_index == 0:
return MyNodeData()
elif port_index == 1:
return SimpleNodeData()
def set_in_data(self, node_data, port):
...
def embedded_widget(self):
...
def main(app):
registry = qtpynodeeditor.DataModelRegistry()
registry.register_model(NaiveDataModel, category='My Category')
scene = qtpynodeeditor.FlowScene(registry=registry)
connection_style = scene.style_collection.connection
# Configure the style collection to use colors based on data types:
connection_style.use_data_defined_colors = True
view = qtpynodeeditor.FlowView(scene)
view.setWindowTitle("Connection (data-defined) color example")
view.resize(800, 600)
node_a = scene.create_node(NaiveDataModel)
node_b = scene.create_node(NaiveDataModel)
scene.create_connection(node_a[PortType.output][0],
node_b[PortType.input][0],
)
scene.create_connection(node_a[PortType.output][1],
node_b[PortType.input][1],
)
return scene, view, [node_a, node_b]
if __name__ == '__main__':
logging.basicConfig(level='DEBUG')
app = QtWidgets.QApplication([])
scene, view, nodes = main(app)
view.show()
app.exec_()
|