def add_element(self, field=None, field_layout=None): """Adds a new field to the Array. :param field: Optional field to add. If omitted, a copy of the last element will be added. """ if field is None: if not self.fields: raise RuntimeError('No default field set in the ArrayField.') field = copy.deepcopy(self.fields[-1]) self.fields.append(field) if field_layout: element_widget = QtWidgets.QWidget() field_layout.insertWidget(field_layout.count() - 1, element_widget) hbox = QtWidgets.QHBoxLayout(element_widget) hbox.setContentsMargins(0, 0, 0, 0) field_widget = field.widget() hbox.addWidget(field_widget) action = QtWidgets.QAction('Remove', field_layout) action.triggered.connect( partial(self.remove_element, field_layout, element_widget)) icon = QtGui.QIcon(QtGui.QPixmap(':/smallTrash.png')) action.setIcon(icon) action.setToolTip('Remove') action.setStatusTip('Remove') delete_button = QtWidgets.QToolButton() delete_button.setDefaultAction(action) hbox.addWidget(delete_button)
def __init__(self, comp, queue, parent=None): super(ComponentWidget, self).__init__(parent) self.setMouseTracking(True) self.queue_layout = parent.queue_layout self.queue = queue self.comp = comp vbox = QtWidgets.QVBoxLayout(self) self.setFrameStyle(QtWidgets.QFrame.StyledPanel) self.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Maximum) self.over_grab_hotspot = False self.color = ComponentWidget.normal_color # Header hbox = QtWidgets.QHBoxLayout() self.header_layout = hbox hbox.setContentsMargins(16, 4, 4, 4) vbox.addLayout(hbox) # Expand toggle expand_action = QtWidgets.QAction('Toggle', self) expand_action.setCheckable(True) icon = QtGui.QIcon(QtGui.QPixmap(':/arrowDown.png')) expand_action.setIcon(icon) expand_action.setToolTip('Toggle details') expand_action.setStatusTip('Toggle details') button = QtWidgets.QToolButton() button.setDefaultAction(expand_action) hbox.addWidget(button) # Enable checkbox enabled = QtWidgets.QCheckBox() enabled.setToolTip('Enable/Disable Component') hbox.addWidget(enabled) # Breakpoint self.break_point_action = QtWidgets.QAction('Breakpoint', self) self.break_point_action.setCheckable(True) self.break_point_action.setIcon(self.break_point_disabled_icon) self.break_point_action.setToolTip('Set break point at component.') self.break_point_action.setStatusTip('Set break point at component.') self.break_point_action.toggled.connect(self.set_break_point) button = QtWidgets.QToolButton() button.setDefaultAction(self.break_point_action) hbox.addWidget(button) # Execute button action = QtWidgets.QAction('Execute', self) icon = QtGui.QIcon(QtGui.QPixmap(':/timeplay.png')) action.setIcon(icon) action.setToolTip('Execute the component') action.setStatusTip('Execute the component') action.triggered.connect( partial(self.execute_component, on_error=parent.on_component_execution_error)) button = QtWidgets.QToolButton() button.setDefaultAction(action) hbox.addWidget(button) # Image label label = QtWidgets.QLabel() label.setPixmap(comp.image(size=24)) label.setToolTip(comp.__class__.__doc__) hbox.addWidget(label) # Name label label = QtWidgets.QLabel(comp.name().split('.')[-1]) label.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed) label.setToolTip(comp.__class__.__doc__) font = QtGui.QFont() font.setPointSize(14) label.setFont(font) hbox.addWidget(label) hbox.addStretch() if comp.help_url(): action = QtWidgets.QAction('Help', self) icon = QtGui.QIcon(QtGui.QPixmap(':/help.png')) action.setIcon(icon) action.setToolTip('Open help documentation.') action.setStatusTip('Open help documentation.') action.triggered.connect(partial(webbrowser.open, comp.help_url())) button = QtWidgets.QToolButton() button.setDefaultAction(action) hbox.addWidget(button) action = QtWidgets.QAction('Delete', self) icon = QtGui.QIcon(QtGui.QPixmap(':/smallTrash.png')) action.setIcon(icon) message = 'Delete Component' action.setToolTip(message) action.setStatusTip(message) action.triggered.connect(partial(self.remove, prompt=True)) button = QtWidgets.QToolButton() button.setDefaultAction(action) hbox.addWidget(button) content_vbox = QtWidgets.QVBoxLayout() content_vbox.setContentsMargins(16, 0, 0, 0) vbox.addLayout(content_vbox) content_widget = comp.widget() content_vbox.addWidget(content_widget) enabled.toggled.connect(content_widget.setEnabled) enabled.setChecked(comp.enabled) enabled.toggled.connect(comp.set_enabled) expand_action.toggled.connect(content_widget.setVisible) content_widget.setVisible(False)