Python PyQt5.QtGui.QPainter() Examples

The following are code examples for showing how to use PyQt5.QtGui.QPainter(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: dcc   Author: amimo   File: DisasmViewMode.py    Apache License 2.0 6 votes vote down vote up
def draw(self, refresh=False):
        if self.dataModel.getOffset() in self.Paints:
            self.refresh = False
            self.qpix = QtGui.QPixmap(self.Paints[self.dataModel.getOffset()])
            self.drawAdditionals()
            return

        if self.refresh or refresh:
            qp = QtGui.QPainter()
            qp.begin(self.qpix)

            self.drawTextMode(qp)
            self.refresh = False
            qp.end()

        #        self.Paints[self.dataModel.getOffset()] = QtGui.QPixmap(self.qpix)
        self.drawAdditionals() 
Example 2
Project: dcc   Author: amimo   File: DisasmViewMode.py    Apache License 2.0 6 votes vote down vote up
def drawAdditionals(self):
        self.newPix = self._getNewPixmap(self.width, self.height + self.SPACER)
        qp = QtGui.QPainter()
        qp.begin(self.newPix)
        qp.setWindow(-50, 0, self.COLUMNS * self.fontWidth, self.ROWS * self.fontHeight)

        qp.drawPixmap(0, 0, self.qpix)

        # self.transformationEngine.decorateText()

        # highlight selected text
        self.selector.highlightText()

        # draw other selections
        self.selector.drawSelections(qp)

        # draw our cursor
        self.drawCursor(qp)

        self.drawBranch(qp)
        self.drawSelected(qp)

        qp.end() 
Example 3
Project: dcc   Author: amimo   File: SourceViewMode.py    Apache License 2.0 6 votes vote down vote up
def drawAdditionals(self):
        self.newPix = self._getNewPixmap(self.width, self.height + self.SPACER)
        qp = QtGui.QPainter()
        qp.begin(self.newPix)
        qp.setWindow(-50, 0, self.COLUMNS * self.fontWidth, self.ROWS * self.fontHeight)

        qp.drawPixmap(0, 0, self.qpix)

        # self.transformationEngine.decorateText()

        # highlight selected text
        self.selector.highlightText()

        # draw other selections
        self.selector.drawSelections(qp)

        # draw our cursor
        self.drawCursor(qp)
        self.drawLine(qp)

        qp.end() 
Example 4
Project: dcc   Author: amimo   File: HexViewMode.py    Apache License 2.0 6 votes vote down vote up
def drawAdditionals(self):
        self.newPix = self._getNewPixmap(self.width, self.height + self.SPACER)
        qp = QtGui.QPainter()
        qp.begin(self.newPix)
        qp.drawPixmap(0, 0, self.qpix)

        # self.transformationEngine.decorateText()

        # highlight selected text
        self.selector.highlightText()

        # draw other selections
        self.selector.drawSelections(qp)

        # draw our cursor
        self.drawCursor(qp)

        # draw dword lines
        for i in range(self.COLUMNS // 4)[1:]:
            xw = i * 4 * 3 * self.fontWidth - 4
            qp.setPen(QtGui.QColor(0, 255, 0))
            qp.drawLine(xw, 0, xw, self.ROWS * self.fontHeight)

        qp.end() 
Example 5
Project: dcc   Author: amimo   File: Banners.py    Apache License 2.0 6 votes vote down vote up
def draw(self):
        qp = QtGui.QPainter()

        offset = self.viewMode.getPageOffset()
        columns, rows = self.viewMode.getGeometry()

        qp.begin(self.qpix)
        qp.fillRect(0, 0, self.width, self.height, self.backgroundBrush)
        qp.setPen(self.textPen)
        qp.setFont(self.font)

        for i in range(rows):
            s = '{0:08x}'.format(offset)
            qp.drawText(0 + 5, (i + 1) * self.fontHeight, s)
            columns = self.viewMode.getColumnsbyRow(i)
            offset += columns

        qp.end() 
Example 6
Project: dcc   Author: amimo   File: Banners.py    Apache License 2.0 6 votes vote down vote up
def draw(self):
        # i don't really like this in terms of arhitecture. We have
        # artificially introduced getHeaderInfo() in Views. Then we had one top
        # banner implemented per plugin. I will think to a better solution

        qp = QtGui.QPainter()
        qp.begin(self.qpix)

        qp.fillRect(0, 0, self.width, self.height, self.backgroundBrush)
        qp.setPen(self.textPen)
        qp.setFont(self.font)

        cemu = ConsoleEmulator(qp, self.height // self.fontHeight, self.width // self.fontWidth)

        cemu.writeAt(1, 0, 'FileAddr')

        offset = 11

        text = self.viewMode.getHeaderInfo()

        cemu.writeAt(offset, 0, text)

        qp.end() 
Example 7
Project: dcc   Author: amimo   File: BinViewMode.py    Apache License 2.0 6 votes vote down vote up
def drawAdditionals(self):
        self.newPix = self._getNewPixmap(self.width, self.height + self.SPACER)
        qp = QtGui.QPainter()
        qp.begin(self.newPix)
        qp.drawPixmap(0, 0, self.qpix)

        # self.transformationEngine.decorateText()

        # highlight selected text
        self.selector.highlightText()

        # draw other selections
        self.selector.drawSelections(qp)

        # draw our cursor
        self.drawCursor(qp)
        qp.end() 
Example 8
Project: dcc   Author: amimo   File: BinViewMode.py    Apache License 2.0 6 votes vote down vote up
def draw(self, refresh=False, row=0, howMany=0):
        if self.dataModel.getOffset() in self.Paints:
            self.refresh = False
            self.qpix = QtGui.QPixmap(self.Paints[self.dataModel.getOffset()])
            self.drawAdditionals()
            return

        if self.refresh or refresh:
            qp = QtGui.QPainter()
            qp.begin(self.qpix)
            start = time()
            if not howMany:
                howMany = self.ROWS

            self.drawTextMode(qp, row=row, howMany=howMany)
            end = time() - start
            log.debug('draw Time ' + str(end))
            self.refresh = False
            qp.end()

        #        self.Paints[self.dataModel.getOffset()] = QtGui.QPixmap(self.qpix)
        self.drawAdditionals() 
Example 9
Project: kucher   Author: Zubax   File: model.py    GNU General Public License v3.0 6 votes vote down vote up
def _draw_flags_icon(mutable: bool, persistent: bool, icon_size: int) -> QPixmap:
    """
    Combines icons into a single large icon and renders it into a pixmap of specified size.
    This operation is quite resource-consuming (we're drawing pictures after all, ask Picasso),
    so we cache the results in a LRU cache.
    """
    icon_name = 'edit' if mutable else 'lock'
    mutability = get_icon_pixmap(icon_name, icon_size)

    # https://youtu.be/AX2uz2XYkbo?t=21s
    icon_name = 'save' if persistent else 'random-access-memory'
    persistence = get_icon_pixmap(icon_name, icon_size)

    icon_size_rect = QRect(0, 0, icon_size, icon_size)

    pixmap = QPixmap(icon_size * 2, icon_size)
    mask = QBitmap(pixmap.width(), pixmap.height())
    mask.clear()
    pixmap.setMask(mask)

    painter = QPainter(pixmap)
    painter.drawPixmap(icon_size_rect, mutability, icon_size_rect)
    painter.drawPixmap(QRect(icon_size, 0, icon_size, icon_size),
                       persistence, icon_size_rect)
    return pixmap 
Example 10
Project: cct   Author: awacha   File: progressbardelegate.py    BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def paint(self, painter:QtGui.QPainter, option:QtWidgets.QStyleOptionViewItem, index:QtCore.QModelIndex):
        data = index.data(QtCore.Qt.UserRole)
        assert isinstance(data, JobRecord)
        if data.isRunning:
            pbaroption = QtWidgets.QStyleOptionProgressBar()
            pbaroption.state = QtWidgets.QStyle.State_Enabled
            pbaroption.direction = QtWidgets.QApplication.layoutDirection()
            pbaroption.rect = option.rect
            pbaroption.fontMetrics = QtWidgets.QApplication.fontMetrics()
            pbaroption.minimum = 0
            pbaroption.maximum = data.total if data.total is not None else 0
            pbaroption.textAlignment = QtCore.Qt.AlignCenter
            pbaroption.textVisible = True
            pbaroption.progress = data.current if data.current is not None else 0
            pbaroption.text = data.statusmessage
            QtWidgets.QApplication.style().drawControl(QtWidgets.QStyle.CE_ProgressBar, pbaroption, painter)
        else:
            super().paint(painter, option, index) 
Example 11
Project: musaic   Author: al165   File: sliders.py    GNU General Public License v3.0 6 votes vote down vote up
def paintEvent(self, e):
        painter = QtGui.QPainter(self)

        brush = QtGui.QBrush()
        brush.setColor(self._forground_color)
        brush.setStyle(Qt.SolidPattern)

        width = painter.device().width()
        height = painter.device().height()

        percent = (self.value - self.minimum) / (self.maximum - self.minimum)

        rect = QtCore.QRect(0, 0, width*percent, height)
        painter.fillRect(rect, brush)

        if self._text_color:
            painter.setPen(self._text_color)

        if self._show_text:
            rect = QtCore.QRect(0, 0, width, height)
            painter.drawText(rect, Qt.AlignVCenter | Qt.AlignHCenter, str(f'{self.value}'))

        painter.end() 
Example 12
Project: musaic   Author: al165   File: sliders.py    GNU General Public License v3.0 6 votes vote down vote up
def paintEvent(self, e):
        painter = QtGui.QPainter(self)

        brush = QtGui.QBrush()
        brush.setColor(self._forground_color)
        brush.setStyle(Qt.SolidPattern)

        width = painter.device().width()
        height = painter.device().height()

        left_percent = (self.left - self.minimum) / (self.maximum - self.minimum)
        right_percent = (self.right - self.minimum) / (self.maximum - self.minimum)

        rect = QtCore.QRect(width*left_percent, 0, width*(right_percent - left_percent), height)
        painter.fillRect(rect, brush)

        if self._text_color:
            painter.setPen(self._text_color)

        if self._show_text:
            rect = QtCore.QRect(0, 0, width, height)
            painter.drawText(rect, Qt.AlignVCenter | Qt.AlignHCenter, str(f'{self.left}, {self.right}'))

        painter.end() 
Example 13
Project: musaic   Author: al165   File: sliders.py    GNU General Public License v3.0 6 votes vote down vote up
def paintEvent(self, e):
        painter = QtGui.QPainter(self)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        rect = painter.device().rect()

        radius = min(rect.width(), rect.height())/2

        pc = (self.value - self.minimum) / (self.maximum - self.minimum)

        a = 4.18879 - pc*5.23599
        x = math.cos(a) * (radius-1) + radius
        y = -math.sin(a) * (radius-1) + radius

        pen = QtGui.QPen()
        pen.setWidth(2)
        pen.setColor(self._color)
        painter.setPen(pen)
        painter.drawArc(1, 1, 2*radius-1, 2*radius-1, -120*16, -300*16)
        pen.setColor(QtGui.QColor('#DDDDDD'))
        painter.setPen(pen)
        painter.drawLine(radius, radius, x, y) 
Example 14
Project: PyQt-multifunctional-uart-helper   Author: IronSublimate   File: widgetpainter.py    MIT License 6 votes vote down vote up
def __init__(self, parent=None):
        super(WidgetPainter, self).__init__(parent)
        # self.painter3 = QPainter(self)
        self.qpix = QPixmap()
        # self.parentUi = None
        self.imgWidth = 80
        self.imgHeight = 60
        self.label_position = None  #: QLabel
        self.label_pause = None  #: QLabel
        self.grid_points = []
        self.enable_grid = False
        self.pause = False
        self.enable_extra_14_bytes = False
        self.extra_bytes_len = 0
        self.extra_data = None  # tuple
        # [0]中心点的行数
        # [1]中心点的列数
        # [2]列左极限
        # [3]列右极限
        # [4]控制中心的列数 
Example 15
Project: PyQt-multifunctional-uart-helper   Author: IronSublimate   File: widgetpainter.py    MIT License 6 votes vote down vote up
def paintEvent(self, a0: QPaintEvent):
        # print("paint")
        painter = QPainter(self)

        # painter.begin(self)
        painter.drawPixmap(0, 0, self.width(), self.height(), self.qpix)
        if self.enable_extra_14_bytes and self.extra_data:
            pix_width = self.width() / self.imgWidth
            pix_height = self.height() / self.imgHeight
            # painter.setPen(QPen(Qt.red, -14))
            painter.setBrush(QBrush(Qt.red))
            painter.drawEllipse(self.extra_data[1] * pix_width, self.extra_data[0] * pix_height, pix_width, pix_height)
            painter.drawEllipse(self.extra_data[2] * pix_width, self.extra_data[0] * pix_height, pix_width, pix_height)
            painter.drawEllipse(self.extra_data[3] * pix_width, self.extra_data[0] * pix_height, pix_width, pix_height)
            painter.drawEllipse(self.extra_data[4] * pix_width, self.extra_data[0] * pix_height, pix_width, pix_height)

        if self.enable_grid:
            painter.setPen(Qt.darkBlue)
            painter.drawLines(self.grid_points)
        # painter.end() 
Example 16
Project: SpriteMator   Author: rafaelvasco   File: utils.py    Apache License 2.0 6 votes vote down vote up
def generate_checkerboard_tile(size, color1, color2):
    tile_size = size * 2

    tile = QImage(tile_size, tile_size, QImage.Format_ARGB32_Premultiplied)

    painter = QPainter()

    painter.begin(tile)

    painter.fillRect(0, 0, tile_size, tile_size, color1)
    painter.fillRect(0, 0, size, size, color2)
    painter.fillRect(size, size, size, size, color2)

    painter.end()

    tile_pixmap = QPixmap.fromImage(tile)

    return tile_pixmap


# ------------------------------------------------------------------------------ 
Example 17
Project: SpriteMator   Author: rafaelvasco   File: color_picker_widget.py    Apache License 2.0 6 votes vote down vote up
def _generate_picker(self):

        image = QImage(8, 18, QImage.Format_ARGB32_Premultiplied)

        image.fill(Qt.transparent)

        p = QPainter()

        p.begin(image)

        pen = QPen(Qt.black)
        pen.setWidth(2)

        p.setPen(pen)

        p.setBrush(Qt.white)

        rect = QRect(0, 0, 8, 18)

        p.drawRect(rect)

        p.end()

        self._pickerPixmap = QPixmap.fromImage(image) 
Example 18
Project: SpriteMator   Author: rafaelvasco   File: sprite.py    Apache License 2.0 6 votes vote down vote up
def flatten(self):

        if len(self._surfaces) == 1:
            return self._surfaces[0].image

        flattened_image = utils.create_image(self._animation.frame_width(),
                                             self._animation.frame_height())

        painter = QPainter()
        painter.begin(flattened_image)

        for surface in self._surfaces:
            painter.drawImage(0, 0, surface.image)

        painter.end()

        return flattened_image 
Example 19
Project: eddy   Author: obdasystems   File: view.py    GNU General Public License v3.0 6 votes vote down vote up
def setGridSize(self, size):
        """
        Sets the grid size.
        """
        action = self.session.action('toggle_grid')
        size = clamp(size, 0)
        if size <= 0 or not action.isChecked():
            brush = QtGui.QBrush(QtCore.Qt.NoBrush)
        else:
            image = QtGui.QImage(size, size, QtGui.QImage.Format_RGB32)
            image.fill(QtCore.Qt.white)
            painter = QtGui.QPainter(image)
            painter.setPen(QtGui.QPen(QtGui.QBrush(QtGui.QColor(80, 80, 80, 255)), 1, QtCore.Qt.SolidLine))
            painter.drawPoint(QtCore.QPointF(0, 0))
            painter.end()
            brush = QtGui.QBrush(image)
        self.setBackgroundBrush(brush) 
Example 20
Project: eddy   Author: obdasystems   File: palette.py    GNU General Public License v3.0 6 votes vote down vote up
def paintEvent(self, paintEvent):
        """
        Perform the painting of the button in the palette.
        :type paintEvent: QPaintEvent
        """
        icon = self.icon()
        painter = QtGui.QPainter(self)
        if self.isChecked():
            painter.setBrush(QtGui.QBrush(QtGui.QColor(66, 165, 245)))
            painter.setPen(QtGui.QPen(QtGui.QBrush(QtGui.QColor(66, 165, 245)), 1.0))
            painter.drawRect(0, 0, 60, 44)
        painter.setOpacity(1.0 if self.isEnabled() else 0.33)
        painter.drawPixmap(0, 0, icon.pixmap(QtCore.QSize(60, 44)))

    #############################################
    #   INTERFACE
    ################################# 
Example 21
Project: plexdesktop   Author: coryo   File: delegates.py    GNU General Public License v3.0 6 votes vote down vote up
def placeholder_thumb_generator(title, size=150):
    """Returns a QPixmap of size with the first letter of each word in title"""
    initials = ' '.join([x[0] for x in title.split(' ') if len(x) > 2])
    key = 'placeholder' + initials
    img = QtGui.QPixmapCache.find(key)
    if img:
        return img
    qsize = QtCore.QSize(size, size)
    circle_color = QtGui.QColor(50, 50, 50)
    text_color = QtGui.QColor(75, 75, 75)
    rect = QtCore.QRect(QtCore.QPoint(0, 0), QtCore.QPoint(size, size))
    center = QtCore.QPoint(size / 2, size / 2)
    img = QtGui.QPixmap(qsize)
    img.fill(QtCore.Qt.transparent)
    p = QtGui.QPainter(img)
    p.setFont(QtGui.QFont('Open Sans', size / 4, weight=QtGui.QFont.Bold))
    p.setBrush(QtGui.QBrush(circle_color))
    p.setPen(circle_color)
    p.setRenderHint(QtGui.QPainter.Antialiasing, True)
    p.drawEllipse(center, size / 2 - 1, size / 2 - 1)
    p.setPen(text_color)
    p.drawText(rect, QtCore.Qt.AlignCenter | QtCore.Qt.AlignVCenter, initials)
    QtGui.QPixmapCache.insert(key, img)
    return img 
Example 22
Project: plexdesktop   Author: coryo   File: delegates.py    GNU General Public License v3.0 6 votes vote down vote up
def draw_progress_bar(plex_item, pixmap, height=6):
    """draw a progress indicator on the bottom of pixmap with height pixels"""
    if not hasattr(plex_item, 'in_progress'):
        return
    if not plex_item.in_progress:
        return
    progress_color = QtGui.QColor(204, 123, 25)
    progress = plex_item.view_offset / max(1, plex_item.duration)
    p = QtGui.QPainter(pixmap)
    rect = p.window()
    progress_rect = QtCore.QRect(rect.bottomLeft() - QtCore.QPoint(0, height),
                                 rect.bottomRight())
    progress_fill = QtCore.QRect(progress_rect)
    progress_fill.setWidth(rect.width() * progress)
    p.fillRect(progress_rect, QtGui.QBrush(QtCore.Qt.black))
    p.fillRect(progress_fill, QtGui.QBrush(progress_color)) 
Example 23
Project: plexdesktop   Author: coryo   File: delegates.py    GNU General Public License v3.0 6 votes vote down vote up
def draw_unwatched_indicator(plex_item, pixmap, size=0.20):
    """draw a triangle on the top right of pixmap"""
    if not hasattr(plex_item, 'watched') and not hasattr(plex_item, 'in_progress'):
        return
    if plex_item.watched or plex_item.in_progress:
        return
    p = QtGui.QPainter(pixmap)
    rect = p.window()
    top_right = rect.topRight()
    size = pixmap.height() * size
    color = QtGui.QColor(204, 123, 25)
    triangle = QtGui.QPolygon([top_right, top_right - QtCore.QPoint(size, 0),
                               top_right + QtCore.QPoint(0, size)])
    p.setPen(QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 120)), 6))
    p.drawLine(triangle.point(1), triangle.point(2))
    p.setBrush(QtGui.QBrush(color))
    p.setPen(color)
    p.drawPolygon(triangle) 
