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: 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 20
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 21
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 22
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 23
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 24
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 25
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 26
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 27
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 28
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 29
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 30
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 31
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 32
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 33
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 34
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 35
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 36
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 37
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 38
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 39
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 40
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 41
Project: eddy   Author: obdasystems   File: view.py    GNU General Public License v3.0 5 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 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
    ################################# 
Example 51
Project: eddy   Author: obdasystems   File: Unsatisfiable_Entity_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
    ################################# 
Example 52
Project: hpimon   Author: jjnurminen   File: hpimon.py    MIT License 5 votes vote down vote up
def paintEvent(self, event):
        painter = QtGui.QPainter()
        painter.begin(self)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        painter.setBrush(QtGui.QColor(self.color))
        painter.drawEllipse(0, 0, self.diam, self.diam)
        painter.end() 
Example 53
Project: visma   Author: aerospaceresearch   File: window.py    GNU General Public License v3.0 5 votes vote down vote up
def paintEvent(self, event):
        painter = QPainter(self)
        painter.drawPixmap(event.rect(), self.pixmap) 
Example 54
Project: SeamEater   Author: Entscheider   File: imgshowwdg.py    GNU General Public License v3.0 5 votes vote down vote up
def mousePressEvent(self, event):
        if self.__pixmap:
            self.__pressing = True
            self.__painter = guig.QPainter(self.__pixmap)
            self.__painter.setBrush(guig.QBrush(guig.QColor(0, 0, 0))) 
Example 55
Project: pyqt5-widgets   Author: mfitzp   File: power_bar.py    MIT License 5 votes vote down vote up
def paintEvent(self, e):
        painter = QtGui.QPainter(self)

        brush = QtGui.QBrush()
        brush.setColor(self._background_color)
        brush.setStyle(Qt.SolidPattern)
        rect = QtCore.QRect(0, 0, painter.device().width(), painter.device().height())
        painter.fillRect(rect, brush)

        # Get current state.
        parent = self.parent()
        vmin, vmax = parent.minimum(), parent.maximum()
        value = parent.value()

        # Define our canvas.
        d_height = painter.device().height() - (self._padding * 2)
        d_width = painter.device().width() - (self._padding * 2)

        # Draw the bars.
        step_size = d_height / self.n_steps
        bar_height = step_size * self._bar_solid_percent
        bar_spacer = step_size * (1 - self._bar_solid_percent) / 2

        # Calculate the y-stop position, from the value in range.
        pc = (value - vmin) / (vmax - vmin)
        n_steps_to_draw = int(pc * self.n_steps)

        for n in range(n_steps_to_draw):
            brush.setColor(QtGui.QColor(self.steps[n]))
            rect = QtCore.QRect(
                self._padding,
                self._padding + d_height - ((1 + n) * step_size) + bar_spacer,
                d_width,
                bar_height
            )
            painter.fillRect(rect, brush)

        painter.end() 
Example 56
Project: pyqt5-widgets   Author: mfitzp   File: equalizer_bar.py    MIT License 5 votes vote down vote up
def paintEvent(self, e):
        painter = QtGui.QPainter(self)

        brush = QtGui.QBrush()
        brush.setColor(self._background_color)
        brush.setStyle(Qt.SolidPattern)
        rect = QtCore.QRect(0, 0, painter.device().width(), painter.device().height())
        painter.fillRect(rect, brush)

        # Define our canvas.
        d_height = painter.device().height() - (self._padding * 2)
        d_width = painter.device().width() - (self._padding * 2)

        # Draw the bars.
        step_y = d_height / self.n_steps
        bar_height = step_y * self._y_solid_percent
        bar_height_space = step_y * (1 - self._x_solid_percent) / 2

        step_x = d_width / self.n_bars
        bar_width = step_x * self._x_solid_percent
        bar_width_space = step_x * (1 - self._y_solid_percent) / 2

        for b in range(self.n_bars):

            # Calculate the y-stop position for this bar, from the value in range.
            pc = (self._values[b] - self._vmin) / (self._vmax - self._vmin)
            n_steps_to_draw = int(pc * self.n_steps)

            for n in range(n_steps_to_draw):
                brush.setColor(QtGui.QColor(self.steps[n]))
                rect = QtCore.QRect(
                    self._padding + (step_x * b) + bar_width_space,
                    self._padding + d_height - ((1 + n) * step_y) + bar_height_space,
                    bar_width,
                    bar_height
                )
                painter.fillRect(rect, brush)

        painter.end() 
