예제 #1
0
 def setPalette(self, palette):
     # type: (QPalette) -> None
     """
     Set the body color palette (:class:`QPalette`).
     """
     self.palette = QPalette(palette)
     self.__updateBrush()
예제 #2
0
            def update():
                validator = edit.validator()
                if validator is not None and edit.text().strip():
                    state, _, _ = validator.validate(edit.text(), 0)
                else:
                    state = QValidator.Acceptable
                palette = edit.palette()
                colors = {
                    QValidator.Intermediate: (Qt.yellow, Qt.black),
                    QValidator.Invalid: (Qt.red, Qt.black),
                }.get(state, None)
                if colors is None:
                    palette = QPalette()
                else:
                    palette.setColor(QPalette.Base, colors[0])
                    palette.setColor(QPalette.Text, colors[1])

                cr = edit.cursorRect()
                p = edit.mapToGlobal(cr.bottomRight())
                edit.setPalette(palette)
                if state != QValidator.Acceptable and edit.isVisible():
                    validator.show_tip(edit, p, edit.toolTip(),
                                       textFormat=Qt.RichText)
                else:
                    validator.show_tip(edit, p, "")
예제 #3
0
 def test_update_palette(self):
     w = self.widget
     w.set_root(t(1.0, leaf(0, 0), leaf(1, 1)))
     w.setSelectedClusters([w.root()])
     p = QPalette()
     p.setColor(QPalette.All, QPalette.WindowText, QColor(Qt.red))
     w.setPalette(p)
     item = w.item(w.root())
     self.assertEqual(item.pen().color(), p.color(QPalette.WindowText))
예제 #4
0
 def palette(self):
     if self.__palette is None:
         scene = self.scene()
         if scene is not None:
             return scene.palette()
         else:
             return QPalette()
     else:
         return QPalette(self.__palette)
예제 #5
0
    def __init__(self, parent=None, **kwargs):
        super(AddonManagerWidget, self).__init__(parent, **kwargs)

        #: list of Available | Installed
        self.__items = []
        self.setLayout(QVBoxLayout())

        self.__header = QLabel(
            wordWrap=True,
            textFormat=Qt.RichText
        )
        self.__search = QLineEdit(
            placeholderText=self.tr("Filter")
        )

        self.layout().addWidget(self.__search)

        self.__view = view = QTreeView(
            rootIsDecorated=False,
            editTriggers=QTreeView.NoEditTriggers,
            selectionMode=QTreeView.SingleSelection,
            alternatingRowColors=True
        )
        self.__view.setItemDelegateForColumn(0, TristateCheckItemDelegate())
        self.layout().addWidget(view)

        self.__model = model = QStandardItemModel()
        model.setHorizontalHeaderLabels(["", "Name", "Version", "Action"])
        model.dataChanged.connect(self.__data_changed)
        proxy = QSortFilterProxyModel(
            filterKeyColumn=1,
            filterCaseSensitivity=Qt.CaseInsensitive
        )
        proxy.setSourceModel(model)
        self.__search.textChanged.connect(proxy.setFilterFixedString)

        view.setModel(proxy)
        view.selectionModel().selectionChanged.connect(
            self.__update_details
        )
        header = self.__view.header()
        header.setSectionResizeMode(0, QHeaderView.Fixed)
        header.setSectionResizeMode(2, QHeaderView.ResizeToContents)

        self.__details = QTextBrowser(
            frameShape=QTextBrowser.NoFrame,
            readOnly=True,
            lineWrapMode=QTextBrowser.WidgetWidth,
            openExternalLinks=True,
        )

        self.__details.setWordWrapMode(QTextOption.WordWrap)
        palette = QPalette(self.palette())
        palette.setColor(QPalette.Base, Qt.transparent)
        self.__details.setPalette(palette)
        self.layout().addWidget(self.__details)