Example 24
Project: pyqt5-widgets   Author: mfitzp   File: paint.py    MIT License 6 votes vote down vote up
def __init__(self, width, height, background='white', *args, **kwargs):
        super().__init__(*args, **kwargs)
        pixmap = QtGui.QPixmap(width, height)
        self.setPixmap(pixmap)

        # Fill the canvas with the initial color.
        painter = QtGui.QPainter(self.pixmap())
        brush = QtGui.QBrush()
        brush.setColor(QtGui.QColor(background))
        brush.setStyle(Qt.SolidPattern)
        painter.fillRect(0, 0, pixmap.width(), pixmap.height(), brush)
        painter.end()

        self.last_x, self.last_y = None, None
        self._pen_color = QtGui.QColor('#000000')
        self._pen_width = 4 
Example 25
Project: pyqt5-widgets   Author: mfitzp   File: paint.py    MIT License 6 votes vote down vote up
def mouseMoveEvent(self, e):
        if self.last_x is None:  # First event.
            self.last_x = e.x()
            self.last_y = e.y()
            return  #  Ignore the first time.

        painter = QtGui.QPainter(self.pixmap())
        p = painter.pen()
        p.setWidth(self._pen_width)
        p.setColor(self._pen_color)
        painter.setPen(p)
        painter.drawLine(self.last_x, self.last_y, e.x(), e.y())
        painter.end()
        self.update()

        # Update the origin for next time.
        self.last_x = e.x()
        self.last_y = e.y() 
