Exemplo n.º 1
0
def paint_with_opacity(pixmap: QPixmap, opacity: float):
    transparent_image = QImage(QSize(36, 36),
                               QImage.Format_ARGB32_Premultiplied)
    transparent_image.fill(Qt.transparent)
    painter = QPainter(transparent_image)
    painter.setOpacity(opacity)
    painter.drawPixmap(18 - pixmap.width() / 2, 18 - pixmap.height() / 2,
                       pixmap)
    painter.end()
    return QPixmap.fromImage(transparent_image)
Exemplo n.º 2
0
class EntropyWidget(QWidget):
    def __init__(self, parent, view, data):
        super(EntropyWidget, self).__init__(parent)
        self.view = view
        self.data = data
        self.raw_data = data.file.raw

        self.block_size = (len(self.raw_data) / 4096) + 1
        if self.block_size < 1024:
            self.block_size = 1024
        self.width = int(len(self.raw_data) / self.block_size)
        self.image = QImage(self.width, 1, QImage.Format_ARGB32)
        self.image.fill(QColor(0, 0, 0, 0))

        self.thread = EntropyThread(self.raw_data, self.image, self.block_size)
        self.started = False

        self.timer = QTimer()
        self.timer.timeout.connect(self.timerEvent)
        self.timer.setInterval(100)
        self.timer.setSingleShot(False)
        self.timer.start()

        self.setMinimumHeight(UIContext.getScaledWindowSize(32, 32).height())

    def paintEvent(self, event):
        p = QPainter(self)
        p.drawImage(self.rect(), self.image)
        p.drawRect(self.rect())

    def sizeHint(self):
        return QSize(640, 32)

    def timerEvent(self):
        if not self.started:
            self.thread.start()
            self.started = True
        if self.thread.updated:
            self.thread.updated = False
            self.update()

    def mousePressEvent(self, event):
        if event.button() != Qt.LeftButton:
            return
        frac = float(event.x()) / self.rect().width()
        offset = int(frac * self.width * self.block_size)
        self.view.navigateToFileOffset(offset)
Exemplo n.º 3
0
	def __init__(self):
		# Sidebar icons are 28x28 points. Should be at least 56x56 pixels for
		# HiDPI display compatibility. They will be automatically made theme
		# aware, so you need only provide a grayscale image, where white is
		# the color of the shape.
		icon = QImage(56, 56, QImage.Format_RGB32)
		icon.fill(0)

		# Render an "H" as the example icon
		p = QPainter()
		p.begin(icon)
		p.setFont(QFont("Open Sans", 56))
		p.setPen(QColor(255, 255, 255, 255))
		p.drawText(QRectF(0, 0, 56, 56), Qt.AlignCenter, "H")
		p.end()

		SidebarWidgetType.__init__(self, icon, "Hello")
Exemplo n.º 4
0
class Image(qrcode.image.base.BaseImage):
    def __init__(self, border, width, box_size):
        self.border = border
        self.width = width
        self.box_size = box_size
        size = (width + border * 2) * box_size
        self._image = QImage(size, size, QImage.Format_RGB16)
        self._image.fill(Qt.white)

    def pixmap(self):
        return QPixmap.fromImage(self._image)

    def drawrect(self, row, col):
        painter = QPainter(self._image)
        painter.fillRect((col + self.border) * self.box_size,
                         (row + self.border) * self.box_size, self.box_size,
                         self.box_size, Qt.black)

    def save(self, stream, kind=None):
        pass