Example 57
Project: pyqt5-widgets   Author: mfitzp   File: gradient.py    MIT License 5 votes vote down vote up
def paintEvent(self, e):
        painter = QtGui.QPainter(self)
        width = painter.device().width()
        height = painter.device().height()

        # Draw the linear horizontal gradient.
        gradient = QtGui.QLinearGradient(0, 0, width, 0)
        for stop, color in self._gradient:
            gradient.setColorAt(stop, QtGui.QColor(color))

        rect = QtCore.QRect(0, 0, width, height)
        painter.fillRect(rect, gradient)

        pen = QtGui.QPen()

        y = painter.device().height() / 2


        # Draw the stop handles.
        for stop, _ in self._gradient:
            pen.setColor(QtGui.QColor('white'))
            painter.setPen(pen)

            painter.drawLine(stop * width, y - self._handle_h, stop * width, y + self._handle_h)

            pen.setColor(QtGui.QColor('red'))
            painter.setPen(pen)

            rect = QtCore.QRect(
                stop * width - self._handle_w/2,
                y - self._handle_h/2,
                self._handle_w,
                self._handle_h
            )
            painter.drawRect(rect)

        painter.end() 
Example 58
Project: PaintsTensorFlow   Author: seekerzz   File: Painter.py    MIT License 5 votes vote down vote up
def mouseMoveEvent(self, e):
        if (e.buttons() & Qt.LeftButton) & self.drawing:
            painter = QPainter(self.color_info)
            painter.setPen(self.pen)
            painter.drawLine(self.last_point, e.pos())
            self.last_point = e.pos()
            self.update() 
Example 59
Project: PaintsTensorFlow   Author: seekerzz   File: Painter.py    MIT License 5 votes vote down vote up
def paintEvent(self, e):
        try:

            canvas_painter = QPainter(self)
            np_img = self.setpixmap(self.image, self.color_info)
            img = Img.fromarray(np_img)
            img = ImageQt(img)
            canvas_painter.drawPixmap(self.canvas.rect(),
                                      QPixmap.fromImage(img),
                                      self.canvas.rect())
        except TypeError:
            pass 
Example 60
Project: interSubs   Author: oltodosel   File: interSubs.py    MIT License 5 votes vote down vote up
def draw_text_n_outline(self, painter: QPainter, x, y, outline_width, outline_blur, text):
		outline_color = QColor(config.outline_color)

		font = self.font()
		text_path = QPainterPath()
		if config.R2L_from_B:
			text_path.addText(x, y, font, ' ' + r2l(text.strip()) + ' ')
		else:
			text_path.addText(x, y, font, text)

		# draw blur
		range_width = range(outline_width, outline_width + outline_blur)
		# ~range_width = range(outline_width + outline_blur, outline_width, -1)

		for width in range_width:
			if width == min(range_width):
				alpha = 200
			else:
				alpha = (max(range_width) - width) / max(range_width) * 200

			blur_color = QColor(outline_color.red(), outline_color.green(), outline_color.blue(), alpha)
			blur_brush = QBrush(blur_color, Qt.SolidPattern)
			blur_pen = QPen(blur_brush, width, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)

			painter.setPen(blur_pen)
			painter.drawPath(text_path)

		# draw outline
		outline_color = QColor(outline_color.red(), outline_color.green(), outline_color.blue(), 255)
		outline_brush = QBrush(outline_color, Qt.SolidPattern)
		outline_pen = QPen(outline_brush, outline_width, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)

		painter.setPen(outline_pen)
		painter.drawPath(text_path)

		# draw text
		color = self.palette().color(QPalette.Text)
		painter.setPen(color)
		painter.drawText(x, y, text) 