Example 26
Project: interSubs   Author: oltodosel   File: interSubs.py    MIT License 6 votes vote down vote up
def paintEvent(self, evt: QPaintEvent):
			if not self.psuedo_line:
				self.psuedo_line = 1
				return

			x = y = 0
			y += self.fontMetrics().ascent()
			painter = QPainter(self)

			self.draw_text_n_outline(
				painter,
				x,
				y + config.outline_top_padding - config.outline_bottom_padding,
				config.outline_thickness,
				config.outline_blur,
				text = self.line
				) 
Example 27
Project: interSubs   Author: oltodosel   File: interSubs.py    MIT License 6 votes vote down vote up
def highligting(self, color, underline_width):
		color = QColor(color)
		color = QColor(color.red(), color.green(), color.blue(), 200)
		painter = QPainter(self)

		if config.hover_underline:
			font_metrics = QFontMetrics(self.font())
			text_width = font_metrics.width(self.word)
			text_height = font_metrics.height()

			brush = QBrush(color)
			pen = QPen(brush, underline_width, Qt.SolidLine, Qt.RoundCap)
			painter.setPen(pen)
			if not self.skip:
				painter.drawLine(0, text_height - underline_width, text_width, text_height - underline_width)

		if config.hover_hightlight:
			x = y = 0
			y += self.fontMetrics().ascent()

			painter.setPen(color)
			painter.drawText(x, y + config.outline_top_padding - config.outline_bottom_padding, self.word) 
