A small, circular node that passes a connection through and adopts the color of the data type.
| 19 | |
| 20 | |
| 21 | class RerouteNode(QGraphicsItem): |
| 22 | """ |
| 23 | A small, circular node that passes a connection through and |
| 24 | adopts the color of the data type. |
| 25 | """ |
| 26 | |
| 27 | def __init__(self, parent=None): |
| 28 | super().__init__(parent) |
| 29 | self.setFlag(QGraphicsItem.ItemIsMovable) |
| 30 | self.setFlag(QGraphicsItem.ItemIsSelectable) |
| 31 | self.setFlag(QGraphicsItem.ItemSendsGeometryChanges) |
| 32 | |
| 33 | self.uuid = str(uuid.uuid4()) |
| 34 | self.title = "Reroute" |
| 35 | self.radius = 8 |
| 36 | self.pins = [] |
| 37 | self.is_reroute = True # Mark this as a reroute node for special handling |
| 38 | |
| 39 | self.input_pin = self.add_pin("input", "input", "any") |
| 40 | self.output_pin = self.add_pin("output", "output", "any") |
| 41 | |
| 42 | self.input_pin.setPos(0, 0) |
| 43 | self.output_pin.setPos(0, 0) |
| 44 | |
| 45 | self.update_color() |
| 46 | |
| 47 | def update_color(self): |
| 48 | """Updates the node's color based on its input connection.""" |
| 49 | if self.input_pin.connections: |
| 50 | source_pin = self.input_pin.connections[0].start_pin |
| 51 | new_type = source_pin.pin_type |
| 52 | new_color = source_pin.color |
| 53 | else: |
| 54 | new_type = "any" |
| 55 | new_color = generate_color_from_string("any") |
| 56 | |
| 57 | self.color_base = new_color.darker(110) |
| 58 | self.color_highlight = new_color.lighter(110) |
| 59 | self.color_shadow = new_color.darker(140) |
| 60 | self.pen_default = QPen(self.color_shadow, 1.5) |
| 61 | self.pen_selected = QPen(new_color.lighter(150), 2.5) |
| 62 | |
| 63 | self.output_pin.pin_type = new_type |
| 64 | self.output_pin.color = new_color |
| 65 | |
| 66 | if self.scene(): |
| 67 | self.output_pin.update_connections() |
| 68 | self.update() |
| 69 | |
| 70 | def add_pin(self, name, direction, pin_type_str, pin_category="data"): |
| 71 | pin = Pin(self, name, direction, pin_type_str, pin_category) |
| 72 | pin.hide() |
| 73 | self.pins.append(pin) |
| 74 | return pin |
| 75 | |
| 76 | def get_pin_by_name(self, name): |
| 77 | if name == "input": |
| 78 | return self.input_pin |
no outgoing calls