예제 #1
0
    def pixmap(self, size, mode, state):
        # type: (QSize, QIcon.Mode, QIcon.State) -> QPixmap
        if not self.__generator.isValid():
            return QPixmap()

        dsize = self.__generator.defaultSize()  # type: QSize
        if not dsize.isNull():
            dsize.scale(size, Qt.KeepAspectRatio)
            size = dsize
        key = "{}.SVGIconEngine/{}/{}x{}".format(__name__, self.__cache_id,
                                                 size.width(), size.height())
        pm = QPixmapCache.find(key)
        if pm is None or pm.isNull():
            pm = QPixmap(size)
            pm.fill(Qt.transparent)
            painter = QPainter(pm)
            try:
                self.__generator.render(
                    painter, QRectF(0, 0, size.width(), size.height()))
            finally:
                painter.end()
            QPixmapCache.insert(key, pm)
        style = QApplication.style()
        if style is not None:
            opt = QStyleOption()
            opt.palette = QApplication.palette()
            pm = style.generatedIconPixmap(mode, pm, opt)
        return pm
예제 #2
0
    def paintEvent(self, QPaintEvent):
        import math


        if self.direction == 'x':
            _angle = self.parent.rotationX
            _x1 = self.width() / 2
            _y1 = self.height() / 2
            _x2 = math.cos(math.radians(_angle)) * (self.width() / 2)
            _y2 = math.sin(math.radians(_angle)) * (self.width() / 2)
        elif self.direction == 'y':
            _angle = self.parent.rotationY
            _x1 = self.width() / 2
            _y1 = self.height() / 2
            _x2 = math.cos(math.radians(_angle + 90)) * (self.height() / 2)
            _y2 = math.sin(math.radians(_angle + 90)) * (self.height() / 2)
        else:
            _angle = 0
            _x1 = 0
            _y1 = 0
            _x2 = 0
            _y2 = 0
        _painter = QPainter(self)
        _pm = QPixmap(self.width(), self.height())
        _pm_compass = QPixmap(self.compassImage).transformed(QTransform().rotate(self.compassRotation))
        _pm_image = QPixmap(self.image).transformed(QTransform().rotate(_angle))
        _painter.drawPixmap(0, 0, _pm_compass)
        _painter.setPen(QColor(255, 160, 47))
        _painter.drawLine(_x1, _y1, _x2, _y2)
        _x = (self.width() - _pm_image.width()) / 2
        _y = (self.height() - _pm_image.height()) / 2
        _painter.drawPixmap(_x, _y, _pm_image)

        _painter.end()
예제 #3
0
    def __init__(self, widget, parent=None, name=None):
        OWPlot.__init__(self, parent, name, axes=[], widget=widget)
        ScaleData.__init__(self)

        self.update_antialiasing(False)

        self.widget = widget
        self.last_selected_curve = None
        self.enableGridXB(0)
        self.enableGridYL(0)
        self.domain_contingencies = None
        self.auto_update_axes = 1
        self.old_legend_keys = []
        self.selection_conditions = {}
        self.attributes = []
        self.visualized_mid_labels = []
        self.attribute_indices = []
        self.valid_data = []
        self.groups = {}
        self.colors = None

        self.selected_examples = []
        self.unselected_examples = []
        self.bottom_pixmap = QPixmap(
            gui.resource_filename("icons/upgreenarrow.png"))
        self.top_pixmap = QPixmap(
            gui.resource_filename("icons/downgreenarrow.png"))
예제 #4
0
 def __init__(self, pixmap=None, parent=None):
     super().__init__(parent)
     self.setCacheMode(QGraphicsItem.ItemCoordinateCache)
     self._pixmap = QPixmap(pixmap) if pixmap is not None else QPixmap()
     self._keepAspect = True
     self._crop = False
     self._subset = True
     self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
 def setPathway(self, pathway):
     """
     Set pathway
     """
     self.pathway = pathway
     if pathway:
         image_filename = pathway.get_image()
         self._pixmap = QPixmap(image_filename)
     else:
         self._pixmap = QPixmap()
     self.setPixmap(self._pixmap)