Example 28
Project: PyRHEED   Author: yux1991   File: plot_chart.py    MIT License 6 votes vote down vote up
def main(self):
        self.chartView.SAVE_TEXT.connect(self.save_polar_as_text)
        self.chartView.SAVE_IMAGE.connect(self.save_polar_as_image)
        self.chartView.SAVE_SVG.connect(self.save_polar_as_SVG)
        self.chartView.setRenderHint(QtGui.QPainter.Antialiasing)
        self.chartView.setContentsMargins(0,0,0,0)
        if self.type == 'Polar':
            self.profileChart = QtChart.QPolarChart()
        elif self.type == 'Normal':
            self.profileChart = QtChart.QChart()
        self.profileChart.setBackgroundRoundness(0)
        self.profileChart.setMargins(QtCore.QMargins(0,0,0,0))
        self.profileChart.setTheme(self.theme)
        self.chartView.setChart(self.profileChart)
        self.coordinate = QtWidgets.QLabel("")
        self.chartView.CHART_MOUSE_MOVEMENT.connect(self.update_coordinate)
        self.chartView.CHART_MOUSE_LEAVE.connect(self.clear_coordinate)
        self.Grid = QtWidgets.QGridLayout()
        self.Grid.addWidget(self.chartView,0,0)
        self.Grid.addWidget(self.coordinate,1,0)
        self.setLayout(self.Grid) 