예제 #6
0
    def __init__(self, parent=None, **kwargs):
        super(AddonManagerWidget, self).__init__(parent, **kwargs)
        self.__items = []
        self.setLayout(QVBoxLayout())

        self.__header = QLabel(
            wordWrap=True,
            textFormat=Qt.RichText
        )
        self.__search = QLineEdit(
            placeholderText=self.tr("Filter")
        )

        self.tophlayout = topline = QHBoxLayout()
        topline.addWidget(self.__search)
        self.layout().addLayout(topline)

        self.__view = view = QTreeView(
            rootIsDecorated=False,
            editTriggers=QTreeView.NoEditTriggers,
            selectionMode=QTreeView.SingleSelection,
            alternatingRowColors=True
        )
        self.__view.setItemDelegateForColumn(0, TristateCheckItemDelegate())
        self.layout().addWidget(view)

        self.__model = model = QStandardItemModel()
        model.setHorizontalHeaderLabels(["", "Name", "Version", "Action"])
        model.dataChanged.connect(self.__data_changed)
        self.__proxy = proxy = QSortFilterProxyModel(
            filterKeyColumn=1,
            filterCaseSensitivity=Qt.CaseInsensitive
        )
        proxy.setSourceModel(model)
        self.__search.textChanged.connect(proxy.setFilterFixedString)

        view.setModel(proxy)
        view.selectionModel().selectionChanged.connect(
            self.__update_details
        )
        header = self.__view.header()
        header.setSectionResizeMode(0, QHeaderView.Fixed)
        header.setSectionResizeMode(2, QHeaderView.ResizeToContents)

        self.__details = QTextBrowser(
            frameShape=QTextBrowser.NoFrame,
            readOnly=True,
            lineWrapMode=QTextBrowser.WidgetWidth,
            openExternalLinks=True,
        )

        self.__details.setWordWrapMode(QTextOption.WordWrap)
        palette = QPalette(self.palette())
        palette.setColor(QPalette.Base, Qt.transparent)
        self.__details.setPalette(palette)
        self.layout().addWidget(self.__details)
 def __pen_cache(self, palette: QPalette, state: QStyle.State) -> QPen:
     """Return a QPen from the `palette` for `state`."""
     # NOTE: This method exists mostly to avoid QPen, QColor (de)allocations.
     key = palette.cacheKey(), int(state) & _State_Mask
     try:
         return self.__pen_lru_cache[key]
     except KeyError:
         cgroup = QPalette.Normal if state & QStyle.State_Active else QPalette.Inactive
         cgroup = cgroup if state & QStyle.State_Enabled else QPalette.Disabled
         role = QPalette.HighlightedText if state & QStyle.State_Selected else QPalette.Text
         pen = QPen(palette.color(cgroup, role))
         self.__pen_lru_cache[key] = pen
         return pen
def qgraphicsitem_accent_color(item: 'QGraphicsItem', palette: QPalette):
    style = qgraphicsitem_style(item)
    mo = style.metaObject()
    if mo.className() == 'QMacStyle':
        return qmacstyle_accent_color(style)
    else:
        return palette.highlight().color()
예제 #9
0
 def setTabPalette(self, index, palette):
     # type: (int, QPalette) -> None
     """
     Set the tab button palette.
     """
     self.__tabs[index] = self.__tabs[index]._replace(
         palette=QPalette(palette))
     self.__updateTab(index)
예제 #10
0
    def test_widget(self):
        w = HeatmapGridWidget()
        self.scene.addItem(w)

        for p in self._Data.values():
            w.setHeatmaps(p)

        w.headerGeometry()
        w.footerGeometry()

        # Trigger the change events.
        p = QPalette()
        p.setColor(QPalette.All, QPalette.Text, Qt.red)
        w.setPalette(p)
        f = QFont()
        f.setPointSizeF(19.5)
        w.setFont(f)
예제 #11
0
 def __init__(self, *args, background=None, **kwargs):
     super().__init__(*args, background=background, **kwargs)
     if background is None:
         # Revert the pg.PlotWidget's modifications, use default
         # for QGraphicsView
         self.setBackgroundRole(QPalette.Base)
     # Reset changes to the palette (undo changes from pg.GraphicsView)
     self.setPalette(QPalette())
     self.__updateScenePalette()
예제 #12
0
 def __init__(self, *args, **kwargs):
     self.__selected = False
     self.__palette = QPalette()
     self.__content = ""
     #: The cached text background shape when this item is selected
     self.__cachedBackgroundPath = None  # type: Optional[QPainterPath]
     self.__styleState = QStyle.State(0)
     super().__init__(*args, **kwargs)
     layout = self.document().documentLayout()
     layout.update.connect(self.__onLayoutChanged)
