Please revise upgrade and improve: import sys
from PyQt6 import QtWidgets, QtCore, QtGui

class NetworkComponent(QtWidgets.QGraphicsRectItem):
    def __init__(self, label, x, y, width=50, height=50):
        super().__init__(x, y, width, height)
        self.label = label
        self.setBrush(QtGui.QBrush(QtGui.QColor(0, 255, 0)))  # Green
        self.setPen(QtGui.QPen(QtGui.QColor(0, 0, 0)))  # Black
        self.setFlag(QtWidgets.QGraphicsItem.ItemIsMovable)
        self.setFlag(QtWidgets.QGraphicsItem.ItemIsSelectable)
        self.setAcceptHoverEvents(True)

    def hoverEnterEvent(self, event):
        self.setBrush(QtGui.QBrush(QtGui.QColor(255, 255, 0)))  # Yellow on hover
        super().hoverEnterEvent(event)

    def hoverLeaveEvent(self, event):
        self.setBrush(QtGui.QBrush(QtGui.QColor(0, 255, 0)))  # Back to green
        super().hoverLeaveEvent(event)

    def paint(self, painter, option, widget=None):
        super().paint(painter, option, widget)
        painter.drawText(self.boundingRect(), QtCore.Qt.AlignmentFlag.AlignCenter, self.label)


class NetworkCable(QtWidgets.QGraphicsLineItem):
    def __init__(self, start_item, end_item):
        super().__init__()
        self.start_item = start_item
        self.end_item = end_item
        self.setPen(QtGui.QPen(QtGui.QColor(0, 0, 0), 2))  # Black

    def update_position(self):
        start_pos = self.start_item.rect().center() + self.start_item.pos()
        end_pos = self.end_item.rect().center() + self.end_item.pos()
        self.setLine(QtCore.QLineF(start_pos, end_pos))