Example 29
Project: PyRHEED   Author: yux1991   File: plot_chart.py    MIT License 6 votes vote down vote up
def save_polar_as_image(self):
        if self.CHART_IS_PRESENT:
            self.filename = QtWidgets.QFileDialog.getSaveFileName(None,"choose save file name","./plot.png","PNG (*.png);;JPEG (*.jpeg);;GIF (*.gif);;BMP (*.bmp)")
            if not self.filename[0] == "":
                output_size = QtCore.QSize(int(self.profileChart.size().width()),int(self.profileChart.size().height()))
                output_rect = QtCore.QRectF(QtCore.QPointF(0,0),QtCore.QSizeF(output_size))
                image = QtGui.QImage(output_size,QtGui.QImage.Format_ARGB32)
                image.fill(QtCore.Qt.transparent)
                painter = QtGui.QPainter()
                painter.begin(image)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                self.profileChart.scene().render(painter, source=output_rect,target=output_rect,mode=QtCore.Qt.IgnoreAspectRatio)
                painter.end()
                image.save(self.filename[0])
            else:
                return
        else:
            self.raise_error("No plot is available") 
Example 30
Project: PyRHEED   Author: yux1991   File: plot_chart.py    MIT License 6 votes vote down vote up
def save_polar_as_SVG(self):
        if self.CHART_IS_PRESENT:
            self.filename = QtWidgets.QFileDialog.getSaveFileName(None,"choose save file name","./plot.svg","SVG (*.svg)")
            if not self.filename[0] == "":
                output_size = QtCore.QSize(int(self.profileChart.size().width()),int(self.profileChart.size().height()))
                output_rect = QtCore.QRectF(QtCore.QPointF(0,0),QtCore.QSizeF(output_size))
                svg = QtSvg.QSvgGenerator()
                svg.setFileName(self.filename[0])
                svg.setSize(output_size)
                svg.setViewBox(output_rect)
                painter = QtGui.QPainter()
                painter.begin(svg)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                self.profileChart.scene().render(painter, source=output_rect,target=output_rect,mode=QtCore.Qt.IgnoreAspectRatio)
                painter.end()
            else:
                return
        else:
            self.raise_error("No plot is available") 