예제 #13
0
 def __pen_cache(self, palette: QPalette, state: QStyle.State) -> QPen:
     """Return a QPen from the `palette` for `state`."""
     # NOTE: This method exists mostly to avoid QPen, QColor (de)allocations.
     key = palette.cacheKey(), int(state) & _State_Mask
     try:
         return self.__pen_lru_cache[key]
     except KeyError:
         pen = QPen(text_color_for_state(palette, state))
         self.__pen_lru_cache[key] = pen
         return pen
예제 #14
0
 def palette(self):
     # type: () -> QPalette
     palette = QPalette(self.__palette)
     parent = self.parentWidget()
     scene = self.scene()
     if parent is not None:
         return parent.palette().resolve(palette)
     elif scene is not None:
         return scene.palette().resolve(palette)
     else:
         return palette
예제 #15
0
    def __init__(self):
        super().__init__()

        self.data = None  # type: Optional[Table]

        self.model = FeatureStatisticsTableModel(parent=self)
        self.table_view = FeatureStatisticsTableView(self.model, parent=self)
        self.table_view.selectionModel().selectionChanged.connect(
            self.on_select)
        self.table_view.horizontalHeader().sectionClicked.connect(
            self.on_header_click)

        box = gui.vBox(self.controlArea)
        box.setContentsMargins(0, 0, 0, 4)
        pal = QPalette()
        pal.setColor(QPalette.Window,
                     self.table_view.palette().color(QPalette.Base))
        box.setAutoFillBackground(True)
        box.setPalette(pal)

        box.layout().addWidget(self.table_view)

        self.color_var_model = DomainModel(
            valid_types=(ContinuousVariable, DiscreteVariable),
            placeholder='None',
        )
        self.cb_color_var = gui.comboBox(self.buttonsArea,
                                         master=self,
                                         value='color_var',
                                         model=self.color_var_model,
                                         label='Color:',
                                         orientation=Qt.Horizontal,
                                         contentsLength=13,
                                         searchable=True)
        self.cb_color_var.activated.connect(self.__color_var_changed)

        gui.rubber(self.buttonsArea)
        gui.auto_send(self.buttonsArea, self, "auto_commit")
예제 #16
0
 def __init__(self, *args, background=None, **kwargs):
     axisItems = kwargs.pop("axisItems", None)
     if axisItems is None:  # Use palette aware AxisItems
         axisItems = {
             "left": AxisItem("left"),
             "bottom": AxisItem("bottom")
         }
     super().__init__(*args,
                      background=background,
                      axisItems=axisItems,
                      **kwargs)
     if background is None:
         # Revert the pg.PlotWidget's modifications, use default
         # for QGraphicsView background role
         self.setBackgroundRole(QPalette.Base)
     # Reset changes to the palette (undo changes from pg.GraphicsView)
     self.setPalette(QPalette())
     self.__updateScenePalette()
예제 #17
0
class OWPalette:
    """
        These constants are defined here so that they can be changed without
        extensive changes to the visualizations
    """
    Canvas = QPalette.Base
    Grid = QPalette.Button
    Text = QPalette.Text
    Data = QPalette.Text
    Axis = QPalette.Text

    System = QPalette()
    Light = create_palette({
        Canvas: Qt.white,
        Grid: Qt.lightGray,
        Text: Qt.black
    })
    Dark = create_palette({
        Canvas: Qt.black,
        Grid: Qt.darkGray,
        Text: Qt.white
    })
예제 #18
0
def text_color_for_state(palette: QPalette, state: QStyle.State) -> QColor:
    """Return the appropriate `palette` text color for the `state`."""
    cgroup = QPalette.Normal if state & QStyle.State_Active else QPalette.Inactive
    cgroup = cgroup if state & QStyle.State_Enabled else QPalette.Disabled
    role = QPalette.HighlightedText if state & QStyle.State_Selected else QPalette.Text
    return palette.color(cgroup, role)
예제 #19
0
 def setPalette(self, palette):
     if self.__palette != palette:
         self.__palette = QPalette(palette)
         self.__updateDefaultTextColor()
         self.update()