예제 #6
0
 def __init__(self,
              parent: Optional[QGraphicsItem] = None,
              pixmap: Optional[QPixmap] = None,
              scaleContents=False,
              aspectMode=Qt.KeepAspectRatio,
              **kwargs) -> None:
     self.__scaleContents = scaleContents
     self.__aspectMode = aspectMode
     self.__pixmap = QPixmap(pixmap) if pixmap is not None else QPixmap()
     super().__init__(None, **kwargs)
     self.setFlag(QGraphicsWidget.ItemUsesExtendedStyleOption, True)
     self.setContentsMargins(0, 0, 0, 0)
     if parent is not None:
         self.setParentItem(parent)
예제 #7
0
def decorate_welcome_icon(icon, background_color):
    """Return a `QIcon` with a circle shaped background.
    """
    welcome_icon = QIcon()
    sizes = [32, 48, 64, 80]
    background_color = NAMED_COLORS.get(background_color, background_color)
    background_color = QColor(background_color)
    grad = radial_gradient(background_color)
    for size in sizes:
        icon_pixmap = icon.pixmap(5 * size / 8, 5 * size / 8)
        icon_size = icon_pixmap.size()
        icon_rect = QRect(QPoint(0, 0), icon_size)

        pixmap = QPixmap(size, size)
        pixmap.fill(QColor(0, 0, 0, 0))
        p = QPainter(pixmap)
        p.setRenderHint(QPainter.Antialiasing, True)
        p.setBrush(QBrush(grad))
        p.setPen(Qt.NoPen)
        ellipse_rect = QRect(0, 0, size, size)
        p.drawEllipse(ellipse_rect)
        icon_rect.moveCenter(ellipse_rect.center())
        p.drawPixmap(icon_rect.topLeft(), icon_pixmap)
        p.end()

        welcome_icon.addPixmap(pixmap)

    return welcome_icon
예제 #8
0
    def test_splashscreen(self):
        splash = pkg_resources.resource_filename(
            config.__package__, "icons/orange-canvas-core-splash.svg"
        )
        w = SplashScreen()
        w.setPixmap(QPixmap(splash))
        w.setTextRect(QRect(100, 100, 400, 50))
        w.show()

        def advance_time():
            now = datetime.now()
            time = now.strftime("%c : %f")
            i = now.second % 3
            if i == 2:
                w.setTextFormat(Qt.RichText)
                time = "<i>" + time + "</i>"
            else:
                w.setTextFormat(Qt.PlainText)

            w.showMessage(time, alignment=Qt.AlignCenter)

            rect = QRect(100, 100 + i * 20, 400, 50)
            w.setTextRect(rect)

            self.assertEqual(w.textRect(), rect)

        timer = QTimer(w, interval=1)
        timer.timeout.connect(advance_time)
        timer.start()

        self.app.exec_()
    def test(self):
        img = QImage(100, 100, QImage.Format_ARGB32)
        img.fill(Qt.green)
        p = QPainter(img)
        pix = QPixmap(10, 10)
        pix.fill(Qt.red)
        frgmts = [
            QPainter.PixmapFragment.create(
                QPointF(25, 25),
                QRectF(0, 0, 10, 10),
                5., 5.,
            ),
            QPainter.PixmapFragment.create(
                QPointF(75, 75),
                QRectF(0, 0, 10, 10),
                5., 5.,
            )

        ]
        p.drawPixmapFragments(frgmts, pix)
        p.end()
        self.assertEqual(QColor(img.pixel(10, 10)), QColor(Qt.red))
        self.assertEqual(QColor(img.pixel(80, 80)),  QColor(Qt.red))
        self.assertEqual(QColor(img.pixel(90, 10)), QColor(Qt.green))
        self.assertEqual(QColor(img.pixel(10, 90)), QColor(Qt.green))