Example 31
Project: PyRHEED   Author: yux1991   File: profile_chart.py    MIT License 6 votes vote down vote up
def save_profile_as_SVG(self):
        if self.CHART_IS_PRESENT:
            self.filename = QtWidgets.QFileDialog.getSaveFileName(None,"choose save file name","./profile.svg","SVG (*.svg)")
            if not self.filename[0] == "":
                output_size = QtCore.QSize(800,600)
                output_rect = QtCore.QRectF(QtCore.QPointF(0,0),QtCore.QSizeF(output_size))

                svg = QtSvg.QSvgGenerator()
                svg.setFileName(self.filename[0])
                svg.setSize(output_size)
                svg.setViewBox(output_rect)

                original_size = self.profileChart.size()
                self.profileChart.resize(QtCore.QSizeF(output_size))
                painter = QtGui.QPainter()
                painter.begin(svg)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                self.profileChart.scene().render(painter, source=output_rect,target=output_rect,mode=QtCore.Qt.IgnoreAspectRatio)
                painter.end()
                self.profileChart.resize(original_size)
            else:
                return
        else:
            self.raise_error("No line profile is available") 
Example 32
Project: dcc   Author: amimo   File: SourceViewMode.py    Apache License 2.0 5 votes vote down vote up
def draw(self, refresh=False):
        if self.dataModel.getOffset() in self.Paints:
            self.refresh = False
            self.qpix = QtGui.QPixmap(self.Paints[self.dataModel.getOffset()])
            self.drawAdditionals()
            return

        if self.refresh or refresh:
            qp = QtGui.QPainter()
            qp.begin(self.qpix)
            self.drawTextMode(qp)
            self.refresh = False
            qp.end()

        self.drawAdditionals() 
Example 33
Project: dcc   Author: amimo   File: binwindow.py    Apache License 2.0 5 votes vote down vote up
def paintEvent(self, e):
        qp = QtGui.QPainter()
        qp.begin(self)
        qp.setOpacity(1)

        offsetLeft = self.offsetWindow_h + self.Banners.getLeftOffset()
        offsetBottom = self.offsetWindow_v + self.Banners.getTopOffset()

        qp.drawPixmap(offsetLeft, offsetBottom, self.viewMode.getPixmap())

        self.Banners.draw(qp, self.offsetWindow_h, self.offsetWindow_v, self.size().height())

        qp.end() 
Example 34
Project: kucher   Author: Zubax   File: style_option_modifying_delegate.py    GNU General Public License v3.0 5 votes vote down vote up
def paint(self, painter: QPainter, option: QStyleOptionViewItem, index: QModelIndex):
        if self._decoration_position is not None:
            option.decorationPosition = self._decoration_position

        if self._decoration_alignment is not None:
            option.decorationAlignment = self._decoration_alignment

        super(StyleOptionModifyingDelegate, self).paint(painter, option, index) 
Example 35
Project: kucher   Author: Zubax   File: editor_delegate.py    GNU General Public License v3.0 5 votes vote down vote up
def paint(self, painter: QPainter, option: QStyleOptionViewItem, index: QModelIndex):
        """
        Reposition the icon to the right side.
        """
        option.decorationPosition = QStyleOptionViewItem.Right
        option.decorationAlignment = Qt.AlignRight | Qt.AlignVCenter
        super(EditorDelegate, self).paint(painter, option, index) 
Example 36
Project: SpriteMator   Author: rafaelvasco   File: main_window.py    Apache License 2.0 5 votes vote down vote up
def paintEvent(self, e):

        if not self._workspaceVisible:
            p = QPainter(self)

            x = self.width() / 2 - self._logo.width() / 2
            y = self.height() / 2 - self._logo.height() / 2

            p.drawPixmap(x, y, self._logo)

            p.drawText(x + 50, y + 200,
                       '.:: SpriteMator ::. | Version: %s' % app_data.meta['VERSION']) 
Example 37
Project: SpriteMator   Author: rafaelvasco   File: draggable_list_base_widget.py    Apache License 2.0 5 votes vote down vote up
def paintEvent(self, e):

        painter = QPainter(self)

        painter.translate(0, self._scrollOffset)

        for layerItem in self._items:

            if not layerItem.is_dragged:
                layerItem.draw(painter)

        if self._draggedItem is not None:
            self._draggedItem.draw(painter)

            #------------------------------------------------------------------------------- 