Example 61
Project: FIRST-plugin-ida   Author: vrtadmin   File: first.py    GNU General Public License v2.0 5 votes vote down vote up
def drawRow(self, painter, option, index):
                '''Draws the row in the tree view that contains the model item
                index, using the painter given. The option control how the item
                is displayed.

                Args:
                    painter (:obj:`QtGui.QPainter`): Painter
                    option (:obj:`QtGui.QStyleOptionViewItem`): Options
                    index (:obj:`QtCore.QModelIndex`): Index
                '''
                metadata_id = index.data(FIRSTUI.ROLE_ID)
                header = self.header()
                firstSection = header.logicalIndex(0)
                left = header.sectionViewportPosition(firstSection)
                indent = self.__depth * self.indentation()

                if (index.data(FIRSTUI.ROLE_COMMENT)
                    and (index.row() == 0) and (index.column() == 0)):
                    lastSection = header.logicalIndex(header.count() - 1)
                    right = header.sectionViewportPosition(lastSection) + header.sectionSize(lastSection)

                    left += indent;

                    option.rect.setX(left)
                    option.rect.setWidth(right - left)

                    self.itemDelegate(index).paint(painter, option, index)

                else:
                    super(FIRST.Model.TreeView, self).drawRow(painter, option, index) 
Example 62
Project: Computer-graphics   Author: Panda-Lewandowski   File: lab6.py    MIT License 5 votes vote down vote up
def draw_edges(image, edges):
    p = QPainter()
    p.begin(image)
    p.setPen(QPen(QColor(0, 0, 255)))
    for ed in edges:
        p.drawLine(ed[0], ed[1], ed[2], ed[3])
    p.end() 
Example 63
Project: Computer-graphics   Author: Panda-Lewandowski   File: lab6.py    MIT License 5 votes vote down vote up
def draw_circle(image, rad, point):
    p = QPainter()
    p.begin(image)
    p.setPen(QPen(QColor(0, 0, 255)))
    p.drawEllipse(point.x() - rad, point.y() - rad, rad * 2, rad * 2)
    p.end() 
Example 64
Project: Computer-graphics   Author: Panda-Lewandowski   File: lab5.py    MIT License 5 votes vote down vote up
def draw_edges(image, edges):
    p = QPainter()
    p.begin(image)
    p.setPen(QPen(col_one))
    for ed in edges:
        p.drawLine(ed[0], ed[1], ed[2], ed[3])
    p.end() 
Example 65
Project: MNIST_Recognition   Author: jiweibo   File: gui.py    MIT License 5 votes vote down vote up
def mouseMoveEvent(self, QMouseEvent):
        painter = QPainter()
        pen = QPen()

        pen.setStyle(self.init_style)
        pen.setWidth(self.init_weight)
        pen.setColor(self.init_color)

        painter.begin(self.pix)
        painter.setPen(pen)
        painter.drawLine(self.start_pos, QMouseEvent.pos())
        painter.end()

        self.start_pos = QMouseEvent.pos()
        self.update() 
Example 66
Project: MNIST_Recognition   Author: jiweibo   File: gui.py    MIT License 5 votes vote down vote up
def paintEvent(self, QPaintEvent):
        painter = QPainter()
        painter.drawPixmap(QPoint(0, 0), self.pix)
        self.label.setPixmap(self.pix) 
Example 67
Project: MNIST_Recognition   Author: jiweibo   File: gui.py    MIT License 5 votes vote down vote up
def resizeEvent(self, QResizeEvent):
        if self.height() > self.pix.height() or self.width() > self.pix.width():
            new_pix = QPixmap(self.size())
            new_pix.fill(Qt.white)

            painter = QPainter(new_pix)
            painter.drawPixmap(QPoint(0, 0), self.pix)

            self.pix = new_pix

        QWidget.resizeEvent(self, QResizeEvent) 
Example 68
Project: PyFEM   Author: jjcremmers   File: XPyFEM.py    GNU General Public License v3.0 5 votes vote down vote up
def paintEvent(self, e):

    dc = QtGui.QPainter(self)
    dc.drawLine(0, 0, 100, 100)
    dc.drawLine(100, 0, 0, 100) 
