def main(app, connections, sizes): registry = qtpynodeeditor.DataModelRegistry() scene = qtpynodeeditor.FlowScene(registry=registry) view = qtpynodeeditor.FlowView(scene) view.setWindowTitle("Style example") view.resize(800, 600) shapes = { idx: QtWidgets.QLabel(f'{idx}: {connections[idx]}') for idx in range(len(sizes)) } for size, (idx, shape) in zip(sizes, shapes.items()): # shape.setFixedSize(size[0] * 10, size[1] * 10) # shape.setStyleSheet( # "border: 2px solid white; border-radius: 5px; background: transparent; color: red;") proxy = scene.addWidget(shape) shapes[idx] = proxy proxy.setPos(0, 0) root = build_tree(shapes, connections) layout(scene, root, root) remove_groups(scene, root) validate(scene, shapes) connect_widgets(scene, root) return scene, view, root
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]
def __init__(self, monitor, *, parent=None): super().__init__(parent=parent) self._edges_removed = [] self.monitor = monitor self.detector = monitor.detector self.monitor.update.connect(self._ports_updated) self.registry = qtpynodeeditor.DataModelRegistry() for ophyd_cls, model in data_model.models.items(): self.registry.register_model(model, category='Area Detector') self.scene = qtpynodeeditor.FlowScene( registry=self.registry, allow_node_deletion=False, allow_node_creation=False) self._connected_by_user = {} self.scene.connection_created.connect(self._user_connected_nodes) self.scene.connection_deleted.connect(self._user_deleted_connection) self.view = qtpynodeeditor.FlowView(self.scene) self.view.setMinimumSize(400, 400) self.layout = QtWidgets.QVBoxLayout() self.dock = QtWidgets.QDockWidget() self.layout.addWidget(self.view) self.setLayout(self.layout) self._nodes = {} self._edges = set() self._auto_position = True
def main(app): registry = nodeeditor.DataModelRegistry() models = (AdditionModel, DivisionModel, ModuloModel, MultiplicationModel, NumberSourceDataModel, SubtractionModel, NumberDisplayModel) for model in models: registry.register_model(model, category='Operations', style=None) registry.register_type_converter(DecimalData, IntegerData, decimal_to_integer_converter) registry.register_type_converter(IntegerData, DecimalData, decimal_to_integer_converter) scene = nodeeditor.FlowScene(registry=registry) view = nodeeditor.FlowView(scene) view.setWindowTitle("Calculator example") view.resize(800, 600) view.show() inputs = [] node_add = scene.create_node(AdditionModel) node_sub = scene.create_node(SubtractionModel) node_mul = scene.create_node(MultiplicationModel) node_div = scene.create_node(DivisionModel) node_mod = scene.create_node(ModuloModel) for node_operation in (node_add, node_sub, node_mul, node_div, node_mod): node_a = scene.create_node(NumberSourceDataModel) node_a.model.embedded_widget().setText('1.0') inputs.append(node_a) node_b = scene.create_node(NumberSourceDataModel) node_b.model.embedded_widget().setText('2.0') inputs.append(node_b) scene.create_connection( node_a[PortType.output][0], node_operation[PortType.input][0], ) scene.create_connection( node_a[PortType.output][0], node_operation[PortType.input][1], ) node_display = scene.create_node(NumberDisplayModel) scene.create_connection( node_operation[PortType.output][0], node_display[PortType.input][0], ) try: scene.auto_arrange(nodes=inputs, layout='bipartite') except ImportError: ... return scene, view, [node_a, node_b]
def main(app): style = StyleCollection.from_json(style_json) registry = qtpynodeeditor.DataModelRegistry() registry.register_model(MyDataModel, category='My Category', style=style) scene = qtpynodeeditor.FlowScene(style=style, registry=registry) view = qtpynodeeditor.FlowView(scene) view.setWindowTitle("Style example") view.resize(800, 600) node = scene.create_node(MyDataModel) return scene, view, [node]
def main(app): registry = qtpynodeeditor.DataModelRegistry() registry.register_model(ImageShowModel, category='My Category') registry.register_model(ImageLoaderModel, category='My Category') scene = qtpynodeeditor.FlowScene(registry=registry) view = qtpynodeeditor.FlowView(scene) view.setWindowTitle("Image example") view.resize(800, 600) node_loader = scene.create_node(ImageLoaderModel) node_show = scene.create_node(ImageShowModel) scene.create_connection( node_loader[PortType.output][0], node_show[PortType.input][0], ) return scene, view, [node_loader, node_show]
def main(app, init_style): # Load style, if an initial style is wanted if init_style: with open(init_style) as f: json_style = json.load(f) style = StyleCollection.from_json(json_style) else: style = None # Create registry, to register possible node types registry = nodeeditor.DataModelRegistry() # Add node models to registry models = [XORModel, ADDModel, SUBModel, MULModel, DIVModel, MODModel] # IOModels io_models = [RGBInModel, RGBOutModel] for model in models: registry.register_model(model, category="Arithmetics", style=style) for model in io_models: registry.register_model(model, category="IO", style=style) scene = nodeeditor.FlowScene(style=style, registry=registry) view = nodeeditor.FlowView(scene) view.setWindowTitle("Grim") view.resize(1000, 750) view.show() return scene, view
def scene(qapp, registry): return nodeeditor.FlowScene(registry=registry)