Example 38
Project: SpriteMator   Author: rafaelvasco   File: color_picker_widget.py    Apache License 2.0 5 votes vote down vote up
def paintEvent(self, e):
        p = QPainter(self)

        paint_rect = e.rect()

        half_width = paint_rect.width() / 2
        paint_rect.adjust(0, 0, -half_width, -2)

        if self._primaryColor:

            if self._primaryColor.alpha() < 255:
                p.drawTiledPixmap(paint_rect, self._background)

            p.fillRect(paint_rect, self._primaryColor)
            if self._activeColorIndex == ColorIndex.Primary:
                p.fillRect(paint_rect.adjusted(0, paint_rect.height(), 0, paint_rect.height() + 2),
                           QColor("red"))

        if self._secondaryColor:

            second_box_rect = paint_rect.translated(half_width, 0)

            if self._primaryColor.alpha() < 255:
                p.drawTiledPixmap(second_box_rect, self._background)

            p.fillRect(second_box_rect, self._secondaryColor)
            if self._activeColorIndex == ColorIndex.Secondary:
                p.fillRect(paint_rect.adjusted(paint_rect.width(), paint_rect.height(),
                                               paint_rect.width(),
                                               paint_rect.height() + 2), QColor("red"))

        if self._previewColor:

            if self._activeColorIndex == ColorIndex.Primary:
                p.fillRect(paint_rect, self._previewColor)
            else:
                p.fillRect(paint_rect.translated(half_width, 0), self._previewColor) 
Example 39
Project: SpriteMator   Author: rafaelvasco   File: options_bar_widget.py    Apache License 2.0 5 votes vote down vote up
def paintEvent(self, e):

        painter = QPainter(self)

        painter.setOpacity(0.5)
        painter.fillRect(self.rect(), self._backgroundColor) 
Example 40
Project: SpriteMator   Author: rafaelvasco   File: sprite.py    Apache License 2.0 5 votes vote down vote up
def resize(self, width, height):

        new_image = utils.create_image(width, height)

        painter = QPainter(new_image)

        painter.drawImage(0, 0, self._image)

        self._image = new_image

        self._resize_pixel_buffer() 
Example 41
Project: eddy   Author: obdasystems   File: dock.py    GNU General Public License v3.0 5 votes vote down vote up
def paintEvent(self, paintEvent):
        """
        This is needed for the widget to pick the stylesheet.
        :type paintEvent: QPaintEvent
        """
        option = QtWidgets.QStyleOption()
        option.initFrom(self)
        painter = QtGui.QPainter(self)
        style = self.style()
        style.drawPrimitive(QtWidgets.QStyle.PE_Widget, option, painter, self) 
Example 42
Project: eddy   Author: obdasystems   File: welcome.py    GNU General Public License v3.0 5 votes vote down vote up
def paintEvent(self, paintEvent):
        """
        This is needed for the widget to pick the stylesheet.
        :type paintEvent: QPaintEvent
        """
        option = QtWidgets.QStyleOption()
        option.initFrom(self)
        painter = QtGui.QPainter(self)
        style = self.style()
        style.drawPrimitive(QtWidgets.QStyle.PE_Widget, option, painter, self)

    #############################################
    #   SLOTS
    ################################# 
Example 43
Project: eddy   Author: obdasystems   File: welcome.py    GNU General Public License v3.0 5 votes vote down vote up
def paintEvent(self, paintEvent):
        """
        This is needed for the widget to pick the stylesheet.
        :type paintEvent: QPaintEvent
        """
        option = QtWidgets.QStyleOption()
        option.initFrom(self)
        painter = QtGui.QPainter(self)
        style = self.style()
        style.drawPrimitive(QtWidgets.QStyle.PE_Widget, option, painter, self) 
Example 44
Project: eddy   Author: obdasystems   File: splash.py    GNU General Public License v3.0 5 votes vote down vote up
def paintEvent(self, paintEvent):
        """
        Executed when the splashscreen needs to be painted.
        :type paintEvent: QPaintEvent
        """
        painter = QtGui.QPainter(self)
        # APPNAME
        painter.setFont(self.font1)
        painter.setPen(QtGui.QPen(QtGui.QColor(255, 255, 255), 1.0, QtCore.Qt.SolidLine))
        painter.drawText(QtCore.QRect(31 + self.__spaceX, 138 + self.__spaceY, 380, 400), QtCore.Qt.AlignTop|QtCore.Qt.AlignLeft, APPNAME)
        # VERSION
        painter.setFont(self.font2)
        painter.setPen(QtGui.QPen(QtGui.QColor(255, 255, 255), 1.0, QtCore.Qt.SolidLine))
        painter.drawText(QtCore.QRect(34 + self.__spaceX, 185 + self.__spaceY, 380, 400), QtCore.Qt.AlignTop|QtCore.Qt.AlignLeft, 'Version {0}'.format(VERSION))
        # COPYRIGHT
        painter.setFont(self.font3)
        painter.setPen(QtGui.QPen(QtGui.QColor(122, 101, 104), 1.0, QtCore.Qt.SolidLine))
        painter.drawText(QtCore.QRect(0 + self.__spaceX, 220 + self.__spaceY, 360, 40), QtCore.Qt.AlignTop|QtCore.Qt.AlignHCenter, COPYRIGHT)
        # CREDITS
        painter.setFont(self.font3)
        painter.setPen(QtGui.QPen(QtGui.QColor(122, 101, 104), 1.0, QtCore.Qt.SolidLine))
        painter.drawText(QtCore.QRect(0 + self.__spaceX, 273 + self.__spaceY, 360, 80), QtCore.Qt.AlignTop|QtCore.Qt.AlignHCenter, CREDITS)
        # LICENSE
        painter.setFont(self.font3)
        painter.setPen(QtGui.QPen(QtGui.QColor(122, 101, 104), 1.0, QtCore.Qt.SolidLine))
        painter.drawText(QtCore.QRect(0 + self.__spaceX, 286 + self.__spaceY, 360, 40), QtCore.Qt.AlignTop|QtCore.Qt.AlignHCenter, LICENSE) 