예제 #20
0
def create_palette(light_color, color):
    """
    Return a new :class:`QPalette` from for the :class:`NodeBodyItem`.
    """
    palette = QPalette()

    palette.setColor(QPalette.Inactive, QPalette.Light,
                     saturated(light_color, 50))
    palette.setColor(QPalette.Inactive, QPalette.Midlight,
                     saturated(light_color, 90))
    palette.setColor(QPalette.Inactive, QPalette.Button, light_color)

    palette.setColor(QPalette.Active, QPalette.Light, saturated(color, 50))
    palette.setColor(QPalette.Active, QPalette.Midlight, saturated(color, 90))
    palette.setColor(QPalette.Active, QPalette.Button, color)
    palette.setColor(QPalette.ButtonText, QColor("#515151"))
    return palette
예제 #21
0
def breeze_dark():
    # 'Breeze Dark' color scheme from KDE.
    text = QColor(239, 240, 241)
    textdisabled = QColor(98, 108, 118)
    window = QColor(49, 54, 59)
    base = QColor(35, 38, 41)
    highlight = QColor(61, 174, 233)
    link = QColor(41, 128, 185)

    light = QColor(69, 76, 84)
    mid = QColor(43, 47, 52)
    dark = QColor(28, 31, 34)
    shadow = QColor(20, 23, 25)

    palette = QPalette()
    palette.setColor(QPalette.Window, window)
    palette.setColor(QPalette.WindowText, text)
    palette.setColor(QPalette.Disabled, QPalette.WindowText, textdisabled)
    palette.setColor(QPalette.Base, base)
    palette.setColor(QPalette.AlternateBase, window)
    palette.setColor(QPalette.ToolTipBase, window)
    palette.setColor(QPalette.ToolTipText, text)
    palette.setColor(QPalette.Text, text)
    palette.setColor(QPalette.Disabled, QPalette.Text, textdisabled)
    palette.setColor(QPalette.Button, window)
    palette.setColor(QPalette.ButtonText, text)
    palette.setColor(QPalette.Disabled, QPalette.ButtonText, textdisabled)
    palette.setColor(QPalette.BrightText, Qt.white)
    palette.setColor(QPalette.Highlight, highlight)
    palette.setColor(QPalette.HighlightedText, text)
    palette.setColor(QPalette.Light, light)
    palette.setColor(QPalette.Mid, mid)
    palette.setColor(QPalette.Dark, dark)
    palette.setColor(QPalette.Shadow, shadow)
    palette.setColor(QPalette.Link, link)
    return palette
예제 #22
0
def create_palette(light_color, color):
    """
    Return a new :class:`QPalette` from for the :class:`NodeBodyItem`.
    """
    palette = QPalette()

    palette.setColor(QPalette.Inactive, QPalette.Light,
                     saturated(light_color, 50))
    palette.setColor(QPalette.Inactive, QPalette.Midlight,
                     saturated(light_color, 90))
    palette.setColor(QPalette.Inactive, QPalette.Button,
                     light_color)

    palette.setColor(QPalette.Active, QPalette.Light,
                     saturated(color, 50))
    palette.setColor(QPalette.Active, QPalette.Midlight,
                     saturated(color, 90))
    palette.setColor(QPalette.Active, QPalette.Button,
                     color)
    palette.setColor(QPalette.ButtonText, QColor("#515151"))
    return palette
예제 #23
0
def _make_palette(base: QColor, text: QColor, window: QColor,
                  highlight: QColor, highlight_disabled: QColor,
                  text_disabled: QColor, link: QColor, light: QColor,
                  mid: QColor, dark: QColor, shadow: QColor):
    palette = QPalette()
    palette.setColor(QPalette.Window, window)
    palette.setColor(QPalette.WindowText, text)
    palette.setColor(QPalette.Disabled, QPalette.WindowText, text_disabled)
    palette.setColor(QPalette.Base, base)
    palette.setColor(QPalette.AlternateBase, window)
    palette.setColor(QPalette.ToolTipBase, window)
    palette.setColor(QPalette.ToolTipText, text)
    palette.setColor(QPalette.Text, text)
    palette.setColor(QPalette.Disabled, QPalette.Text, text_disabled)
    palette.setColor(QPalette.Button, window)
    palette.setColor(QPalette.ButtonText, text)
    palette.setColor(QPalette.Disabled, QPalette.ButtonText, text_disabled)
    palette.setColor(QPalette.BrightText, Qt.white)
    palette.setColor(QPalette.Highlight, highlight)
    palette.setColor(QPalette.Disabled, QPalette.Highlight, highlight_disabled)
    palette.setColor(QPalette.HighlightedText, text)
    palette.setColor(QPalette.Light, light)
    palette.setColor(QPalette.Mid, mid)
    palette.setColor(QPalette.Dark, dark)
    palette.setColor(QPalette.Shadow, shadow)
    palette.setColor(QPalette.Link, link)
    return palette