예제 #10
0
def shadowTemplatePixmap(color, length):
    """
    Returns 1 pixel wide, `length` pixels long linear-gradient.

    Args:
        color (QColor): shadow color
        length (int): length of cast shadow

    """
    key = "InnerShadowTemplate " + \
          color.name() + " " + \
          str(length)

    # get cached template
    shadowPixmap = QPixmapCache.find(key)
    if shadowPixmap:
        return shadowPixmap

    shadowPixmap = QPixmap(1, length)
    shadowPixmap.fill(Qt.transparent)

    grad = QLinearGradient(0, 0, 0, length)
    grad.setColorAt(0, color)
    grad.setColorAt(1, Qt.transparent)

    painter = QPainter()
    painter.begin(shadowPixmap)
    painter.fillRect(shadowPixmap.rect(), grad)
    painter.end()

    # cache template
    QPixmapCache.insert(key, shadowPixmap)

    return shadowPixmap
예제 #11
0
    def __shadowPixmapForDpr(self, dpr=1.0):
        # type: (float) -> QPixmap
        """
        Return a shadow pixmap rendered in `dpr` device pixel ratio.
        """
        offset = self.offset()
        radius = self.radius()
        color = self.color()
        fill_color = self.palette().color(QPalette.Window)
        rect_size = QSize(int(50 * dpr), int(50 * dpr))
        left = top = right = bottom = int(radius * dpr)
        # Size of the pixmap.
        pixmap_size = QSize(rect_size.width() + left + right,
                            rect_size.height() + top + bottom)
        shadow_rect = QRect(QPoint(left, top) - offset * dpr, rect_size)
        pixmap = QPixmap(pixmap_size)
        pixmap.fill(Qt.transparent)

        pixmap = render_drop_shadow_frame(
            pixmap,
            QRectF(shadow_rect),
            shadow_color=color,
            offset=QPointF(offset * dpr),
            radius=radius * dpr,
            rect_fill_color=fill_color
        )
        pixmap.setDevicePixelRatio(dpr)
        return pixmap
예제 #12
0
def decorate_welcome_icon(icon, background_color):
    # type: (QIcon, Union[QColor, str]) -> QIcon
    """Return a `QIcon` with a circle shaped background.
    """
    welcome_icon = QIcon()
    sizes = [32, 48, 64, 80, 128, 256]
    background_color = NAMED_COLORS.get(background_color, background_color)
    background_color = QColor(background_color)
    grad = radial_gradient(background_color)
    for size in sizes:
        icon_size = QSize(int(5 * size / 8), int(5 * size / 8))
        icon_rect = QRect(QPoint(0, 0), icon_size)
        pixmap = QPixmap(size, size)
        pixmap.fill(Qt.transparent)
        p = QPainter(pixmap)
        p.setRenderHint(QPainter.Antialiasing, True)
        p.setBrush(QBrush(grad))
        p.setPen(Qt.NoPen)
        ellipse_rect = QRect(0, 0, size, size)
        p.drawEllipse(ellipse_rect)
        icon_rect.moveCenter(ellipse_rect.center())
        icon.paint(
            p,
            icon_rect,
            Qt.AlignCenter,
        )
        p.end()

        welcome_icon.addPixmap(pixmap)

    return welcome_icon
예제 #13
0
    def splash_screen():
        splash_n = random.randint(1, 3)
        path = pkg_resources.resource_filename(
            __name__, f"icons/orange-splash-screen-{splash_n:02}.png")
        pm = QPixmap(path)

        version = Config.ApplicationVersion
        if version:
            version_parsed = LooseVersion(version)
            version_comp = version_parsed.version
            version = ".".join(map(str, version_comp[:2]))
        size = 13
        font = QFont("Helvetica")
        font.setPixelSize(size)
        metrics = QFontMetrics(font)
        br = metrics.boundingRect(version)
        br.moveTopLeft(QPoint(171, 438))

        p = QPainter(pm)
        p.setRenderHint(QPainter.Antialiasing)
        p.setRenderHint(QPainter.TextAntialiasing)
        p.setFont(font)
        p.setPen(QColor("#000000"))
        p.drawText(br, Qt.AlignLeft, version)
        p.end()
        return pm, QRect(23, 24, 200, 20)