Example 69
Project: PyRHEED   Author: yux1991   File: canvas.py    MIT License 5 votes vote down vote up
def save_scene(self):
        imageFileName = QtWidgets.QFileDialog.getSaveFileName(None,"choose save file name","./pattern.jpeg",\
                                                                   "Image (*.jpeg)")
        rect = self._scene.sceneRect()
        capture = QtGui.QImage(rect.size().toSize(),QtGui.QImage.Format_ARGB32_Premultiplied)
        painter = QtGui.QPainter(capture)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        self._scene.render(painter,QtCore.QRectF(capture.rect()),QtCore.QRectF(rect))
        painter.end()
        capture.save(imageFileName[0]) 
Example 70
Project: PyRHEED   Author: yux1991   File: profile_chart.py    MIT License 5 votes vote down vote up
def __init__(self,config):
        super(ProfileChart,self).__init__()
        chartDefault = dict(config['chartDefault'].items())
        if int(chartDefault['theme']) == 0:
            self.theme = QtChart.QChart.ChartThemeLight
        if int(chartDefault['theme']) == 1:
            self.theme = QtChart.QChart.ChartThemeBlueCerulean
        if int(chartDefault['theme']) == 2:
            self.theme = QtChart.QChart.ChartThemeDark
        if int(chartDefault['theme']) == 3:
            self.theme = QtChart.QChart.ChartThemeBrownSand
        if int(chartDefault['theme']) == 4:
            self.theme = QtChart.QChart.ChartThemeBlueNcs
        if int(chartDefault['theme']) == 5:
            self.theme = QtChart.QChart.ChartThemeHighContrast
        if int(chartDefault['theme']) == 6:
            self.theme = QtChart.QChart.ChartThemeBlueIcy
        if int(chartDefault['theme']) == 7:
            self.theme = QtChart.QChart.ChartThemeQt

        self.setRenderHint(QtGui.QPainter.Antialiasing)
        self._scaleFactor = 1
        self.setContentsMargins(0,0,0,0)
        self.profileChart = QtChart.QChart()
        self.profileChart.setBackgroundRoundness(0)
        self.profileChart.setMargins(QtCore.QMargins(0,0,0,0))
        self.profileChart.setTheme(self.theme)
        self.setChart(self.profileChart)
        self.image_worker = Image() 
Example 71
Project: MusicBox   Author: HuberTRoy   File: desktopLyricButtons.py    MIT License 5 votes vote down vote up
def paintEvent(self,event):
        self.painter = QtGui.QPainter()
        self.painter.begin(self)
        self.painter.drawPixmap(self.rect(), self.pixmap.copy(0, self.btn_height * self.status, self.btn_width, self.btn_height))
        self.painter.end() 
Example 72
Project: MusicBox   Author: HuberTRoy   File: desktopLyricButtons.py    MIT License 5 votes vote down vote up
def paintEvent(self,event):
        self.painter = QtGui.QPainter()
        self.painter.begin(self)
        self.painter.drawPixmap(self.rect(), self.pixmap.copy(self.btn_width * self.status, 0, self.btn_width, self.btn_height))
        self.painter.end() 
Example 73
Project: MusicBox   Author: HuberTRoy   File: desktopLyricButtons.py    MIT License 5 votes vote down vote up
def paintEvent(self,event):
        self.painter = QtGui.QPainter()
        self.painter.begin(self)
        self.painter.drawPixmap(self.rect(), self.pixmap.copy(0, 0, self.btn_width, self.btn_height))
        self.painter.end() 
