示例#1
0
class BlockInspector(QWidget):
    """
    This class contains the widget for displaying the description of a network
    block in the ParamToolbar. Each block attribute is labeled and wrapped
    in a drop-down box.

    Attributes
    ----------
    layout : QVBoxLayout
        Vertical main_layout of the widget.
    title_label : CustomLabel
        Title of the widget.
    description_label : CustomLabel
        Description of the block.
    parameters : QWidget
        Container of parameters.
    parameters_label : CustomLabel
        Label of parameters.
    parameters_layout : QVBoxLayout
        Vertical main_layout of parameters.
    inputs : QWidget
        Container of inputs.
    inputs_label : CustomLabel
        Label of inputs.
    inputs_layout : QVBoxLayout
        Vertical main_layout of inputs.
    outputs : QWidget
        Container of outputs.
    outputs_label : CustomLabel
        Label of outputs.
    outputs_layout : QVBoxLayout
        Vertical main_layout of outputs.

    """
    def __init__(self, block: NodeBlock):
        super().__init__()
        self.setStyleSheet(style.BLOCK_BOX_STYLE)
        self.layout = QVBoxLayout()
        self.layout.setSpacing(0)
        self.layout.setContentsMargins(0, 0, 10, 0)
        self.setLayout(self.layout)
        self.adjustSize()
        self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Maximum)

        # Widget title
        self.title_label = CustomLabel()
        self.title_label.setStyleSheet(style.TITLE_LABEL_STYLE)
        self.title_label.setText(block.block_id + ":" + block.node.name)

        # NodeBlock description
        self.description_label = CustomLabel()
        self.description_label.setStyleSheet(style.DESCRIPTION_STYLE)
        self.description_label.setWordWrap(True)
        self.description_label.setAlignment(Qt.AlignLeft)
        self.description_label.setText(block.node.descr)
        self.description_label.setSizePolicy(QSizePolicy.Preferred,
                                             QSizePolicy.Minimum)

        # Parameters section
        if block.node.param:
            self.parameters_label = CustomLabel("Parameters")
            self.parameters_label.setStyleSheet(style.NODE_LABEL_STYLE)
            self.parameters = QWidget()
            self.parameters_layout = QVBoxLayout()
            self.parameters_layout.setSpacing(0)
            self.parameters.setLayout(self.parameters_layout)
            self.parameters.setStyleSheet("padding: 0px")

            for par, values in block.node.param.items():
                self.parameters_layout.addWidget(DropDownLabel(par, values))

        # Inputs section
        if block.node.input:
            self.inputs_label = CustomLabel("Input")
            self.inputs_label.setStyleSheet(style.NODE_LABEL_STYLE)
            self.inputs = QWidget()
            self.inputs_layout = QVBoxLayout()
            self.inputs_layout.setSpacing(0)
            self.inputs.setLayout(self.inputs_layout)
            self.inputs.setStyleSheet("padding: 0px")

            for par, values in block.node.input.items():
                self.inputs_layout.addWidget(DropDownLabel(par, values))

        # Outputs section
        if block.node.output:
            self.outputs_label = CustomLabel("Output")
            self.outputs_label.setStyleSheet(style.NODE_LABEL_STYLE)
            self.outputs = QWidget()
            self.outputs_layout = QVBoxLayout()
            self.outputs_layout.setSpacing(0)
            self.outputs.setLayout(self.outputs_layout)
            self.outputs.setStyleSheet("padding: 0px")

            for par, values in block.node.output.items():
                self.outputs_layout.addWidget(DropDownLabel(par, values))

        # Compose widget
        self.layout.addWidget(self.title_label)
        self.layout.addWidget(self.description_label)

        if block.node.param:
            self.layout.addWidget(self.parameters_label)
            self.layout.addWidget(self.parameters)

        if block.node.input:
            self.layout.addWidget(self.inputs_label)
            self.layout.addWidget(self.inputs)

        if block.node.output:
            self.layout.addWidget(self.outputs_label)
            self.layout.addWidget(self.outputs)
示例#2
0
class DropDownLabel(QWidget):
    """
    This widget displays a generic parameter name and value.
    It features a drop-down arrow button that shows or hides
    the description.

    Attributes
    ----------
    layout : QVBoxLayout
        Vertical main_layout of the widget.
    top : QWidget
        First part of the widget with name, type and default value of the
        parameter.
    top_layout : QHBoxLayout
        Horizontal main_layout of the top of the widget.
    name_label : CustomLabel
        Id and type of the object.
    type_label : CustomLabel
        Object type.
    default_label : CustomLabel
        Eventual default value.
    down_button : CustomButton
        Arrow button to show/hide the description of the parameter.
    description : CustomLabel
        Description of the parameter.

    Methods
    ----------
    change_description_mode()
        This method shows or hides the description of the parameter.

    """
    def __init__(self, name: str, parameters: dict):
        super().__init__()
        self.layout = QVBoxLayout()
        self.setContentsMargins(0, 0, 0, 0)
        self.setLayout(self.layout)
        self.setStyleSheet(style.DROPDOWN_STYLE)
        self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Expanding)

        # Top bar with short info
        self.top = QWidget()
        self.top.setContentsMargins(0, 0, 0, 0)
        self.top.setStyleSheet(style.DROPDOWN_TOP_STYLE)
        self.top_layout = QHBoxLayout()
        self.top_layout.setContentsMargins(0, 0, 0, 0)
        self.top.setLayout(self.top_layout)

        self.name_label = CustomLabel(name)
        self.name_label.setAlignment(Qt.AlignLeft)
        self.name_label.setStyleSheet(style.DROPDOWN_NAME_STYLE)
        self.top_layout.addWidget(self.name_label, Qt.AlignLeft)

        self.type_label = CustomLabel(parameters["type"])
        self.type_label.setAlignment(Qt.AlignLeft)
        self.type_label.setToolTip("Type")
        self.type_label.setStyleSheet(style.DROPDOWN_TYPE_STYLE)
        self.top_layout.addWidget(self.type_label, Qt.AlignLeft)

        if "default" in parameters:
            self.default_label = CustomLabel(parameters["default"])
            self.default_label.setStyleSheet(style.DROPDOWN_DEFAULT_STYLE)
            self.default_label.setToolTip("Default value")
            self.default_label.setAlignment(Qt.AlignCenter)
            self.top_layout.addWidget(self.default_label, Qt.AlignRight)

        self.down_button = CustomButton("\u25bc")
        self.down_button.setStyleSheet(style.DROPDOWN_ARROW_STYLE)
        self.down_button.clicked.connect(lambda: self.__toggle_visibility())
        self.top_layout.addWidget(self.down_button, Qt.AlignRight)

        self.layout.addWidget(self.top)

        self.description = CustomLabel(parameters["description"])
        self.description.setSizePolicy(QSizePolicy.Minimum,
                                       QSizePolicy.Maximum)
        self.description.setWordWrap(True)
        self.description.setStyleSheet(style.DESCRIPTION_STYLE)
        self.description.hide()
        self.layout.addWidget(self.description)

    def __toggle_visibility(self):
        """
        This method toggles the visibility of the parameter description
        changing the arrow icon of the button.

        """

        if self.description.isHidden():
            self.description.show()
            self.down_button.setText("\u25b2")
        else:
            self.description.hide()
            self.down_button.setText("\u25bc")