예제 #14
0
def splash_screen():
    """
    """
    pm = QPixmap(
        pkg_resources.resource_filename(__name__,
                                        "icons/orange-splash-screen.png"))

    version = QCoreApplication.applicationVersion()
    size = 21 if len(version) < 5 else 16
    font = QFont("Helvetica")
    font.setPixelSize(size)
    font.setBold(True)
    font.setItalic(True)
    font.setLetterSpacing(QFont.AbsoluteSpacing, 2)
    metrics = QFontMetrics(font)
    br = metrics.boundingRect(version).adjusted(-5, 0, 5, 0)
    br.moveCenter(QPoint(436, 224))

    p = QPainter(pm)
    p.setRenderHint(QPainter.Antialiasing)
    p.setRenderHint(QPainter.TextAntialiasing)
    p.setFont(font)
    p.setPen(QColor("#231F20"))
    p.drawText(br, Qt.AlignCenter, version)
    p.end()
    return pm, QRect(88, 193, 200, 20)
예제 #15
0
    def __updatePixmap(self):
        """
        Update the cached shadow pixmap.
        """
        rect_size = QSize(50, 50)
        left = top = right = bottom = self.radius_

        # Size of the pixmap.
        pixmap_size = QSize(rect_size.width() + left + right,
                            rect_size.height() + top + bottom)
        shadow_rect = QRect(QPoint(left, top), rect_size)
        pixmap = QPixmap(pixmap_size)
        pixmap.fill(QColor(0, 0, 0, 0))
        rect_fill_color = self.palette().color(QPalette.Window)

        pixmap = render_drop_shadow_frame(
            pixmap,
            QRectF(shadow_rect),
            shadow_color=self.color_,
            offset=QPointF(0, 0),
            radius=self.radius_,
            rect_fill_color=rect_fill_color,
        )

        self.__shadowPixmap = pixmap
        self.update()
예제 #16
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.__pixmap = QPixmap()
     # Flag indicating if the widget was resized as a result of user
     # initiated window resize. When false the widget will automatically
     # resize/re-position based on pixmap size.
     self.__hasExplicitSize = False
     self.__inUpdateWindowGeometry = False
예제 #17
0
 def __shadowPixmap(self):
     # type: () -> QPixmap
     if self.__cachedShadowPixmap is None \
             or self.__cachedShadowPixmap.devicePixelRatioF() \
             != self.devicePixelRatioF():
         self.__cachedShadowPixmap = self.__shadowPixmapForDpr(
             self.devicePixelRatioF())
     return QPixmap(self.__cachedShadowPixmap)
예제 #18
0
    def setPixmap(self, pixmap):
        # type: (QPixmap) -> None
        self.setAttribute(Qt.WA_TranslucentBackground,
                          pixmap.hasAlpha() and is_transparency_supported())

        self.__pixmap = QPixmap(pixmap)
        super().setPixmap(pixmap)
        if pixmap.hasAlpha() and not is_transparency_supported():
            self.setMask(pixmap.createHeuristicMask())