Example 74
Project: MusicBox   Author: HuberTRoy   File: player.py    MIT License 5 votes vote down vote up
def paintEvent(self, event):
        painter = QPainter(self)
        painter.setFont(self.font)
        
        linear = QLinearGradient(QPoint(self.rect().topLeft()), QPoint(self.rect().bottomLeft()))
        linear.setStart(0, 10)
        linear.setFinalStop(0, 50)
        linear.setColorAt(0.1, QColor(14, 179, 255));
        linear.setColorAt(0.5, QColor(154, 232, 255));
        linear.setColorAt(0.9, QColor(14, 179, 255));
        
        linear2 = QLinearGradient(QPoint(self.rect().topLeft()), QPoint(self.rect().bottomLeft()))
        linear2.setStart(0, 10)
        linear2.setFinalStop(0, 50)
        linear2.setColorAt(0.1, QColor(222, 54, 4));
        linear2.setColorAt(0.5, QColor(255, 172, 116));
        linear2.setColorAt(0.9, QColor(222, 54, 4));
        
        painter.setPen(QColor(0, 0, 0, 200));
        painter.drawText(QRect(1, 1, self.screen.width(), 60), Qt.AlignHCenter | Qt.AlignVCenter, self.lyric)
        
        painter.setPen(QColor('transparent'));
        self.textRect = painter.drawText(QRect(0, 0, self.screen.width(), 60), Qt.AlignHCenter | Qt.AlignVCenter, self.lyric)

        painter.setPen(QPen(linear, 0))
        painter.drawText(self.textRect, Qt.AlignLeft | Qt.AlignVCenter, self.lyric)
        if self.intervel != 0:
            self.widthBlock = self.textRect.width()/(self.intervel/150.0)
        else:
            self.widthBlock = 0
        self.maskRect = QRectF(self.textRect.x(), self.textRect.y(), self.textRect.width(), self.textRect.height())
        self.maskRect.setWidth(self.maskWidth)
        painter.setPen(QPen(linear2, 0));
        painter.drawText(self.maskRect, Qt.AlignLeft | Qt.AlignVCenter, self.lyric) 
Example 75
Project: dcc   Author: amimo   File: BinViewMode.py    Apache License 2.0 4 votes vote down vote up
def scroll_h(self, dx):
        self.qpix.scroll(dx * self.fontWidth, 0, self.qpix.rect())

        qp = QtGui.QPainter()

        qp.begin(self.qpix)
        qp.setFont(self.font)
        qp.setPen(self.textPen)

        factor = abs(dx)
        if dx < 0:
            qp.fillRect((self.COLUMNS - 1 * factor) * self.fontWidth, 0, factor * self.fontWidth,
                        self.ROWS * self.fontHeight + self.SPACER, self.backgroundBrush)
        if dx > 0:
            qp.fillRect(0, 0, factor * self.fontWidth, self.ROWS * self.fontHeight + self.SPACER, self.backgroundBrush)

        cemu = ConsoleEmulator(qp, self.ROWS, self.COLUMNS)

        page = self.transformationEngine.decorate()
        # scriem pe fiecare coloana in parte
        for column in range(factor):
            # fiecare caracter de pe coloana
            for i in range(self.ROWS):

                if dx < 0:
                    # cu (column) selectam coloana
                    idx = (i + 1) * self.COLUMNS - (column + 1)
                if dx > 0:
                    idx = i * self.COLUMNS + column

                # c = self.dataModel.getDisplayablePage()[idx]
                c = self.transformationEngine.getChar(idx)
                qp.setPen(self.transformationEngine.choosePen(idx))

                if self.transformationEngine.chooseBrush(idx) is not None:
                    qp.setBackgroundMode(1)
                    qp.setBackground(self.transformationEngine.chooseBrush(idx))


                #                self.decorate(qp, (idx, c), self.dataModel.getDisplayablePage())
                if dx < 0:
                    cemu.writeAt(self.COLUMNS - (column + 1), i, self.cp437(c))

                if dx > 0:
                    cemu.writeAt(column, i, self.cp437(c))

                qp.setBackgroundMode(0)
        qp.end() 
Example 76
Project: SpriteMator   Author: rafaelvasco   File: animation_manager_widget.py    Apache License 2.0 4 votes vote down vote up
def paintEvent(self, e):

        p = QPainter(self)

        current_frame_index = self._sprite.current_animation.current_frame_index

        frame_list = self._sprite.current_animation.frames

        frame_size = self._frameSize
        frame_padding = self._framePadding
        half_padding = frame_padding // 2
        two_padding = frame_padding * 2

        if self._horizontalShift != 0:
            p.translate(-self._horizontalShift, 0)

        for frameIndex, frame in enumerate(frame_list):

            surfaces = frame.surfaces

            frame_rect = QRect(
                frame_padding + frameIndex * frame_size + two_padding * frameIndex,
                frame_padding,
                frame_size,
                frame_size)

            if current_frame_index == frameIndex:
                p.setPen(self._pen)

                p.drawRect(frame_rect.adjusted(-half_padding, -half_padding,
                                               half_padding, half_padding))

                p.setPen(Qt.black)

                p.drawRect(frame_rect.adjusted(-1, -1, 0, 0))

            p.drawTiledPixmap(frame_rect, self._checkerTile)

            for surface in surfaces:
                p.drawImage(frame_rect, surface.image, surface.image.rect())

            p.setPen(Qt.black)
            p.drawText(frame_rect.left() + two_padding,
                       frame_rect.top() + two_padding * 2, str(frameIndex + 1)) 