예제 #24
0
 def setPalette(self, palette):
     # type: (QPalette) -> None
     if self.__palette != palette:
         self.__palette = QPalette(palette)
         QApplication.sendEvent(self, QEvent(QEvent.PaletteChange))
예제 #25
0
class NodeBodyItem(GraphicsPathObject):
    """
    The central part (body) of the `NodeItem`.
    """
    def __init__(self, parent=None):
        # type: (NodeItem) -> None
        super().__init__(parent)
        assert isinstance(parent, NodeItem)

        self.__processingState = 0
        self.__progress = -1.
        self.__animationEnabled = False
        self.__isSelected = False
        self.__hover = False
        self.__shapeRect = QRectF(-10, -10, 20, 20)

        self.setAcceptHoverEvents(True)

        self.setFlag(QGraphicsItem.ItemSendsScenePositionChanges, True)
        self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, True)

        self.setPen(QPen(Qt.NoPen))

        self.setPalette(default_palette())

        self.shadow = QGraphicsDropShadowEffect(
            blurRadius=0,
            color=QColor(SHADOW_COLOR),
            offset=QPointF(0, 0),
        )
        self.shadow.setEnabled(False)

        # An item with the same shape as this object, stacked behind this
        # item as a source for QGraphicsDropShadowEffect. Cannot attach
        # the effect to this item directly as QGraphicsEffect makes the item
        # non devicePixelRatio aware.
        shadowitem = GraphicsPathObject(self, objectName="shadow-shape-item")
        shadowitem.setPen(Qt.NoPen)
        shadowitem.setBrush(QBrush(QColor(SHADOW_COLOR).lighter()))
        shadowitem.setGraphicsEffect(self.shadow)
        shadowitem.setFlag(QGraphicsItem.ItemStacksBehindParent)
        self.__shadow = shadowitem
        self.__blurAnimation = QPropertyAnimation(self.shadow, b"blurRadius",
                                                  self)
        self.__blurAnimation.setDuration(100)
        self.__blurAnimation.finished.connect(self.__on_finished)

        self.__pingAnimation = QPropertyAnimation(self, b"scale", self)
        self.__pingAnimation.setDuration(250)
        self.__pingAnimation.setKeyValues([(0.0, 1.0), (0.5, 1.1), (1.0, 1.0)])

    # TODO: The body item should allow the setting of arbitrary painter
    # paths (for instance rounded rect, ...)
    def setShapeRect(self, rect):
        # type: (QRectF) -> None
        """
        Set the item's shape `rect`. The item should be confined within
        this rect.
        """
        path = QPainterPath()
        path.addEllipse(rect)
        self.setPath(path)
        self.__shadow.setPath(path)
        self.__shapeRect = rect

    def setPalette(self, palette):
        # type: (QPalette) -> None
        """
        Set the body color palette (:class:`QPalette`).
        """
        self.palette = QPalette(palette)
        self.__updateBrush()

    def setAnimationEnabled(self, enabled):
        # type: (bool) -> None
        """
        Set the node animation enabled.
        """
        if self.__animationEnabled != enabled:
            self.__animationEnabled = enabled

    def setProcessingState(self, state):
        # type: (int) -> None
        """
        Set the processing state of the node.
        """
        if self.__processingState != state:
            self.__processingState = state
            if not state and self.__animationEnabled:
                self.ping()

    def setProgress(self, progress):
        # type: (float) -> None
        """
        Set the progress indicator state of the node. `progress` should
        be a number between 0 and 100.

        """
        self.__progress = progress
        self.update()

    def ping(self):
        # type: () -> None
        """
        Trigger a 'ping' animation.
        """
        animation_restart(self.__pingAnimation)

    def hoverEnterEvent(self, event):
        self.__hover = True
        self.__updateShadowState()
        return super().hoverEnterEvent(event)

    def hoverLeaveEvent(self, event):
        self.__hover = False
        self.__updateShadowState()
        return super().hoverLeaveEvent(event)

    def paint(self, painter, option, widget=None):
        # type: (QPainter, QStyleOptionGraphicsItem, Optional[QWidget]) -> None
        """
        Paint the shape and a progress meter.
        """
        # Let the default implementation draw the shape
        if option.state & QStyle.State_Selected:
            # Prevent the default bounding rect selection indicator.
            option.state = QStyle.State(option.state ^ QStyle.State_Selected)
        super().paint(painter, option, widget)
        if self.__progress >= 0:
            # Draw the progress meter over the shape.
            # Set the clip to shape so the meter does not overflow the shape.
            painter.save()
            painter.setClipPath(self.shape(), Qt.ReplaceClip)
            color = self.palette.color(QPalette.ButtonText)
            pen = QPen(color, 5)
            painter.setPen(pen)
            painter.setRenderHints(QPainter.Antialiasing)
            span = max(1, int(self.__progress * 57.60))
            painter.drawArc(self.__shapeRect, 90 * 16, -span)
            painter.restore()

    def __updateShadowState(self):
        # type: () -> None
        if self.__isSelected or self.__hover:
            enabled = True
            radius = 17
        else:
            enabled = False
            radius = 0

        if enabled and not self.shadow.isEnabled():
            self.shadow.setEnabled(enabled)

        if self.__isSelected:
            color = QColor(SELECTED_SHADOW_COLOR)
        else:
            color = QColor(SHADOW_COLOR)

        self.shadow.setColor(color)

        if radius == self.shadow.blurRadius():
            return

        if self.__animationEnabled:
            if self.__blurAnimation.state() == QPropertyAnimation.Running:
                self.__blurAnimation.pause()

            self.__blurAnimation.setStartValue(self.shadow.blurRadius())
            self.__blurAnimation.setEndValue(radius)
            self.__blurAnimation.start()
        else:
            self.shadow.setBlurRadius(radius)

    def __updateBrush(self):
        # type: () -> None
        palette = self.palette
        if self.__isSelected:
            cg = QPalette.Active
        else:
            cg = QPalette.Inactive

        palette.setCurrentColorGroup(cg)
        c1 = palette.color(QPalette.Light)
        c2 = palette.color(QPalette.Button)
        grad = radial_gradient(c2, c1)
        self.setBrush(QBrush(grad))

    # TODO: The selected state should be set using the
    # QStyle flags (State_Selected. State_HasFocus)

    def setSelected(self, selected):
        # type: (bool) -> None
        """
        Set the `selected` state.

        .. note:: The item does not have `QGraphicsItem.ItemIsSelectable` flag.
                  This property is instead controlled by the parent NodeItem.

        """
        self.__isSelected = selected
        self.__updateShadowState()
        self.__updateBrush()

    def __on_finished(self):
        # type: () -> None
        if self.shadow.blurRadius() == 0:
            self.shadow.setEnabled(False)