예제 #19
0
    def setupScene(self):
        self.error()
        if self.data:
            attr = self.stringAttrs[self.smilesAttr]
            titleAttr = self.allAttrs[self.titleAttr]
            assert self.thumbnailView.count() == 0
            size = QSizeF(self.imageSize, self.imageSize)

            for i, inst in enumerate(self.data):
                if not numpy.isfinite(inst[attr]):  # skip missing
                    continue

                smiles = str(inst[attr])
                title = str(inst[titleAttr])

                thumbnail = GraphicsThumbnailWidget(QPixmap(), title=title)
                thumbnail.setThumbnailSize(size)
                thumbnail.setToolTip(smiles)
                thumbnail.instance = inst
                self.thumbnailView.addThumbnail(thumbnail)

                if self.check_smiles(smiles):
                    pixmap = self.pixmap_from_smiles(smiles)
                    thumbnail.setPixmap(pixmap)
                    self._successcount += 1

                else:
                    pixmap = QPixmap()
                    thumbnail.setPixmap(pixmap)
                    thumbnail.setToolTip(thumbnail.toolTip() +
                                         "\nInvalid SMILES")
                    self._errcount += 1

                future = Future()
                future.set_result(pixmap)
                future._reply = None

                self.items.append(_ImageItem(i, thumbnail, smiles, future))

            if any(it.future is not None and not it.future.done()
                   for it in self.items):
                self.info.setText("Retrieving...\n")
            else:
                self._updateStatus()
예제 #20
0
    def __startInternalDrag(self, frame, hotSpot=None):
        drag = QDrag(self)
        pixmap = QPixmap(frame.size())
        frame.render(pixmap)

        transparent = QPixmap(pixmap.size())
        transparent.fill(Qt.transparent)
        painter = QPainter(transparent)
        painter.setOpacity(0.35)
        painter.drawPixmap(0, 0, pixmap.width(), pixmap.height(), pixmap)
        painter.end()

        drag.setPixmap(transparent)
        if hotSpot is not None:
            drag.setHotSpot(hotSpot)
        mime = QMimeData()
        mime.setData("application/x-internal-move", b"")
        drag.setMimeData(mime)
        return drag.exec(Qt.MoveAction)
예제 #21
0
def palette_pixmap(colors, size):
    img = QPixmap(size)
    img.fill(Qt.transparent)

    painter = QPainter(img)
    grad = palette_gradient(colors)
    grad.setCoordinateMode(QLinearGradient.ObjectBoundingMode)
    painter.setPen(Qt.NoPen)
    painter.setBrush(QBrush(grad))
    painter.drawRect(0, 0, size.width(), size.height())
    painter.end()
    return img
예제 #22
0
def createDiscPalettePixmap(width, height, palette):
    p = QPainter()
    img = QPixmap(width, height)
    p.begin(img)
    p.setPen(QPen(Qt.NoPen))
    if type(palette) == dict:  # if palette is the dict with different
        palette = palette[max(palette.keys())]
    if len(palette) == 0: return img
    rectWidth = width / float(len(palette))
    for i, col in enumerate(palette):
        p.setBrush(QBrush(QColor(*col)))
        p.drawRect(QRectF(i * rectWidth, 0, (i + 1) * rectWidth, height))
    return img
예제 #23
0
    def __init__(self,
                 parent=None,
                 pixmap=None,
                 textRect=None,
                 textFormat=Qt.PlainText,
                 **kwargs):
        super().__init__(parent, **kwargs)
        self.__textRect = textRect or QRect()
        self.__message = ""
        self.__color = Qt.black
        self.__alignment = Qt.AlignLeft
        self.__textFormat = textFormat
        self.__pixmap = QPixmap()

        if pixmap is None:
            pixmap = QPixmap()

        self.setPixmap(pixmap)

        self.setAutoFillBackground(False)
        # Also set FramelessWindowHint (if not already set)
        self.setWindowFlags(self.windowFlags() | Qt.FramelessWindowHint)
def createExContPalettePixmap(width, height, color1, color2, passThroughColors):
    p = QPainter()
    img = QPixmap(width, height)
    p.begin(img)

    #p.eraseRect(0, 0, w, h)
    p.setPen(QPen(Qt.NoPen))
    g = QLinearGradient(0, 0, width, height)
    g.setColorAt(0, color1)
    g.setColorAt(1, color2)
    for i, color in enumerate(passThroughColors):
        g.setColorAt(float(i + 1) / (len(passThroughColors) + 1), color)
    p.fillRect(img.rect(), QBrush(g))
    return img
