Ejemplo n.º 1
0
    def draw_node(self, node: Node, painter):
        """Draw the specified node."""
        painter.setBrush(
            QBrush(
                self.selected_color
                if node is self.selected_node else self.regular_node_color,
                Qt.SolidPattern,
            ))

        node_position = node.get_position()
        node_radius = Vector(node.get_radius()).repeat(2)

        painter.drawEllipse(QPointF(*node_position), *node_radius)

        if self.labels_checkbox.isChecked():
            label = node.get_label()

            # scale font down, depending on the length of the label of the node
            painter.setFont(
                QFont(self.font_family, self.font_size / len(label)))

            # draw the node label within the node dimensions
            painter.drawText(
                QRectF(*(node_position - node_radius), *(2 * node_radius)),
                Qt.AlignCenter,
                label,
            )
Ejemplo n.º 2
0
    def select_node(self, node: Node):
        """Sets the selected node to the specified node, sets the input line edit to 
        its label and enables it."""
        self.selected_node = node

        self.input_line_edit.setText(node.get_label())
        self.input_line_edit.setEnabled(True)
        self.input_line_edit.setFocus()