예제 #26
0
 def setPalette(self, palette):
     # type: (QPalette) -> None
     if self.__palette != palette:
         self.__palette = QPalette(palette)
         self.__updateDefaultTextColor()
         self.update()
예제 #27
0
def create_palette(colors):
    p = QPalette()
    for role, color in colors.items():
        p.setColor(role, color)
    return p
예제 #28
0
def create_palette(colors):
    p = QPalette()
    for role, color in colors.items():
        p.setColor(role, color)
    return p
예제 #29
0
파일: __main__.py 프로젝트: astaric/orange3
def breeze_dark():
    # 'Breeze Dark' color scheme from KDE.
    text = QColor(239, 240, 241)
    textdisabled = QColor(98, 108, 118)
    window = QColor(49, 54, 59)
    base = QColor(35, 38, 41)
    highlight = QColor(61, 174, 233)
    link = QColor(41, 128, 185)

    light = QColor(69, 76, 84)
    mid = QColor(43, 47, 52)
    dark = QColor(28, 31, 34)
    shadow = QColor(20, 23, 25)

    palette = QPalette()
    palette.setColor(QPalette.Window, window)
    palette.setColor(QPalette.WindowText, text)
    palette.setColor(QPalette.Disabled, QPalette.WindowText, textdisabled)
    palette.setColor(QPalette.Base, base)
    palette.setColor(QPalette.AlternateBase, window)
    palette.setColor(QPalette.ToolTipBase, window)
    palette.setColor(QPalette.ToolTipText, text)
    palette.setColor(QPalette.Text, text)
    palette.setColor(QPalette.Disabled, QPalette.Text, textdisabled)
    palette.setColor(QPalette.Button, window)
    palette.setColor(QPalette.ButtonText, text)
    palette.setColor(QPalette.Disabled, QPalette.ButtonText, textdisabled)
    palette.setColor(QPalette.BrightText, Qt.white)
    palette.setColor(QPalette.Highlight, highlight)
    palette.setColor(QPalette.HighlightedText, text)
    palette.setColor(QPalette.Light, light)
    palette.setColor(QPalette.Mid, mid)
    palette.setColor(QPalette.Dark, dark)
    palette.setColor(QPalette.Shadow, shadow)
    palette.setColor(QPalette.Link, link)
    return palette