Example 77
Project: SpriteMator   Author: rafaelvasco   File: color_picker_widget.py    Apache License 2.0 4 votes vote down vote up
def paintEvent(self, e):

        p = QPainter(self)

        # Paint border

        bar_rect = self.rect().adjusted(0, 15, 0, -1)

        if self._background is not None:
            p.drawTiledPixmap(bar_rect, self._background)

        pen = QPen()
        pen.setColor(Qt.black)
        pen.setWidth(1)

        p.setPen(pen)

        bar_rect.adjust(0, 0, -1, 0)

        p.drawRect(bar_rect)

        p.setPen(Qt.white)

        # Paint Spectrum

        bar_rect.adjust(1, 1, 0, 0)

        p.fillRect(bar_rect, QBrush(self._gradient))

        # Paint Picker

        p.drawPixmap(self._pickRect, self._pickerPixmap)

        # Draw Label

        label_rect = QRect(200, 1, 20, 15)

        p.drawText(label_rect, Qt.AlignRight, str(self._value))

        if len(self._label) > 0:
            label_rect.adjust(-200, 0, 0, 0)
            p.drawText(label_rect, Qt.AlignLeft, self._label)


# ----------------------------------------------------------------------------- 
Example 78
Project: hexutil   Author: stephanh42   File: example.py    MIT License 4 votes vote down vote up
def paintEvent(self, event):
        # compute center of window
        size = self.size()
        xc = size.width()//2
        yc = size.height()//2
        # bounding box when we translate the origin to be at the center
        bbox = hexutil.Rectangle(-xc, -yc, size.width(), size.height())
        hexgrid = self.hexgrid
        painter = QtGui.QPainter()
        painter.begin(self)
        try:
            # paint background black
            painter.save()
            painter.setPen(QtCore.Qt.NoPen)
            painter.setBrush(QtGui.QColor())
            painter.drawRect(0, 0, size.width(), size.height())
            painter.restore()

            # set up drawing state
            painter.setPen(self.pen)
            painter.setRenderHint(QtGui.QPainter.Antialiasing)
            painter.setRenderHint(QtGui.QPainter.TextAntialiasing)
            painter.setFont(self.font)
            painter.translate(xc, yc)
            # draw each hexagon which is in the window
            for hexagon in hexgrid.hexes_in_rectangle(bbox):
                polygon = QtGui.QPolygon([QtCore.QPoint(*corner) for corner in hexgrid.corners(hexagon)])
                hexagon2 = hexagon + self.player
                tile = self.level.get_seen_tile(hexagon2)
                if tile == ' ':
                    continue
                painter.setBrush(self._tile_brushes[tile])
                painter.drawPolygon(polygon)
                if hexagon2 not in self.fov:
                    painter.setBrush(self.unseen_brush)
                    painter.drawPolygon(polygon)
                if hexagon2 in self.selected_path:
                    painter.setBrush(self.select_brush)
                    painter.drawPolygon(polygon)
                if hexagon2 == self.player:
                    rect = hexgrid.bounding_box(hexagon)
                    rect = QtCore.QRectF(*rect) # convert to Qt RectF
                    painter.drawText(rect, QtCore.Qt.AlignCenter, '@')
        finally:
            painter.end() 
