def hide_section(label: CustomLabel, buttons: dict): """ This method hides the given dictionary of buttons with its label. Parameters ---------- label: CustomLabel buttons: dict """ label.hide() label.setStyleSheet(style.HIDDEN_LABEL_STYLE) for tool in buttons.values(): tool.hide() if type(tool) is NodeButton: tool.setStyleSheet(style.HIDDEN_LABEL_STYLE)
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")