예제 #30
0
 def setColor(self, color):
     self.color = color
     palette = QPalette()
     palette.setBrush(QPalette.Background, color)
     self.icon.setPalette(palette)
예제 #31
0
 def setColor(self, color):
     self.color = color
     palette = QPalette()
     palette.setBrush(QPalette.Background, color)
     self.icon.setPalette(palette)
예제 #32
0
    def setupGraphics(self):
        """
        Set up the graphics.
        """
        shape_rect = QRectF(-24, -24, 48, 48)

        self.shapeItem = NodeBodyItem(self)
        self.shapeItem.setShapeRect(shape_rect)
        self.shapeItem.setAnimationEnabled(self.__animationEnabled)

        # Rect for widget's 'ears'.
        anchor_rect = QRectF(-31, -31, 62, 62)
        self.inputAnchorItem = SinkAnchorItem(self)
        input_path = QPainterPath()
        start_angle = 180 - self.ANCHOR_SPAN_ANGLE / 2
        input_path.arcMoveTo(anchor_rect, start_angle)
        input_path.arcTo(anchor_rect, start_angle, self.ANCHOR_SPAN_ANGLE)
        self.inputAnchorItem.setAnchorPath(input_path)

        self.outputAnchorItem = SourceAnchorItem(self)
        output_path = QPainterPath()
        start_angle = self.ANCHOR_SPAN_ANGLE / 2
        output_path.arcMoveTo(anchor_rect, start_angle)
        output_path.arcTo(anchor_rect, start_angle, -self.ANCHOR_SPAN_ANGLE)
        self.outputAnchorItem.setAnchorPath(output_path)

        self.inputAnchorItem.hide()
        self.outputAnchorItem.hide()

        # Title caption item
        self.captionTextItem = NameTextItem(self)

        self.captionTextItem.setPlainText("")
        self.captionTextItem.setPos(0, 33)

        def iconItem(standard_pixmap):
            item = GraphicsIconItem(self,
                                    icon=standard_icon(standard_pixmap),
                                    iconSize=QSize(16, 16))
            item.hide()
            return item

        self.errorItem = iconItem(QStyle.SP_MessageBoxCritical)
        self.warningItem = iconItem(QStyle.SP_MessageBoxWarning)
        self.infoItem = iconItem(QStyle.SP_MessageBoxInformation)

        self.backgroundItem = QGraphicsPathItem(self)
        backgroundrect = QPainterPath()
        backgroundrect.addRoundedRect(anchor_rect.adjusted(-4, -2, 4, 2),
                                      5,
                                      5,
                                      mode=Qt.AbsoluteSize)
        self.backgroundItem.setPen(QPen(Qt.NoPen))
        self.backgroundItem.setBrush(QPalette().brush(QPalette.Highlight))
        self.backgroundItem.setOpacity(0.5)
        self.backgroundItem.setPath(backgroundrect)
        self.backgroundItem.setZValue(-10)
        self.backgroundItem.setVisible(self.isSelected())

        self.prepareGeometryChange()
        self.__boundingRect = None