class NetworkGUI(QtWidgets.QMainWindow):
    def __init__(self):
        super().__init__()

        self.setWindowTitle("Network Configuration")
        self.setGeometry(100, 100, 800, 600)

        self.central_widget = QtWidgets.QWidget()
        self.setCentralWidget(self.central_widget)
        self.layout = QtWidgets.QVBoxLayout(self.central_widget)

        self.scene = QtWidgets.QGraphicsScene(self)
        self.view = QtWidgets.QGraphicsView(self.scene)
        self.layout.addWidget(self.view)

        self.components = {
            "erven": [],
            "centroids": [],
            "boundary_boxes": [],
            "drop_cables": [],
            "link_cables": [],
            "muc350": [],
            "splitters": []
        }

        self.init_ui()
        self.create_toolbox()
        self.create_initial_components()
        self.draw_connections()

    def init_ui(self):
        self.view.setRenderHint(QtGui.QPainter.RenderHint.Antialiasing)

    def create_toolbox(self):
        toolbox = QtWidgets.QDockWidget("Components", self)
        self.addDockWidget(QtCore.Qt.DockWidgetArea.RightDockWidgetArea, toolbox)

        toolbox_widget = QtWidgets.QWidget()
        toolbox_layout = QtWidgets.QVBoxLayout(toolbox_widget)

        # Add buttons for components
        self.add_component_button(toolbox_layout, "Add Erf", self.add_erven)
        self.add_component_button(toolbox_layout, "Add Centroid", self.add_centroid)
        self.add_component_button(toolbox_layout, "Add Boundary Box", self.add_boundary_box)
        self.add_component_button(toolbox_layout, "Add Drop Cable", self.add_drop_cable)
        self.add_component_button(toolbox_layout, "Add Link Cable", self.add_link_cable)
        self.add_component_button(toolbox_layout, "Add MUC350", self.add_muc350)
        self.add_component_button(toolbox_layout, "Add 1:16-way Splitter", self.add_splitter)

        toolbox.setWidget(toolbox_widget)

    def add_component_button(self, layout, label, callback):
        button = QtWidgets.QPushButton(label)
        button.clicked.connect(callback)
        layout.addWidget(button)

    def create_initial_components(self):
        # Create initial ervens and other components
        for i in range(8):
            erf = NetworkComponent(f"Erf {i+1}", 100 + i * 60, 100)
            self.scene.addItem(erf)
            self.components["erven"].append(erf)

        for i in range(8):
            centroid = NetworkComponent(f"Centroid {i+1}", 100 + i * 60, 125)
            self.scene.addItem(centroid)
            self.components["centroids"].append(centroid)

        # Create boundary boxes
        for i in range(4):
            boundary_box = NetworkComponent(f"BB {i+1}", 300 + i * 60, 100)
            self.scene.addItem(boundary_box)
            self.components["boundary_boxes"].append(boundary_box)

        # Create a central node
        self.central_node = NetworkComponent("Central Node", 400, 200, 60, 30)
        self.scene.addItem(self.central_node)

        # Create T-intersection line
        self.intersection_line = QtWidgets.QGraphicsLineItem(300, 300, 500, 300)
        self.intersection_line.setPen(QtGui.QPen(QtGui.QColor(255, 255, 255), 2))  # White
        self.scene.addItem(self.intersection_line)

    def add_erven(self):
        index = len(self.components["erven"]) + 1
        erf = NetworkComponent(f"Erf {index}", 100 + (index - 1) * 60, 100)
        self.scene.addItem(erf)
        self.components["erven"].append(erf)
        self.draw_connections()

    def add_centroid(self):
        index = len(self.components["centroids"]) + 1
        centroid = NetworkComponent(f"Centroid {index}", 100 + (index - 1) * 60, 125)
        self.scene.addItem(centroid)
        self.components["centroids"].append(centroid)
        self.draw_connections()

    def add_boundary_box(self):
        index = len(self.components["boundary_boxes"]) + 1
        boundary_box = NetworkComponent(f"BB {index}", 300 + (index - 1) * 60, 100)
        self.scene.addItem(boundary_box)
        self.components["boundary_boxes"].append(boundary_box)
        self.draw_connections()

    def add_drop_cable(self):
        index = len(self.components["drop_cables"]) + 1
        drop_cable = NetworkCable(self.components["erven"][-1], self.central_node)  # Connect to last erf
        self.scene.addItem(drop_cable)
        self.components["drop_cables"].append(drop_cable)
        drop_cable.update_position()  # Update position based on connected components

    def add_link_cable(self):
        index = len(self.components["link_cables"]) + 1
        link_cable = NetworkCable(self.central_node, self.components["centroids"][-1])  # Connect to last centroid
        self.scene.addItem(link_cable)
        self.components["link_cables"].append(link_cable)
        link_cable.update_position()  # Update position based on connected components

    def add_muc350(self):
        index = len(self.components["muc350"]) + 1
        muc350 = NetworkComponent(f"MUC350 {index}", 500, 150)
        self.scene.addItem(muc350)
        self.components["muc350"].append(muc350)
        self.draw_connections()

    def add_splitter(self):
        index = len(self.components["splitters"]) + 1
        splitter = NetworkComponent(f"1:16-way Splitter {index}", 600, 150)
        self.scene.addItem(splitter)
        self.components["splitters"].append(splitter)
        self.draw_connections()

    def draw_connections(self):
        self.scene.clear()
        # Redraw existing components
        for component in self.components["erven"]:
            self.scene.addItem(component)
        for component in self.components["centroids"]:
            self.scene.addItem(component)
        for component in self.components["boundary_boxes"]:
            self.scene.addItem(component)
        for component in self.components["drop_cables"]:
            self.scene.addItem(component)
        for component in self.components["link_cables"]:
            self.scene.addItem(component)
        for component in self.components["muc350"]:
            self.scene.addItem(component)
        for component in self.components["splitters"]:
            self.scene.addItem(component)

        self.scene.addItem(self.central_node)
        self.scene.addItem(self.intersection_line)

        # Update positions of cables
        for drop_cable in self.components["drop_cables"]:
            drop_cable.update_position()
        for link_cable in self.components["link_cables"]:
            link_cable.update_position()

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    window = NetworkGUI()
    window.show()
    sys.exit(app.exec())