Example 45
Project: eddy   Author: obdasystems   File: image.py    GNU General Public License v3.0 5 votes vote down vote up
def run(self, path):
        """
        Perform JPEG document generation.
        :type path: str
        """

        shape = self.diagram.visibleRect(margin=220)

        empty_image = QtGui.QImage(int(shape.width()), int(shape.height()),QtGui.QImage.Format_RGB32)
        empty_image.invertPixels()

        pixmap = QtGui.QPixmap(empty_image)

        painter = QtGui.QPainter()

        started = painter.begin(pixmap)

        if started:
            self.diagram.render(painter,source=shape)

            image = pixmap.toImage()

            #pixmap.save(path)
            image.save(path)

            painter.end()

            self.success = True 
Example 46
Project: eddy   Author: obdasystems   File: printer.py    GNU General Public License v3.0 5 votes vote down vote up
def run(self, *args, **kwargs):
        """
        Print the diagram.
        """
        shape = self.diagram.visibleRect(margin=220)
        if shape:
            printer = QtPrintSupport.QPrinter(QtPrintSupport.QPrinter.HighResolution)
            printer.setOutputFormat(QtPrintSupport.QPrinter.NativeFormat)
            dialog = QtPrintSupport.QPrintDialog(printer)
            if dialog.exec_() == QtPrintSupport.QPrintDialog.Accepted:
                painter = QtGui.QPainter()
                if painter.begin(printer):
                    # TURN CACHING OFF
                    for item in self.diagram.items():
                        if item.isNode() or item.isEdge():
                            item.setCacheMode(AbstractItem.NoCache)
                    # RENDER THE DIAGRAM IN THE PAINTER
                    self.diagram.render(painter, source=shape)
                    # TURN CACHING ON
                    for item in self.diagram.items():
                        if item.isNode() or item.isEdge():
                            item.setCacheMode(AbstractItem.DeviceCoordinateCache)
                    # COMPLETE THE PRINT
                    painter.end()

                    self.success = True 
Example 47
Project: eddy   Author: obdasystems   File: palette.py    GNU General Public License v3.0 5 votes vote down vote up
def paintEvent(self, paintEvent):
        """
        This is needed for the widget to pick the stylesheet.
        :type paintEvent: QPaintEvent
        """
        option = QtWidgets.QStyleOption()
        option.initFrom(self)
        painter = QtGui.QPainter(self)
        style = self.style()
        style.drawPrimitive(QtWidgets.QStyle.PE_Widget, option, painter, self)

    #############################################
    #   INTERFACE
    ################################# 
Example 48
Project: eddy   Author: obdasystems   File: info.py    GNU General Public License v3.0 5 votes vote down vote up
def paintEvent(self, paintEvent):
        """
        This is needed for the widget to pick the stylesheet.
        :type paintEvent: QPaintEvent
        """
        option = QtWidgets.QStyleOption()
        option.initFrom(self)
        painter = QtGui.QPainter(self)
        style = self.style()
        style.drawPrimitive(QtWidgets.QStyle.PE_Widget, option, painter, self)


#############################################
#   INFO WIDGETS
################################# 
Example 49
Project: eddy   Author: obdasystems   File: project_explorer.py    GNU General Public License v3.0 5 votes vote down vote up
def paintEvent(self, paintEvent):
        """
        This is needed for the widget to pick the stylesheet.
        :type paintEvent: QPaintEvent
        """
        option = QtWidgets.QStyleOption()
        option.initFrom(self)
        painter = QtGui.QPainter(self)
        style = self.style()
        style.drawPrimitive(QtWidgets.QStyle.PE_Widget, option, painter, self)

    #############################################
    #   INTERFACE
    ################################# 
Example 50
Project: eddy   Author: obdasystems   File: Explanation_explorer.py    GNU General Public License v3.0 5 votes vote down vote up
def paintEvent(self, paintEvent):
        """
        This is needed for the widget to pick the stylesheet.
        :type paintEvent: QPaintEvent
        """
        option = QtWidgets.QStyleOption()
        option.initFrom(self)
        painter = QtGui.QPainter(self)
        style = self.style()
        style.drawPrimitive(QtWidgets.QStyle.PE_Widget, option, painter, self)

    #############################################
    #   SLOTS
    #################################