Example 79
Project: screenrulerzoom   Author: ElMoribond   File: screenrulerzoom.py    GNU General Public License v3.0 4 votes vote down vote up
def paintEvent(self, event):
        qp, unit, cpt, min, mid, max=  QPainter(), self.unitMeasure[self.cUM][1][self.oH], -1, 10, 15, 20
        qp.begin(self)
        qp.setPen(self.colors[0][0][1])
        if self.zoom:
            if not self.moving:
                if self.pix is None:
                    self.saveBackground()
                qp.drawPixmap(0, 0, self.pix.scaled(self.size() * (self.zoom + 1), Qt.KeepAspectRatio))
            else:
                qp.setBrush(self.colors[1][0][1])
                qp.drawRect(-1, -1, self.width() + 1, self.height() + 1)
        else:
            qp.setBrush(self.colors[1][0][1])
            qp.drawRect(-1, -1, self.width() + 1, self.height() + 1)
            # Affichage de la graduation
            for i in range(self.height() if self.oH else self.width()):
                length= 0
                # Affichage en pixel
                if not self.cUM:
                    length, cpt= max if not i % 50 else mid if not i % 10 else min if not i % 2 else 0, cpt + 1
                # Autre unité
                else:
                    if (self.cUM in [ 1, 2, 3 ] and not i % unit) or (self.cUM == 4 and not i % round(unit)):
                        length, cpt= max, cpt+ 1
                    elif (self.cUM in [ 1, 2, 3 ] and not i % (unit / 4)) or (self.cUM == 4 and not i % round(unit / 2)):
                        length= min
                cS= self.fontMetrics().tightBoundingRect(str(cpt) if cpt else self.unitMeasure[self.cUM][0][1])
                # Affichage de l'unité
                if i == 1:
                    if self.oH:
                        qp.drawText((self.width() - cS.width()) / 2, cS.height(), self.unitMeasure[self.cUM][0][1])
                    else:
                        qp.drawText(3, self.height() / 2 + cS.height() / 3, self.unitMeasure[self.cUM][0][1])
                elif i and length:
                    if self.oH:
                        qp.drawLine(0, i, length, i)
                        qp.drawLine(self.width(), i, self.width() - length - 1, i)
                        if length == max:
                            qp.drawText((self.width() - cS.width()) / 2, i + cS.height() / 2, str(cpt))
                    else:
                        qp.drawLine(i, 0, i, length)
                        qp.drawLine(i, self.height(), i, self.height() - length - 1)
                        if length == max:
                            qp.drawText(i - cS.width() / 2, self.height() / 2 + cS.height() / 2, str(cpt))
            # Affichage de la position du curseur
            if self.cursor is not None and not Ruler.menu and (self.oH and self.mapFromParent(self.cursor).y() > -1 or not self.oH and self.mapFromParent(self.cursor).x() > -1) and (self.oH and self.mapFromParent(self.cursor).y() < self.height() or not self.oH and self.mapFromParent(self.cursor).x() < self.width()):
                self.drawCursorPosition(qp, self.mapFromParent(self.cursor))
            if not self.cUM:
                # Affichage des positions sauvegardés
                for m in self.mark:
                    self.drawCursorPosition(qp, m) 
Example 80
Project: Computer-graphics   Author: Panda-Lewandowski   File: lab5.py    MIT License 4 votes vote down vote up
def fill_xor(win):
    pix = QPixmap()
    p = QPainter()


    xm = int(find_max_y(win.edges))
    for ed in win.edges:
        p.begin(win.image)
        # если горизонтальное ребро - дальше
        if ed[1] == ed[3]:
            continue
        # иначе определяем границы сканирования
        if ed[1] > ed[3]:
            ed[1], ed[3] = ed[3], ed[1]

            ed[0], ed[2] = ed[2], ed[0]
            

        y = ed[1]
        end_y = ed[3]
        dx = (ed[2] - ed[0]) / (ed[3] - ed[1])
        start_x = ed[0]

        while y < end_y:
            # определяем пересечение

            x = start_x
            while x < xm:
                col = QColor(win.image.pixel(x, y))
                if col == col_zero:
                    p.setPen(QPen(col_one))
                else:
                    p.setPen(QPen(col_zero))
                p.drawPoint(x, y)
                x += 1

            start_x += dx
            y += 1

            if win.delay.isChecked():
                delay()
                pix.convertFromImage(win.image)
                win.scene.addPixmap(pix)

        if not win.delay.isChecked():
            pix.convertFromImage(win.image)
            win.scene.addPixmap(pix)
        p.end()
    draw_edges(win.image, win.edges)