예제 #1
0
 def widget(self):
     """Get the QWidget of the Field."""
     widget = QtWidgets.QCheckBox(self.verbose_name)
     widget.setChecked(self._value)
     widget.setToolTip(self.help_text)
     widget.toggled.connect(self.set_value)
     return widget
예제 #2
0
    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)