예제 #25
0
    def pixmap(self, size, mode, state):
        # type: (QSize, QIcon.Mode, QIcon.State) -> QPixmap
        if not self.__generator.isValid():
            return QPixmap()

        dsize = self.__generator.defaultSize()  # type: QSize
        if not dsize.isNull():
            dsize.scale(size, Qt.KeepAspectRatio)
            size = dsize

        pm = QPixmap(size)
        pm.fill(Qt.transparent)
        painter = QPainter(pm)
        try:
            self.__generator.render(painter, QRectF(0, 0, size.width(), size.height()))
        finally:
            painter.end()
        style = QApplication.style()
        if style is not None:
            opt = QStyleOption()
            opt.palette = QApplication.palette()
            pm = style.generatedIconPixmap(mode, pm, opt)
        return pm
예제 #26
0
def createContPalettePixmap(width, height, color1, color2, passThroughBlack):
    p = QPainter()
    img = QPixmap(width, height)
    p.begin(img)

    #p.eraseRect(0, 0, w, h)
    p.setPen(QPen(Qt.NoPen))
    g = QLinearGradient(0, 0, width, height)
    g.setColorAt(0, color1)
    g.setColorAt(1, color2)
    if passThroughBlack:
        g.setColorAt(0.5, Qt.black)
    p.fillRect(img.rect(), QBrush(g))
    return img
예제 #27
0
 def update_legend(self, colors, labels):
     layout = self.legend.layout()
     while self.legend_items:
         w = self.legend_items.pop()
         layout.removeWidget(w)
         w.deleteLater()
     for row, (color, label) in enumerate(zip(colors, labels)):
         icon = QLabel()
         p = QPixmap(12, 12)
         p.fill(color)
         icon.setPixmap(p)
         label = QLabel(label)
         layout.addWidget(icon, row, 0)
         layout.addWidget(label, row, 1, alignment=Qt.AlignLeft)
         self.legend_items += (icon, label)
예제 #28
0
    def splash_screen(self):
        # type: () -> Tuple[QPixmap, QRect]
        """
        Return a splash screen pixmap and an text area within it.

        The text area is used for displaying text messages during application
        startup.

        The default implementation returns a bland rectangle splash screen.

        Returns
        -------
        t : Tuple[QPixmap, QRect]
            A QPixmap and a rect area within it.
        """
        return QPixmap(), QRect()
 def test_graphicspixmapwidget(self):
     w = GraphicsPixmapWidget()
     self.scene.addItem(w)
     w.setPixmap(QPixmap(100, 100))
     p = w.pixmap()
     self.assertEqual(p.size(), QSize(100, 100))
     self.view.grab()
     w.setScaleContents(True)
     w.setAspectRatioMode(Qt.KeepAspectRatio)
     s = w.sizeHint(Qt.PreferredSize)
     self.assertEqual(s, QSizeF(100., 100.))
     s = w.sizeHint(Qt.PreferredSize, QSizeF(200., -1.))
     self.assertEqual(s, QSizeF(200., 200.))
     s = w.sizeHint(Qt.PreferredSize, QSizeF(-1., 200.))
     self.assertEqual(s, QSizeF(200., 200.))
     self.view.grab()
예제 #30
0
def crosshairs(color, radius=24, circle=False):
    radius = max(radius, 16)
    pixmap = QPixmap(radius, radius)
    pixmap.fill(Qt.transparent)
    painter = QPainter()
    painter.begin(pixmap)
    painter.setRenderHints(QPainter.Antialiasing)
    pen = QPen(QBrush(color), 1)
    pen.setWidthF(1.5)
    painter.setPen(pen)
    if circle:
        painter.drawEllipse(2, 2, radius - 2, radius - 2)
    painter.drawLine(radius / 2, 7, radius / 2, radius / 2 - 7)
    painter.drawLine(7, radius / 2, radius / 2 - 7, radius / 2)
    painter.end()
    return pixmap