Ejemplo n.º 1
0
    def paintEvent(self, event):
        """
        Overloads the paint event to handle painting pointers for the popup \
        mode.
        
        :param      event | <QPaintEvent>
        """
        # use the base technique for the dialog mode
        if self.currentMode() == XPopupWidget.Mode.Dialog:
            super(XPopupWidget, self).paintEvent(event)
            return

        # setup the coloring options
        palette = self.palette()

        painter = QPainter()
        painter.begin(self)

        pen = QPen(palette.color(palette.Window).darker(130))
        pen.setWidthF(1.75)
        painter.setPen(pen)
        painter.setRenderHint(painter.Antialiasing)
        painter.setBrush(palette.color(palette.Window))
        painter.drawPath(self.borderPath())
        painter.end()
Ejemplo n.º 2
0
 def _paint_bg(self, p: QPainter):
     dpi = Info.dpi
     pen = self.pen()
     p.setRenderHint(QPainter.Antialiasing, True)
     p.setPen(pen)
     p.setBrush(self.bg())
     p.drawRoundedRect(OIBlock.padding * dpi, OIBlock.padding * dpi,
                       self.width() - 2 * OIBlock.padding * dpi,
                       self.height() - 2 * OIBlock.padding * dpi,
                       OIBlock.radius * dpi, OIBlock.radius * dpi)
     p.setBrush(self.title_bg())
     p.drawRoundedRect(OIBlock.padding * dpi, OIBlock.padding * dpi,
                       self.width() - 2 * OIBlock.padding * dpi,
                       .35 * dpi + OIBlock.padding * dpi,
                       OIBlock.radius * dpi, OIBlock.radius * dpi)
     p.setBrush(self.bg())
     p.setPen(QColor(0, 0, 0, 0))
     p.drawRect(0.01 * dpi + OIBlock.padding * dpi,
                0.35 * dpi + OIBlock.padding * dpi,
                self.width() - 0.02 * dpi - 2 * OIBlock.padding * dpi,
                0.10 * dpi)
     p.setPen(pen)
     if self._resizable:
         if self.__corner_path is None:
             self.__init_corner()
         p.setBrush(pen.brush())
         p.drawPath(
             self.__corner_path.translated(self.width(), self.height()))
Ejemplo n.º 3
0
 def paintEvent(self, event):
     """
     Overloads the paint event to handle painting pointers for the popup \
     mode.
     
     :param      event | <QPaintEvent>
     """
     # use the base technique for the dialog mode
     if self.currentMode() == XPopupWidget.Mode.Dialog:
         super(XPopupWidget, self).paintEvent(event)
         return
     
     # setup the coloring options
     palette = self.palette()
     
     painter = QPainter()
     painter.begin(self)
     
     pen = QPen(palette.color(palette.Window).darker(130))
     pen.setWidthF(1.75)
     painter.setPen(pen)
     painter.setRenderHint(painter.Antialiasing)
     painter.setBrush(palette.color(palette.Window))
     painter.drawPath(self.borderPath())
     painter.end()
Ejemplo n.º 4
0
    def make_piece_from_path(o, piece_id, qpainter_path):
        # generate the mask, and call back to actually create the piec.
        path = qpainter_path
        path.closeSubpath()
        #determine the required size of the mask
        mask_rect = path.boundingRect().toAlignedRect()
        #create the mask
        mask = QImage(mask_rect.size(), QImage.Format_ARGB32_Premultiplied)
        # fully transparent color
        mask.fill(0x00000000)

        painter = QPainter(mask)
        painter.translate(-mask_rect.topLeft())
        #we explicitly use a pen stroke in order to let the pieces overlap a bit (which reduces rendering glitches at the edges where puzzle pieces touch)
        # 1.0 still leaves the slightest trace of a glitch. but making the stroke thicker makes the plugs appear non-matching even when they belong together.
        # 2016-06-18: changed to 0.5 -- bevel looks better
        painter.setPen(QPen(Qt.black, 0.5))
        if o.outline_only:
            painter.setBrush(Qt.NoBrush)
        else:
            painter.setBrush(Qt.SolidPattern)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.drawPath(path)
        painter.end()

        o.add_piece_func(piece_id=piece_id,
                         mask_image=mask,
                         offset=mask_rect.topLeft())
Ejemplo n.º 5
0
 def paintEvent(self,paintEvent):
     """设置背景图片,画线"""
     painter = QPainter(self)
     #设置背景图片
     painter.drawPixmap(self.rect(),QPixmap("images/background.png"))
     #获取四条线路径
     self.updateLinesPath()
     painter.setPen(QPen(QColor(Qt.lightGray),1))
     painter.drawPath(self.linesPath)
Ejemplo n.º 6
0
    def paintEvent(self, event):
        """ Reimplement the paint event

        """
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)
        palette = self.palette()
        painter.setPen(palette.dark().color())
        painter.setBrush(palette.window())
        painter.drawPath(self._path)
Ejemplo n.º 7
0
    def paintEvent(self, event):
        """ Reimplement the paint event

        """
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)
        palette = self.palette()
        painter.setPen(palette.dark().color())
        painter.setBrush(palette.window())
        painter.drawPath(self._path)
Ejemplo n.º 8
0
 def _paint_bg(self, p: QPainter):
     pen = self.pen()
     p.setRenderHint(QPainter.Antialiasing, True)
     p.setPen(pen)
     p.setBrush(self.bg())
     p.drawRoundedRect(Block.padding, Block.padding, self.width() - 2 * Block.padding,
                       self.height() - 2 * Block.padding, 8, 8)
     p.setPen(pen)
     if self._resizable:
         p.setBrush(pen.brush())
         p.drawPath(self._corner_path().translated(self.width(), self.height()))
Ejemplo n.º 9
0
 def paint(self, p: QPainter):
     if not self.n1.parent.isVisible() or (self.n2 is not None and not self.n2.parent.isVisible()):
         return
     if self.__path is None:
         self.compute_path()
     c = Block.border_color
     if self.selected:
         c = c.lighter().lighter()
     if not self.__status:
         c = QColor(255, 100, 100, 180)
     p.setPen(QPen(c, 4))
     p.drawPath(self.__path)
Ejemplo n.º 10
0
    def paintEvent(self, QPaintEvent):
        p = QPainter(self.viewport())

        clipPath = QPainterPath()
        clipPath.addEllipse(0, 0, 100, 100)

        p.setRenderHint(QPainter.Antialiasing)
        p.setClipPath(clipPath)
        p.setClipping(False)
        p.setPen(Qt.gray)
        p.drawPath(clipPath)
        self.update()
Ejemplo n.º 11
0
 def paintEvent(self, event):
 
     painter = QPainter()
     painter.begin(self)
     painter.setRenderHint(QPainter.Antialiasing)
     painter.setBrush(QBrush(QColor(192, 192, 255)))
     painter.drawRect(event.rect())
     
     painter.translate(self.width()/2.0, self.height()/2.0)
     painter.scale(self.width()*0.75/100.0, self.height()*0.75/100.0)
     painter.setBrush(QBrush(self.gradient))
     painter.drawPath(self.path)
     painter.end()
Ejemplo n.º 12
0
 def _paint_bg(self, p: QPainter):
     pen = Block.selected_pen if self.__selected else Block.border_pen
     p.setRenderHint(QPainter.Antialiasing, True)
     p.setPen(pen)
     p.setBrush(self.bg())
     p.drawRoundedRect(Block.padding, Block.padding, self.width() - 2 * Block.padding,
                       self.height() - 2 * Block.padding, 8, 8)
     p.setBrush(self.title_bg())
     p.drawRoundedRect(Block.padding, Block.padding, self.width() - 2 * Block.padding, 35 + Block.padding, 8, 8)
     p.setBrush(self.bg())
     p.setPen(QColor(0, 0, 0, 0))
     p.drawRect(1 + Block.padding, 35 + Block.padding, self.width() - 2 - 2 * Block.padding, 10)
     p.setPen(pen)
     if self._resizable:
         p.setBrush(pen.brush())
         p.drawPath(self.__corner_path.translated(self.width(), self.height()))
Ejemplo n.º 13
0
 def createAxisLabelPixmap(self):
     pixmap = QPixmap(250, 250)
     pixmap.fill(self.backgroundColor)
     painter = QPainter()
     painter.begin(pixmap)
     font = QFont()
     font.setBold(True)
     font.setPixelSize(250 - 30)
     path = QPainterPath()
     path.addText(QPointF(50, 250 - 50), font, self.axis)
     brush = QBrush(self.foregroundColor)
     painter.setBrush(brush)
     painter.drawPath(path)
     painter.setFont(font)
     painter.end()
     pixmap = pixmap.scaled(QSize(self.labelsWidth, self.labelsheight), Qt.KeepAspectRatio, Qt.SmoothTransformation)
     return pixmap
Ejemplo n.º 14
0
 def createAxisLabelPixmap(self):
     pixmap = QPixmap(250, 250)
     pixmap.fill(self.backgroundColor)
     painter = QPainter()
     painter.begin(pixmap)
     font = QFont()
     font.setBold(True)
     font.setPixelSize(250 - 30)
     path = QPainterPath()
     path.addText(QPointF(50, 250 - 50), font, self.axis)
     brush = QBrush(self.foregroundColor)
     painter.setBrush(brush)
     painter.drawPath(path)
     painter.setFont(font)
     painter.end()
     pixmap = pixmap.scaled(QSize(self.labelsWidth, self.labelsheight),
                            Qt.KeepAspectRatio, Qt.SmoothTransformation)
     return pixmap
Ejemplo n.º 15
0
    def paintEvent(self, event):
        painter = QPainter(self)
        btnRect = self.geometry()
        iconRect = self.iconSize()

        color = QColor(Qt.black)
        if self.hovered:
            color = self.color
        if self.pressed:
            color = self.color.darker(120)

        painter.setPen(QPen(QColor(Qt.lightGray), 2))
        outline = QPainterPath()
        outline.addRoundedRect(0, 0, btnRect.width(), btnRect.height(), 0, 0)
        painter.setOpacity(1)
        painter.drawPath(outline)

        painter.setBrush(QBrush(color))
        painter.setOpacity(self.opacity)
        painter_path = QPainterPath()
        painter_path.addRoundedRect(1, 1,
                                    btnRect.width() - 2,
                                    btnRect.height() - 2, 0, 0)
        if self.hovered:
            painter.setClipPath(painter_path)
            painter.drawRoundedRect(1, 1,
                                    btnRect.width() - 2,
                                    btnRect.height() - 2, 0, 0)

        painter.setOpacity(1)

        iconPos, textPos = self.calIconTextPos(btnRect, iconRect)
        # 重画文本
        if not self.text().isNull():
            painter.setFont(self.font())
            painter.setPen(QPen(QColor(Qt.black), 2))
            painter.drawText(textPos.x(), textPos.y(), textPos.width(),
                             textPos.height(), Qt.AlignCenter, self.text())
            # 重画图标
        if not self.icon().isNull():
            painter.drawPixmap(iconPos,
                               QPixmap(self.icon().pixmap(self.iconSize())))
Ejemplo n.º 16
0
def _get_pos_widget(name, backgroundColor, foregroundColor):
    label = QLabel()
    label.setAttribute(Qt.WA_TransparentForMouseEvents, True)

    pixmap = QPixmap(25*10, 25*10)
    pixmap.fill(backgroundColor)
    painter = QPainter()
    painter.begin(pixmap)
    pen = QPen(foregroundColor)
    painter.setPen(pen)
    painter.setRenderHint(QPainter.Antialiasing)
    font = QFont()
    font.setBold(True)
    font.setPixelSize(25*10-30)
    path = QPainterPath()
    path.addText(QPointF(50, 25*10-50), font, name)
    brush = QBrush(foregroundColor)
    painter.setBrush(brush)
    painter.drawPath(path)
    painter.setFont(font)
    painter.end()
    pixmap = pixmap.scaled(QSize(20,20),
                           Qt.KeepAspectRatio,
                           Qt.SmoothTransformation)
    label.setPixmap(pixmap)

    spinbox = QSpinBox()
    spinbox.setAttribute(Qt.WA_TransparentForMouseEvents, True)
    spinbox.setEnabled(False)
    spinbox.setAlignment(Qt.AlignCenter)
    spinbox.setToolTip("{0} Spin Box".format(name))
    spinbox.setButtonSymbols(QAbstractSpinBox.NoButtons)
    spinbox.setMaximumHeight(20)
    spinbox.setMaximum(9999)
    font = spinbox.font()
    font.setPixelSize(14)
    spinbox.setFont(font)
    sheet = TEMPLATE.format(foregroundColor.name(),
                            backgroundColor.name())
    spinbox.setStyleSheet(sheet)
    return label, spinbox
Ejemplo n.º 17
0
def _get_pos_widget(name, backgroundColor, foregroundColor):
    label = QLabel()
    label.setAttribute(Qt.WA_TransparentForMouseEvents, True)

    pixmap = QPixmap(25*10, 25*10)
    pixmap.fill(backgroundColor)
    painter = QPainter()
    painter.begin(pixmap)
    pen = QPen(foregroundColor)
    painter.setPen(pen)
    painter.setRenderHint(QPainter.Antialiasing)
    font = QFont()
    font.setBold(True)
    font.setPixelSize(25*10-30)
    path = QPainterPath()
    path.addText(QPointF(50, 25*10-50), font, name)
    brush = QBrush(foregroundColor)
    painter.setBrush(brush)
    painter.drawPath(path)
    painter.setFont(font)
    painter.end()
    pixmap = pixmap.scaled(QSize(20,20),
                           Qt.KeepAspectRatio,
                           Qt.SmoothTransformation)
    label.setPixmap(pixmap)

    spinbox = QSpinBox()
    spinbox.setAttribute(Qt.WA_TransparentForMouseEvents, True)
    spinbox.setEnabled(False)
    spinbox.setAlignment(Qt.AlignCenter)
    spinbox.setToolTip("{0} Spin Box".format(name))
    spinbox.setButtonSymbols(QAbstractSpinBox.NoButtons)
    spinbox.setMaximumHeight(20)
    spinbox.setMaximum(9999)
    font = spinbox.font()
    font.setPixelSize(14)
    spinbox.setFont(font)
    sheet = TEMPLATE.format(foregroundColor.name(),
                            backgroundColor.name())
    spinbox.setStyleSheet(sheet)
    return label, spinbox
Ejemplo n.º 18
0
 def paintEvent(self,event):
     painter = QPainter(self)
     if self.hasUnderLine:
         rect = self.tabRect(self.hoveredTab)
         linesPath = QPainterPath()
         linesPath.moveTo(QPoint(rect.x()+10,rect.height()-5))
         linesPath.lineTo(QPoint(rect.x()-10+rect.width(),rect.height()-5))
         linesPath.closeSubpath()
         painter.setPen(QPen(QColor(170,200,200),6))
         painter.drawPath(linesPath)
         # 如果不是当前选中的页,在页标签下画线
         if self.hoveredTab != self.currentIndex ():
             if self.isTabEnabled(self.hoveredTab):
                 rect = self.tabRect(self.hoveredTab)
                 linesPath = QPainterPath()
                 linesPath.moveTo(QPoint(rect.x()+10,rect.height()-5))
                 linesPath.lineTo(QPoint(rect.x()-10+rect.width(),rect.height()-5))
                 linesPath.closeSubpath()
                 painter.setPen(QPen(QColor(170,200,200),6))
                 painter.drawPath(linesPath)
     QTabBar.paintEvent(self,event)
Ejemplo n.º 19
0
    def mouseMoveEvent(self, event):
        drag = QDrag(event.widget())
        data = QMimeData()
        data.setText(self.commit.name())

        drag.setMimeData(data)

        #data.setColorData(GREEN)
        pixmap = QPixmap(COMMIT_WIDTH, COMMIT_HEIGHT)
        pixmap.fill(WHITE)
        painter = QPainter(pixmap)
        painter.translate(0, 0)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setPen(Qt.NoPen)
        painter.setBrush(QBrush(self.color))
        painter.drawPath(self.setup_display(0, 0))
        painter.end()

        pixmap.setMask(pixmap.createHeuristicMask())
        drag.setPixmap(pixmap)
        drag.setHotSpot(QPoint(0, 0))
        drag.start()
Ejemplo n.º 20
0
 def paintEvent(self,event):
     painter = QPainter(self)
     btnRect = self.geometry()
     
     color = QColor(Qt.black)
     if self.hovered:
         color = self.color
     if self.pressed:
         color = self.color.darker(120)
         
     painter.setBrush(QBrush(color)) 
     painter_path = QPainterPath()
     painter_path.addRoundedRect(1, 1, btnRect.width() - 2, btnRect.height() - 2, 0, 0)
     
     if self.hovered:
         painter.setPen(QPen(color,2))
         outline = QPainterPath()
         outline.addRoundedRect(0, 0, btnRect.width(), btnRect.height(), 0, 0)
         painter.setOpacity(1)
         painter.drawPath(outline)
         painter.setClipPath(painter_path)
         painter.drawRoundedRect(1, 1, btnRect.width() - 2, btnRect.height() - 2, 0, 0)
     
     iconWidth = self.iconSize().width()*3/5
     iconHeight = self.iconSize().height()*3/5
     iconX = (btnRect.width()-iconWidth)/2
     iconY = (btnRect.height()-iconHeight)/2
     
     if self.pressed:
         iconX += 2
         iconY += 2
     
     iconPos = QRect()
     iconPos.setX(iconX)
     iconPos.setY(iconY)
     iconPos.setWidth(iconWidth)
     iconPos.setHeight(iconHeight)
     
     painter.drawPixmap(iconPos, QPixmap(self.icon().pixmap(self.iconSize())))
Ejemplo n.º 21
0
 def _paint_bg(self, p: QPainter):
     dpi = Info.dpi
     pen = self.pen()
     p.setRenderHint(QPainter.Antialiasing, True)
     p.setPen(pen)
     p.setBrush(self.bg())
     p.drawRoundedRect(OIBlock.padding * dpi, OIBlock.padding * dpi, self.width() - 2 * OIBlock.padding * dpi,
                       self.height() - 2 * OIBlock.padding * dpi, OIBlock.radius * dpi, OIBlock.radius * dpi)
     p.setBrush(self.title_bg())
     p.drawRoundedRect(OIBlock.padding * dpi, OIBlock.padding * dpi, self.width() - 2 * OIBlock.padding * dpi,
                       .35 * dpi + OIBlock.padding * dpi, OIBlock.radius * dpi,
                       OIBlock.radius * dpi)
     p.setBrush(self.bg())
     p.setPen(QColor(0, 0, 0, 0))
     p.drawRect(0.01 * dpi + OIBlock.padding * dpi, 0.35 * dpi + OIBlock.padding * dpi,
                self.width() - 0.02 * dpi - 2 * OIBlock.padding * dpi, 0.10 * dpi)
     p.setPen(pen)
     if self._resizable:
         if self.__corner_path is None:
             self.__init_corner()
         p.setBrush(pen.brush())
         p.drawPath(self.__corner_path.translated(self.width(), self.height()))
Ejemplo n.º 22
0
 def adjustMask(self):
     """
     Updates the alpha mask for this popup widget.
     """
     if self.currentMode() == XPopupWidget.Mode.Dialog:
         self.clearMask()
         return
     
     path = self.borderPath()
     bitmap = QBitmap(self.width(), self.height())
     bitmap.fill(QColor('white'))
     
     painter = QPainter()
     painter.begin(bitmap)
     painter.setRenderHint(QPainter.Antialiasing)
     pen = QPen(QColor('black'))
     pen.setWidthF(0.75)
     painter.setPen(pen)
     painter.setBrush(QColor('black'))
     painter.drawPath(path)
     painter.end()
     
     self.setMask(bitmap)
Ejemplo n.º 23
0
    def adjustMask(self):
        """
        Updates the alpha mask for this popup widget.
        """
        if self.currentMode() == XPopupWidget.Mode.Dialog:
            self.clearMask()
            return

        path = self.borderPath()
        bitmap = QBitmap(self.width(), self.height())
        bitmap.fill(QColor('white'))

        painter = QPainter()
        painter.begin(bitmap)
        painter.setRenderHint(QPainter.Antialiasing)
        pen = QPen(QColor('black'))
        pen.setWidthF(0.75)
        painter.setPen(pen)
        painter.setBrush(QColor('black'))
        painter.drawPath(path)
        painter.end()

        self.setMask(bitmap)
Ejemplo n.º 24
0
 def paintEvent(self,event):
     return
     painter = QPainter(self)
     btnRect = self.geometry()
     iconRect = self.iconSize()
     
     color = QColor(Qt.black)
     if self.hovered:
         color = self.color
     if self.pressed:
         color = self.color.darker(120)
     
     painter.setPen(QPen(QColor(Qt.lightGray),2))
     outline = QPainterPath()
     outline.addRoundedRect(0, 0, btnRect.width(), btnRect.height(), 0, 0)
     painter.setOpacity(1)
     painter.drawPath(outline)
    
     painter.setBrush(QBrush(color)) 
     painter.setOpacity(self.opacity)
     painter_path = QPainterPath()
     painter_path.addRoundedRect(1, 1, btnRect.width() - 2, btnRect.height() - 2, 0, 0)
     if self.hovered:
         painter.setClipPath(painter_path)
         painter.drawRoundedRect(1, 1, btnRect.width() - 2, btnRect.height() - 2, 0, 0)
     
     painter.setOpacity(1)       
     
     iconPos,textPos = self.calIconTextPos(btnRect, iconRect)
     # 重画文本
     if not self.text().isNull():
         painter.setFont(self.font())
         painter.setPen(QPen(QColor(Qt.black),2))
         painter.drawText(textPos.x(), textPos.y(), textPos.width(), textPos.height(), Qt.AlignCenter, self.text())
         # 重画图标
     if not self.icon().isNull():
         painter.drawPixmap(iconPos, QPixmap(self.icon().pixmap(self.iconSize())))
Ejemplo n.º 25
0
    def paintEvent(self, event):
        if self._isRunning:
            anglestep = 360. / self._steps
            fillsteps = self._fillsteps
            factor = min(self.width(), self.height()) / 16.
            bw = self._bw

            p = QPainter(self)
            p.setRenderHint(QPainter.Antialiasing, True)
            p.scale(factor, factor)
            p.setPen(Qt.NoPen)

            for i in range(self._steps):
                x1, y1 = self._coords[i]
                c = fillsteps[self._steps - 1 - i]
                a = anglestep * i
                p.setBrush(QBrush(QColor.fromRgbF(bw, bw, bw, c)))
                p.save()
                p.translate(x1 - 2, y1 - 1)
                p.translate(2, 1)
                p.rotate(a)
                p.translate(-2, -1)
                p.drawPath(self._path)
                p.restore()
Ejemplo n.º 26
0
    def paintEvent(self, event):
        if self._isRunning:
            anglestep = 360. / self._steps
            fillsteps = self._fillsteps
            factor = min(self.width(), self.height()) / 16.
            bw = self._bw

            p = QPainter(self)
            p.setRenderHint(QPainter.Antialiasing, True)
            p.scale(factor, factor)
            p.setPen(Qt.NoPen)

            for i in range(self._steps):
                x1, y1 = self._coords[i]
                c = fillsteps[self._steps - 1 - i]
                a = anglestep * i
                p.setBrush(QBrush(QColor.fromRgbF(bw, bw, bw, c)))
                p.save()
                p.translate(x1 - 2, y1 - 1)
                p.translate(2, 1)
                p.rotate(a)
                p.translate(-2, -1)
                p.drawPath(self._path)
                p.restore()
Ejemplo n.º 27
0
    def paintEvent(self, pe):
        p = QPainter(self)
        p.setRenderHint(QPainter.Antialiasing)

        # p.setBrush(QColor(0xf0, 0xf0, 0xf0)) # color of the border
        # p.drawRect(-1, -1, 800, 800)

        pen = QPen()
        pen.setWidth(1)
        pen.setColor(QColor(0x58, 0x58,
                            0x58))  # color of the borders of the keys
        p.setPen(pen)

        p.setBrush(QColor(0x58, 0x58, 0x58))  # color of the keys

        p.setBackgroundMode(Qt.TransparentMode)

        rx = 3

        space = self.space
        w = self.usable_width
        kw = self.key_w

        def drawRow(row, sx, sy, last_end=False):
            x = sx
            y = sy
            keys = row
            rw = w - sx
            i = 0
            for k in keys:
                rect = QRectF(x, y, kw, kw)

                if i == len(keys) - 1 and last_end:
                    rect.setWidth(rw)

                p.drawRoundedRect(rect, rx, rx)

                rect.adjust(5, 1, 0, 0)

                p.setPen(QColor(0xff, 0xff, 0xff))
                p.setFont(self.lowerFont)
                p.drawText(rect, Qt.AlignLeft | Qt.AlignBottom,
                           self.regular_text(k))

                p.setPen(QColor(0x9e, 0xde, 0x00))
                p.setFont(self.upperFont)
                p.drawText(rect, Qt.AlignLeft | Qt.AlignTop,
                           self.shift_text(k))

                rw = rw - space - kw
                x = x + space + kw
                i = i + 1

                p.setPen(pen)
            return (x, rw)

        x = 6
        y = 6

        keys = self.kb["keys"]
        ext_return = self.kb["extended_return"]

        first_key_w = 0

        rows = 4
        remaining_x = [0, 0, 0, 0]
        remaining_widths = [0, 0, 0, 0]

        for i in range(0, rows):
            if first_key_w > 0:
                first_key_w = first_key_w * 1.375

                if self.kb == self.kb_105 and i == 3:
                    first_key_w = kw * 1.275

                rect = QRectF(6, y, first_key_w, kw)
                p.drawRoundedRect(rect, rx, rx)
                x = 6 + first_key_w + space
            else:
                first_key_w = kw

            x, rw = drawRow(keys[i], x, y, i == 1 and not ext_return)

            remaining_x[i] = x
            remaining_widths[i] = rw

            if i != 1 and i != 2:
                rect = QRectF(x, y, rw, kw)
                p.drawRoundedRect(rect, rx, rx)

            x = .5
            y = y + space + kw

        if ext_return:
            rx = rx * 2
            x1 = remaining_x[1]
            y1 = 6 + kw * 1 + space * 1
            w1 = remaining_widths[1]
            x2 = remaining_x[2]
            y2 = 6 + kw * 2 + space * 2

            # this is some serious crap... but it has to be so
            # maybe one day keyboards won't look like this...
            # one can only hope
            pp = QPainterPath()
            pp.moveTo(x1, y1 + rx)
            pp.arcTo(x1, y1, rx, rx, 180, -90)
            pp.lineTo(x1 + w1 - rx, y1)
            pp.arcTo(x1 + w1 - rx, y1, rx, rx, 90, -90)
            pp.lineTo(x1 + w1, y2 + kw - rx)
            pp.arcTo(x1 + w1 - rx, y2 + kw - rx, rx, rx, 0, -90)
            pp.lineTo(x2 + rx, y2 + kw)
            pp.arcTo(x2, y2 + kw - rx, rx, rx, -90, -90)
            pp.lineTo(x2, y1 + kw)
            pp.lineTo(x1 + rx, y1 + kw)
            pp.arcTo(x1, y1 + kw - rx, rx, rx, -90, -90)
            pp.closeSubpath()

            p.drawPath(pp)
        else:
            x = remaining_x[2]
            y = .5 + kw * 2 + space * 2
            rect = QRectF(x, y, remaining_widths[2], kw)
            p.drawRoundedRect(rect, rx, rx)

        QWidget.paintEvent(self, pe)
Ejemplo n.º 28
0
 def createQuadViewStatusBar(self, xbackgroundColor, xforegroundColor, ybackgroundColor, yforegroundColor, zbackgroundColor, zforegroundColor, graybackgroundColor, grayforegroundColor):             
     
     self.xLabel = QLabel()
     self.xLabel.setAttribute(Qt.WA_TransparentForMouseEvents, True)
     self.addWidget(self.xLabel)
     pixmap = QPixmap(25*10, 25*10)
     pixmap.fill(xbackgroundColor)
     painter = QPainter()
     painter.begin(pixmap)
     pen = QPen(xforegroundColor)
     painter.setPen(pen)
     painter.setRenderHint(QPainter.Antialiasing)
     font = QFont()
     font.setBold(True)
     font.setPixelSize(25*10-30)
     path = QPainterPath()
     path.addText(QPointF(50, 25*10-50), font, "X")
     brush = QBrush(xforegroundColor)
     painter.setBrush(brush)
     painter.drawPath(path)        
     painter.setFont(font)
     painter.end()
     pixmap = pixmap.scaled(QSize(20,20),Qt.KeepAspectRatio, Qt.SmoothTransformation)
     self.xLabel.setPixmap(pixmap)
     self.xSpinBox = QSpinBox()
     self.xSpinBox.setAttribute(Qt.WA_TransparentForMouseEvents, True)
     self.xSpinBox.setEnabled(False)
     self.xSpinBox.setAlignment(Qt.AlignCenter)
     self.xSpinBox.setToolTip("xSpinBox")
     self.xSpinBox.setButtonSymbols(QAbstractSpinBox.NoButtons)
     self.xSpinBox.setMaximumHeight(20)
     self.xSpinBox.setMaximum(9999)
     font = self.xSpinBox.font()
     font.setPixelSize(14)
     self.xSpinBox.setFont(font)
     self.xSpinBox.setStyleSheet("QSpinBox { color: " + str(xforegroundColor.name()) + "; font: bold; background-color: " + str(xbackgroundColor.name()) + "; border:0;}")
     self.addWidget(self.xSpinBox)
     
     self.yLabel = QLabel()
     self.yLabel.setAttribute(Qt.WA_TransparentForMouseEvents, True)
     self.addWidget(self.yLabel)
     pixmap = QPixmap(25*10, 25*10)
     pixmap.fill(ybackgroundColor)
     painter = QPainter()
     painter.begin(pixmap)
     pen = QPen(yforegroundColor)
     painter.setPen(pen)
     painter.setRenderHint(QPainter.Antialiasing)
     font = QFont()
     font.setBold(True)
     font.setPixelSize(25*10-30)
     path = QPainterPath()
     path.addText(QPointF(50, 25*10-50), font, "Y")
     brush = QBrush(yforegroundColor)
     painter.setBrush(brush)
     painter.drawPath(path)        
     painter.setFont(font)
     painter.end()
     pixmap = pixmap.scaled(QSize(20,20),Qt.KeepAspectRatio, Qt.SmoothTransformation)
     self.yLabel.setPixmap(pixmap)
     self.ySpinBox = QSpinBox()
     self.ySpinBox.setAttribute(Qt.WA_TransparentForMouseEvents, True)
     self.ySpinBox.setEnabled(False)
     self.ySpinBox.setAlignment(Qt.AlignCenter)
     self.ySpinBox.setToolTip("ySpinBox")
     self.ySpinBox.setButtonSymbols(QAbstractSpinBox.NoButtons)
     self.ySpinBox.setMaximumHeight(20)
     self.ySpinBox.setMaximum(9999)
     font = self.ySpinBox.font()
     font.setPixelSize(14)
     self.ySpinBox.setFont(font)
     self.ySpinBox.setStyleSheet("QSpinBox { color: " + str(yforegroundColor.name()) + "; font: bold; background-color: " + str(ybackgroundColor.name()) + "; border:0;}")
     self.addWidget(self.ySpinBox)
     
     self.zLabel = QLabel()
     self.zLabel.setAttribute(Qt.WA_TransparentForMouseEvents, True)
     self.addWidget(self.zLabel)
     pixmap = QPixmap(25*10, 25*10)
     pixmap.fill(zbackgroundColor)
     painter = QPainter()
     painter.begin(pixmap)
     pen = QPen(zforegroundColor)
     painter.setPen(pen)
     painter.setRenderHint(QPainter.Antialiasing)
     font = QFont()
     font.setBold(True)
     font.setPixelSize(25*10-30)
     path = QPainterPath()
     path.addText(QPointF(50, 25*10-50), font, "Z")
     brush = QBrush(zforegroundColor)
     painter.setBrush(brush)
     painter.drawPath(path)        
     painter.setFont(font)
     painter.end()
     pixmap = pixmap.scaled(QSize(20,20),Qt.KeepAspectRatio, Qt.SmoothTransformation)
     self.zLabel.setPixmap(pixmap)
     self.zSpinBox = QSpinBox()
     self.zSpinBox.setAttribute(Qt.WA_TransparentForMouseEvents, True)
     self.zSpinBox.setEnabled(False)
     self.zSpinBox.setAlignment(Qt.AlignCenter)
     self.zSpinBox.setToolTip("zSpinBox")
     self.zSpinBox.setButtonSymbols(QAbstractSpinBox.NoButtons)
     self.zSpinBox.setMaximumHeight(20)
     self.zSpinBox.setMaximum(9999)
     font = self.zSpinBox.font()
     font.setPixelSize(14)
     self.zSpinBox.setFont(font)
     self.zSpinBox.setStyleSheet("QSpinBox { color: " + str(zforegroundColor.name()) + "; font: bold; background-color: " + str(zbackgroundColor.name()) + "; border:0;}")
     self.addWidget(self.zSpinBox)
     
     self.addSpacing(4)
     
     self.grayScaleLabel = QLabel()
     self.grayScaleLabel.setAttribute(Qt.WA_TransparentForMouseEvents, True)
     self.addWidget(self.grayScaleLabel)
     pixmap = QPixmap(610, 250)
     pixmap.fill(graybackgroundColor)
     painter = QPainter()
     painter.begin(pixmap)
     pen = QPen(grayforegroundColor)
     painter.setPen(pen)
     painter.setRenderHint(QPainter.Antialiasing)
     font = QFont()
     font.setBold(True)
     font.setPixelSize(25*10-30)
     path = QPainterPath()
     path.addText(QPointF(50, 25*10-50), font, "Gray")
     brush = QBrush(grayforegroundColor)
     painter.setBrush(brush)
     painter.drawPath(path)        
     painter.setFont(font)
     painter.end()
     pixmap = pixmap.scaled(QSize(61,20),Qt.KeepAspectRatio, Qt.SmoothTransformation)
     
     """
     self.grayScaleLabel.setPixmap(pixmap)
     self.grayScaleSpinBox = QSpinBox()
     self.grayScaleSpinBox.setAttribute(Qt.WA_TransparentForMouseEvents, True)
     self.grayScaleSpinBox.setEnabled(False)
     self.grayScaleSpinBox.setAlignment(Qt.AlignCenter)
     self.grayScaleSpinBox.setToolTip("grayscaleSpinBox")
     self.grayScaleSpinBox.setButtonSymbols(QAbstractSpinBox.NoButtons)
     self.grayScaleSpinBox.setMaximum(255)
     self.grayScaleSpinBox.setMaximumHeight(20)
     self.grayScaleSpinBox.setMaximum(255)
     font = self.grayScaleSpinBox.font()
     font.setPixelSize(14)
     self.grayScaleSpinBox.setFont(font)
     self.grayScaleSpinBox.setStyleSheet("QSpinBox { color: " + str(grayforegroundColor.name()) + "; font: bold; background-color: " + str(graybackgroundColor.name()) + "; border:0;}")
     self.addWidget(self.grayScaleSpinBox)
     """
     
     self.addStretch()
     
     self.positionCheckBox = QCheckBox()
     self.positionCheckBox.setChecked(True)
     self.positionCheckBox.setCheckable(True)
     self.positionCheckBox.setText("Position")
     self.addWidget(self.positionCheckBox)
     
     self.addSpacing(20)
     
     self.channelLabel = QLabel("Channel:")
     self.addWidget(self.channelLabel)
     
     self.channelSpinBox = QSpinBox()
     self.addWidget(self.channelSpinBox)
     self.addSpacing(20)
     
     self.timeLabel = QLabel("Time:")
     self.addWidget(self.timeLabel)
     
     self.timeSpinBox = QSpinBox()
     self.addWidget(self.timeSpinBox)
Ejemplo n.º 29
0
    def paintEvent(self, pe):
        p = QPainter(self)
        p.setRenderHint(QPainter.Antialiasing)

        pen = QPen()
        pen.setWidth(1)
        pen.setColor(QColor(0x8C, 0xA3, 0xB0))
        p.setPen(pen)

        p.setBrush(QColor(0xE4, 0xEC, 0xF4))

        rx = 6

        space = self.space
        w = self.usable_width
        kw = self.key_w

        def drawRow(row, sx, sy, last_end=False):
            x = sx
            y = sy
            keys = row
            rw = w - sx
            i = 0
            for k in keys:
                rect = QRectF(x, y, kw, kw)

                if i == len(keys) - 1 and last_end:
                    rect.setWidth(rw)

                p.drawRoundedRect(rect, rx, rx)
                p.setPen(Qt.black)

                rect.adjust(5, 1, 0, 0)

                p.setFont(self.lowerFont)
                p.drawText(rect, Qt.AlignLeft | Qt.AlignBottom, self.regular_text(k))

                p.setFont(self.upperFont)
                p.drawText(rect, Qt.AlignLeft | Qt.AlignTop, self.shift_text(k))

                rw = rw - space - kw
                x = x + space + kw
                i = i + 1

                p.setPen(pen)
            return (x, rw)

        x = 0.5
        y = 0.5

        keys = self.kb["keys"]
        ext_return = self.kb["extended_return"]

        first_key_w = 0

        rows = 4
        remaining_x = [0, 0, 0, 0]
        remaining_widths = [0, 0, 0, 0]

        for i in range(0, rows):
            if first_key_w > 0:
                first_key_w = first_key_w * 1.375

                if self.kb == self.kb_105 and i == 3:
                    first_key_w = kw * 1.275

                rect = QRectF(x, y, first_key_w, kw)
                p.drawRoundedRect(rect, rx, rx)
                x = x + first_key_w + space
            else:
                first_key_w = kw

            x, rw = drawRow(keys[i], x, y, i == 1 and not ext_return)

            remaining_x[i] = x
            remaining_widths[i] = rw

            if i != 1 and i != 2:
                rect = QRectF(x, y, rw, kw)
                p.drawRoundedRect(rect, rx, rx)

            x = 0.5
            y = y + space + kw

        if ext_return:
            rx = rx * 2
            x1 = remaining_x[1]
            y1 = 0.5 + kw * 1 + space * 1
            w1 = remaining_widths[1]
            x2 = remaining_x[2]
            y2 = 0.5 + kw * 2 + space * 2
            w2 = remaining_widths[2]

            # this is some serious crap... but it has to be so
            # maybe one day keyboards won't look like this...
            # one can only hope
            pp = QPainterPath()
            pp.moveTo(x1, y1 + rx)
            pp.arcTo(x1, y1, rx, rx, 180, -90)
            pp.lineTo(x1 + w1 - rx, y1)
            pp.arcTo(x1 + w1 - rx, y1, rx, rx, 90, -90)
            pp.lineTo(x1 + w1, y2 + kw - rx)
            pp.arcTo(x1 + w1 - rx, y2 + kw - rx, rx, rx, 0, -90)
            pp.lineTo(x2 + rx, y2 + kw)
            pp.arcTo(x2, y2 + kw - rx, rx, rx, -90, -90)
            pp.lineTo(x2, y1 + kw)
            pp.lineTo(x1 + rx, y1 + kw)
            pp.arcTo(x1, y1 + kw - rx, rx, rx, -90, -90)
            pp.closeSubpath()

            p.drawPath(pp)
        else:
            x = remaining_x[2]
            y = 0.5 + kw * 2 + space * 2
            rect = QRectF(x, y, remaining_widths[2], kw)
            p.drawRoundedRect(rect, rx, rx)

        QWidget.paintEvent(self, pe)
Ejemplo n.º 30
0
    def paintEvent(self, event):
        # Initialize QPainter properties
        painter = QPainter()
        painter.begin(self)
        painter.setRenderHint(QPainter.Antialiasing)
        if self.height() <= self.width() / self.ref_aspect_ratio:
            v_scale = self.height()
            h_scale = v_scale * self.ref_aspect_ratio
        else:
            h_scale = self.width()
            v_scale = h_scale / self.ref_aspect_ratio
        # Scale all objects proportionate to window size
        painter.scale(h_scale / self.width_ref, v_scale / self.height_ref)
        painter.setClipPath(self.dial)  # Don't allow objects or text to extend outside of main dial shape
        painter.save()

        # First draw main gauge background
        pen = QPen(painter.pen())
        pen.setWidth(1)
        pen.setColor(Qt.black)
        painter.setPen(pen)
        painter.setBrush(QColor(100, 100, 100, 255))  # self.dial_bg)
        painter.drawPath(self.dial)

        # Add Minor and Major Alarm limit bars
        pen.setWidth(16)
        pen.setCapStyle(Qt.FlatCap)
        pen.setJoinStyle(Qt.BevelJoin)

        pen.setColor(Qt.yellow)
        painter.setPen(pen)
        painter.setBrush(Qt.NoBrush)
        painter.drawPath(self.low_arc)
        painter.drawPath(self.high_arc)

        pen.setColor(Qt.red)
        painter.setPen(pen)
        painter.drawPath(self.lolo_arc)
        painter.drawPath(self.hihi_arc)

        painter.restore()

        # Display PV current value
        painter.save()
        font = QFont()
        font.setPixelSize(45)
        painter.setFont(font)
        sevr = self.channel.sevr.lower()
        if sevr == 'major':
            color = Qt.red
        elif sevr == 'minor':
            color = Qt.yellow
        elif sevr == 'invalid':
            color = Qt.magenta
        else:
            color = Qt.green
        pen.setColor(color)
        painter.setPen(pen)
        font_metric = QFontMetrics(font)
        painter.translate(self.dial_width / 2, self.dial_height / 2)
        label = self.format_label(self.channel_value)
        painter.drawText(QPointF(0.0 - font_metric.width(label) / 2.0, font_metric.height() / 2.0),
                         label)

        # Display PV name
        painter.setFont(self.pv_label_font)
        pen.setColor(Qt.black)  # Qt.darkCyan)
        pen.setWidth(1)
        painter.setPen(pen)
        # brush = QBrush(Qt.darkCyan)
        # painter.setBrush(brush)
        font_metric = QFontMetrics(self.pv_label_font)
        pv_label = self.channel.egu  # self.channel.name + ' (' + self.channel.egu + ')'
        painter.drawText(QPointF(0.0 - font_metric.width(pv_label) / 2.0,
                                 (self.dial_height / 2.0) + (font_metric.height() * 1.5)),
                         pv_label)
        # painter.drawPath(self.pv_label_path)
        painter.restore()

        # Next add division markers
        painter.save()
        painter.translate(self.dial_width / 2, self.dial_height * 0.98)
        pen.setColor(Qt.black)  # Qt.cyan)
        pen.setWidth(2)
        painter.setPen(pen)
        for i in range(0, 31):
            if (i % 5) != 0:
                painter.drawLine(-self.dial_width / 2.1, 0.0, -self.dial_width / 2.2, 0.0)
            else:
                painter.drawLine(-self.dial_width / 2.1, 0.0, -self.dial_width / 2.3, 0.0)
            painter.rotate(6.0)
        painter.restore()

        # Layout division text labels
        painter.save()
        painter.translate(self.dial_width / 2, self.dial_height * 0.98)
        pen.setColor(Qt.black)  # Qt.cyan)
        painter.setPen(pen)
        font = QFont()
        font.setPixelSize(18)
        painter.setFont(font)
        font_metric = QFontMetrics(font)
        labels = linspace(self.lim_low, self.lim_hi, 7)
        painter.rotate(-90)
        for i in range(0, 7):
            label = self.format_label(labels[i])
            painter.drawText(QPointF(0.0 - font_metric.width(label) / 2.0, -self.dial_height * 0.75), label)
            painter.rotate(30)
        painter.restore()

        # Draw needle at appropriate angle for data
        painter.save()
        painter.translate(self.dial_width / 2, self.dial_height * 0.98)
        painter.rotate(-180 * (1.0 - self.percentage))

        pen.setColor(QColor(self.needle_color).darker(200))
        pen.setWidth(1)
        painter.setPen(pen)
        painter.setBrush(self.needle_color)
        painter.drawPolygon(self.needle)
        painter.restore()

        # if self.percentage <= 0.5:
        #     shadow = max(490 * self.percentage, 127)
        #     needle_left_color = QColor(0, shadow, shadow)  # Qt.darkCyan  # QColor(80,80,80,255)
        #     needle_right_color = Qt.cyan  # QColor(230,230,230,255)
        # else:
        #     shadow = max(125 / self.percentage, 127)
        #     needle_left_color = Qt.cyan  # QColor(230,230,230,255)
        #     needle_right_color = QColor(0, shadow, shadow)  # Qt.darkCyan  # QColor(80,80,80,255)
        #
        # # Draw Highlight side of needle
        # pen.setWidth(1)
        # pen.setColor(Qt.gray)  # needle_left_color)
        # painter.setPen(pen)
        # painter.setBrush(Qt.gray)  # needle_left_color)
        # painter.drawPolygon(self.needle_left)
        #
        # # Draw shadow side of needle
        # pen.setColor(Qt.gray)  # needle_right_color)
        # painter.setPen(pen)
        # painter.setBrush(Qt.gray)  # needle_right_color)
        # painter.drawPolygon(self.needle_right)
        # painter.restore()

        # Draw needle axel pin
        painter.save()
        pen.setWidth(1)
        pen.setColor(Qt.black)
        painter.setPen(pen)
        painter.setBrush(QColor(50, 50, 50, 255))  # self.pin_bg)
        painter.translate(self.dial_width / 2, self.dial_height * 0.98)
        painter.drawEllipse(self.pin_rect)
        painter.restore()

        # Draw glass reflection and shadow effects
        # painter.save()
        # painter.translate(self.dial_width / 2.0, self.dial_height / 2.0)
        # painter.setPen(Qt.NoPen)
        # painter.setBrush(QColor(0, 0, 0, 20))
        # painter.drawEllipse(self.shadow_rect)
        # painter.setBrush(self.gloss_gradient)
        # painter.drawEllipse(self.gloss_rect)
        # painter.restore()

        painter.end()
Ejemplo n.º 31
0
    def paintEvent(self, event):
        painter = QPainter(self)
        width = self.width()
        height = self.height()

        if self.scales_visible:
            curve_width = width - self.y_scale.total_width - self.curve_to_scale - self.curve_outer_border
            curve_height = height - self.y_scale_height_offset - self.x_scale.total_height - self.curve_to_scale
        else:
            curve_width = width - self.curve_outer_border - self.curve_outer_border
            curve_height = height - self.curve_outer_border - self.curve_outer_border

        if DEBUG:
            painter.fillRect(0, 0, width, height, Qt.green)

        # fill canvas
        if self.scales_visible:
            canvas_x = self.y_scale.total_width + self.curve_to_scale - self.curve_outer_border
            canvas_y = self.y_scale_height_offset - self.curve_outer_border
        else:
            canvas_x = 0
            canvas_y = 0

        canvas_width = self.curve_outer_border + curve_width + self.curve_outer_border
        canvas_height = self.curve_outer_border + curve_height + self.curve_outer_border

        painter.fillRect(canvas_x, canvas_y, canvas_width, canvas_height,
                         self.canvas_color)

        # draw cross hair at cursor position
        if self.cross_hair_visible:
            p = self.mapFromGlobal(QCursor.pos())
            p_x = p.x()
            p_y = p.y()

            if p_x >= canvas_x and p_x < canvas_x + canvas_width and \
               p_y >= canvas_y and p_y < canvas_y + canvas_height:
                painter.setPen(QPen(QColor(190, 190, 190), 1, Qt.DashLine))
                painter.drawLine(canvas_x, p_y, canvas_x + canvas_width - 1,
                                 p_y)
                painter.drawLine(p_x, canvas_y, p_x,
                                 canvas_y + canvas_height - 1)

        # draw canvas border
        if self.curve_outer_border > 0:
            painter.setPen(QColor(190, 190, 190))
            painter.drawRect(
                canvas_x, canvas_y, canvas_width - 1, canvas_height -
                1)  # -1 to accommodate the 1px width of the border
            painter.setPen(Qt.black)

        if DEBUG:
            painter.fillRect(canvas_x + self.curve_outer_border,
                             canvas_y + self.curve_outer_border, curve_width,
                             curve_height, Qt.cyan)

        # draw scales
        y_min_scale = self.y_scale.value_min
        y_max_scale = self.y_scale.value_max

        factor_x = float(curve_width) / self.history_length_x
        factor_y = float(curve_height - 1) / max(
            y_max_scale - y_min_scale,
            EPSILON)  # -1 to accommodate the 1px width of the curve

        if self.scales_visible:
            self.draw_x_scale(painter, factor_x)
            self.draw_y_scale(painter, curve_height, factor_y)

        # draw curves
        if self.x_min != None and self.x_max != None:
            x_min = self.x_min
            x_max = self.x_max

            if self.scales_visible:
                curve_x_offset = 0
            else:
                curve_x_offset = round(
                    (self.history_length_x - (x_max - x_min)) * factor_x)

            painter.save()
            painter.translate(
                canvas_x + self.curve_outer_border + curve_x_offset,
                canvas_y + self.curve_outer_border + curve_height - 1 +
                self.curve_y_offset
            )  # -1 to accommodate the 1px width of the curve
            painter.scale(factor_x, -factor_y)
            painter.translate(-x_min, -y_min_scale)

            for c in range(len(self.curves_x)):
                if not self.curves_visible[c]:
                    continue

                curve_x = self.curves_x[c]
                curve_y = self.curves_y[c]
                path = QPainterPath()
                lineTo = path.lineTo

                path.moveTo(curve_x[0], curve_y[0])

                for i in xrange(1, len(curve_x)):
                    lineTo(curve_x[i], curve_y[i])

                painter.setPen(self.plots[c][1])
                painter.drawPath(path)

            painter.restore()
Ejemplo n.º 32
0
    def paintEvent(self, event):
        painter = QPainter(self)
        width = self.width()
        height = self.height()

        if self.scales_visible:
            curve_width = width - self.y_scale.total_width - self.curve_to_scale - self.curve_outer_border
            curve_height = height - self.y_scale_height_offset - self.x_scale.total_height - self.curve_to_scale
        else:
            curve_width = width - self.curve_outer_border - self.curve_outer_border
            curve_height = height - self.curve_outer_border - self.curve_outer_border

        if DEBUG:
            painter.fillRect(0, 0, width, height, Qt.green)

        # fill canvas
        if self.scales_visible:
            canvas_x = self.y_scale.total_width + self.curve_to_scale - self.curve_outer_border
            canvas_y = self.y_scale_height_offset - self.curve_outer_border
        else:
            canvas_x = 0
            canvas_y = 0

        canvas_width = self.curve_outer_border + curve_width + self.curve_outer_border
        canvas_height = self.curve_outer_border + curve_height + self.curve_outer_border

        painter.fillRect(canvas_x, canvas_y, canvas_width, canvas_height, self.canvas_color)

        # draw cross hair at cursor position
        if self.cross_hair_visible:
            p = self.mapFromGlobal(QCursor.pos())
            p_x = p.x()
            p_y = p.y()

            if p_x >= canvas_x and p_x < canvas_x + canvas_width and \
               p_y >= canvas_y and p_y < canvas_y + canvas_height:
                painter.setPen(QPen(QColor(190, 190, 190), 1, Qt.DashLine))
                painter.drawLine(canvas_x, p_y, canvas_x + canvas_width - 1, p_y)
                painter.drawLine(p_x, canvas_y, p_x, canvas_y + canvas_height - 1)

        # draw canvas border
        if self.curve_outer_border > 0:
            painter.setPen(QColor(190, 190, 190))
            painter.drawRect(canvas_x, canvas_y, canvas_width - 1, canvas_height - 1) # -1 to accommodate the 1px width of the border
            painter.setPen(Qt.black)

        if DEBUG:
            painter.fillRect(canvas_x + self.curve_outer_border,
                             canvas_y + self.curve_outer_border,
                             curve_width,
                             curve_height,
                             Qt.cyan)

        # draw scales
        y_min_scale = self.y_scale.value_min
        y_max_scale = self.y_scale.value_max

        factor_x = float(curve_width) / self.history_length_x
        factor_y = float(curve_height - 1) / max(y_max_scale - y_min_scale, EPSILON) # -1 to accommodate the 1px width of the curve

        if self.scales_visible:
            self.draw_x_scale(painter, factor_x)
            self.draw_y_scale(painter, curve_height, factor_y)

        # draw curves
        if self.x_min != None and self.x_max != None:
            x_min = self.x_min
            x_max = self.x_max

            if self.scales_visible:
                curve_x_offset = 0
            else:
                curve_x_offset = round((self.history_length_x - (x_max - x_min)) * factor_x)

            painter.save()
            painter.translate(canvas_x + self.curve_outer_border + curve_x_offset,
                              canvas_y + self.curve_outer_border + curve_height - 1 + self.curve_y_offset) # -1 to accommodate the 1px width of the curve
            painter.scale(factor_x, -factor_y)
            painter.translate(-x_min, -y_min_scale)

            for c in range(len(self.curves_x)):
                if not self.curves_visible[c]:
                    continue

                curve_x = self.curves_x[c]
                curve_y = self.curves_y[c]
                path = QPainterPath()
                lineTo = path.lineTo

                path.moveTo(curve_x[0], curve_y[0])

                for i in xrange(1, len(curve_x)):
                    lineTo(curve_x[i], curve_y[i])

                painter.setPen(self.plots[c][1])
                painter.drawPath(path)

            painter.restore()
def gen_font(font_configs,
             font_type=FONT_TYPES.font01,
             img_width=1024,
             draw_outlines=False):
    img_height = HEIGHT_FACTOR

    seen_chars = []

    game_font = GameFont(width=img_width)
    painter = QPainter(game_font.trans)

    text_brush = QtGui.QBrush(QColor(255, 255, 255, 255))
    painter.setBrush(text_brush)

    outline_brush = QtGui.QBrush()
    outline_pen = QtGui.QPen(QColor(255, 0, 0, 255),
                             1,
                             style=Qt.Qt.DotLine,
                             join=Qt.Qt.MiterJoin)

    x_pos = 0
    y_pos = 0

    line_height = LINE_HEIGHT[font_type]

    for config in font_configs:
        font = QFont(config.family, config.size, config.weight, italic=False)
        font.setKerning(False)
        metric = QFontMetrics(font)

        painter.setFont(font)
        painter.setRenderHint(QPainter.TextAntialiasing, True)
        painter.setRenderHint(QPainter.Antialiasing, True)

        text_pen = painter.pen()
        text_pen.setBrush(QColor(255, 255, 255, 255))
        text_pen.setWidthF(config.pen_size)
        text_pen.setCapStyle(config.pen_cap)
        text_pen.setJoinStyle(config.pen_join)
        text_pen.setStyle(Qt.Qt.SolidLine if config.use_pen else Qt.Qt.NoPen)
        painter.setPen(text_pen)

        for char in sorted(config.chars):

            if char in seen_chars:
                continue
            else:
                seen_chars.append(char)

            # If we want a character to represent something it's not.
            char_to_print = char

            if char in config.subs:
                char_to_print = config.subs[char]

            char_w = metric.width(char_to_print)

            if x_pos + char_w > img_width:
                x_pos = 0
                y_pos += line_height + config.y_margin

            if y_pos < 0:
                y_pos = 0

            if y_pos + line_height > MAX_HEIGHT:
                _LOGGER.warning(
                    "Ran out of vertical space. Generated font does not include all characters."
                )
                break

            game_font.font_data.data.append({
                'char': char,
                'x': x_pos,
                'y': y_pos,
                'w': char_w,
                'h': line_height,
                'y_shift': config.y_shift
            })

            path = QPainterPath()
            path.addText(x_pos + config.x_offset,
                         y_pos + metric.ascent() + config.y_offset, font,
                         char_to_print)
            painter.drawPath(path)

            if draw_outlines:
                painter.setBrush(outline_brush)
                painter.setPen(outline_pen)
                painter.setRenderHint(QPainter.Antialiasing, False)

                painter.drawRect(x_pos, y_pos, char_w, line_height)

                painter.setRenderHint(QPainter.Antialiasing, True)
                painter.setBrush(text_brush)
                painter.setPen(text_pen)

            x_pos += char_w + config.x_margin

    painter.end()

    painter = QPainter(game_font.opaque)
    painter.drawImage(game_font.opaque.rect(), game_font.trans,
                      game_font.trans.rect())
    painter.end()

    # Crop our images so they only take up as much space as they need.
    final_height = int(
        math.ceil(float(y_pos + line_height) / float(HEIGHT_FACTOR)) *
        HEIGHT_FACTOR)
    game_font.trans = game_font.trans.copy(0, 0, img_width, final_height)
    game_font.opaque = game_font.opaque.copy(0, 0, img_width, final_height)

    return game_font


# if __name__ == '__main__':

# app = QtGui.QApplication(sys.argv)

# chars = load_text(CHAR_LIST)
# We can't have dupes, and why not put them in order while we're at it?
# chars = sorted(make_unique(chars))

# game_font = gen_font(chars)
# game_font.save(SAVE_AS)

### EOF ###
def gen_font(font_configs, font_type = FONT_TYPES.font01, img_width = 1024, draw_outlines = False):
  img_height = HEIGHT_FACTOR
  
  seen_chars = []
  
  game_font = GameFont(width = img_width)
  painter = QPainter(game_font.trans)
  
  text_brush = QtGui.QBrush(QColor(255, 255, 255, 255))
  painter.setBrush(text_brush)
  
  outline_brush = QtGui.QBrush()
  outline_pen   = QtGui.QPen(QColor(255, 0, 0, 255), 1, style = Qt.Qt.DotLine, join = Qt.Qt.MiterJoin)
  
  x_pos = 0
  y_pos = 0
  
  line_height = LINE_HEIGHT[font_type]
  
  for config in font_configs:
    font = QFont(config.family, config.size, config.weight, italic = False)
    font.setKerning(False)
    metric = QFontMetrics(font)
    
    painter.setFont(font)
    painter.setRenderHint(QPainter.TextAntialiasing, True)
    painter.setRenderHint(QPainter.Antialiasing, True)
    
    text_pen = painter.pen()
    text_pen.setBrush(QColor(255, 255, 255, 255))
    text_pen.setWidthF(config.pen_size)
    text_pen.setCapStyle(config.pen_cap)
    text_pen.setJoinStyle(config.pen_join)
    text_pen.setStyle(Qt.Qt.SolidLine if config.use_pen else Qt.Qt.NoPen)
    painter.setPen(text_pen)
    
    for char in sorted(config.chars):
      
      if char in seen_chars:
        continue
      else:
        seen_chars.append(char)
      
      # If we want a character to represent something it's not.
      char_to_print = char
      
      if char in config.subs:
        char_to_print = config.subs[char]
      
      char_w = metric.width(char_to_print)
      
      if x_pos + char_w > img_width:
        x_pos = 0
        y_pos += line_height + config.y_margin
      
      if y_pos < 0:
        y_pos = 0
    
      if y_pos + line_height > MAX_HEIGHT:
        _LOGGER.warning("Ran out of vertical space. Generated font does not include all characters.")
        break
    
      game_font.font_data.data.append({'char': char, 'x': x_pos, 'y': y_pos, 'w': char_w, 'h': line_height, 'y_shift': config.y_shift})
      
      path = QPainterPath()
      path.addText(x_pos + config.x_offset, y_pos + metric.ascent() + config.y_offset, font, char_to_print)
      painter.drawPath(path)
      
      if draw_outlines:
        painter.setBrush(outline_brush)
        painter.setPen(outline_pen)
        painter.setRenderHint(QPainter.Antialiasing, False)
        
        painter.drawRect(x_pos, y_pos, char_w, line_height)
        
        painter.setRenderHint(QPainter.Antialiasing, True)
        painter.setBrush(text_brush)
        painter.setPen(text_pen)
      
      x_pos += char_w + config.x_margin
  
  painter.end()
  
  painter = QPainter(game_font.opaque)
  painter.drawImage(game_font.opaque.rect(), game_font.trans, game_font.trans.rect())
  painter.end()
  
  # Crop our images so they only take up as much space as they need.
  final_height = int(math.ceil(float(y_pos + line_height) / float(HEIGHT_FACTOR)) * HEIGHT_FACTOR)
  game_font.trans   = game_font.trans.copy(0, 0, img_width, final_height)
  game_font.opaque  = game_font.opaque.copy(0, 0, img_width, final_height)
  
  return game_font

# if __name__ == '__main__':
  
  # app = QtGui.QApplication(sys.argv)
  
  # chars = load_text(CHAR_LIST)
  # We can't have dupes, and why not put them in order while we're at it?
  # chars = sorted(make_unique(chars))
  
  # game_font = gen_font(chars)
  # game_font.save(SAVE_AS)

### EOF ###
Ejemplo n.º 35
0
    def paintEvent(self, event):
        painter = QPainter(self)
        width = self.width()
        height = self.height()

        if DEBUG:
            painter.fillRect(0, 0, width, height, Qt.blue)
        else:
            painter.fillRect(event.rect(), self.plot.canvas_color)

        y_min_scale = self.plot.y_scale.value_min
        y_max_scale = self.plot.y_scale.value_max

        factor_x = float(width) / self.plot.history_length_x
        factor_y = float(height - 1) / max(
            y_max_scale - y_min_scale, EPSILON
        )  # -1 to accommodate the 1px width of the curve

        if self.plot.x_min != None and self.plot.x_max != None:
            x_min = self.plot.x_min
            x_max = self.plot.x_max

            if self.plot.curve_start == "left":
                curve_x_offset = 0
            else:
                curve_x_offset = round((self.plot.history_length_x - (x_max - x_min)) * factor_x)

            transform = QTransform()

            transform.translate(
                curve_x_offset, height - 1 + self.plot.curve_y_offset
            )  # -1 to accommodate the 1px width of the curve
            transform.scale(factor_x, -factor_y)
            transform.translate(-x_min, -y_min_scale)

            if self.plot.curve_motion_granularity > 1:
                self.plot.partial_update_width = math.ceil(transform.map(QLineF(0, 0, 1.5, 0)).length())
                inverted_event_rect = transform.inverted()[0].mapRect(QRectF(event.rect()))

            painter.save()
            painter.setTransform(transform)

            for c in range(len(self.plot.curves_x)):
                if not self.plot.curves_visible[c]:
                    continue

                curve_x = self.plot.curves_x[c]
                curve_y = self.plot.curves_y[c]
                path = QPainterPath()
                lineTo = path.lineTo

                if self.plot.curve_motion_granularity > 1:
                    start = max(min(bisect.bisect_left(curve_x, inverted_event_rect.left()), len(curve_x) - 1) - 1, 0)
                else:
                    start = 0

                path.moveTo(curve_x[start], curve_y[start])

                for i in xrange(start + 1, len(curve_x)):
                    lineTo(curve_x[i], curve_y[i])

                painter.setPen(self.plot.configs[c][1])
                painter.drawPath(path)

            painter.restore()
Ejemplo n.º 36
0
    def paintEvent(self, event):
        painter = QPainter(self)
        width = self.width()
        height = self.height()

        if DEBUG:
            painter.fillRect(0, 0, width, height, Qt.blue)
        else:
            painter.fillRect(event.rect(), self.plot.canvas_color)

        y_min_scale = self.plot.y_scale.value_min
        y_max_scale = self.plot.y_scale.value_max

        factor_x = float(width) / self.plot.x_diff
        factor_y = float(height - 1) / max(
            y_max_scale - y_min_scale,
            EPSILON)  # -1 to accommodate the 1px width of the curve

        if self.plot.x_min != None and self.plot.x_max != None:
            x_min = self.plot.x_min
            x_max = self.plot.x_max

            if self.plot.curve_start == 'left':
                curve_x_offset = 0
            else:
                curve_x_offset = round(
                    (self.plot.x_diff - (x_max - x_min)) * factor_x)

            transform = QTransform()

            transform.translate(
                curve_x_offset, height - 1 + self.plot.curve_y_offset
            )  # -1 to accommodate the 1px width of the curve
            transform.scale(factor_x, -factor_y)
            transform.translate(-x_min, -y_min_scale)

            if self.plot.curve_motion_granularity > 1:
                self.plot.partial_update_width = math.ceil(
                    transform.map(QLineF(0, 0, 1.5, 0)).length())
                inverted_event_rect = transform.inverted()[0].mapRect(
                    QRectF(event.rect()))

            painter.save()
            painter.setTransform(transform)

            if False and self.plot.curves_visible[0]:
                # Currently unused support for bar graphs.
                # If we need this later on we should add an option to the
                # PlotWidget for it.
                # I tested this for the Sound Pressure Level Bricklet and it works,
                # but it didnt't look good.
                curve_x = self.plot.curves_x[0]
                curve_y = self.plot.curves_y[0]

                t = time.time()
                if self.max_points == None:
                    self.max_points = []
                    for y in curve_y:
                        self.max_points.append((t, y))
                else:
                    for i in range(len(curve_y)):
                        if (curve_y[i] > self.max_points[i][1]) or (
                            (t - self.max_points[i][0]) > 5):
                            self.max_points[i] = (t, curve_y[i])

                for i in range(len(self.plot.curves_x[0])):
                    painter.setPen(self.plot.curve_configs[0].color)
                    painter.drawLine(QPoint(curve_x[i], 0),
                                     QPoint(curve_x[i], curve_y[i]))
                    painter.setPen(Qt.white)
                    painter.drawLine(QPoint(curve_x[i], curve_y[i]),
                                     QPoint(curve_x[i], y_max_scale))
                    painter.setPen(Qt.darkGreen)
                    painter.drawPoint(QPoint(curve_x[i],
                                             self.max_points[i][1]))
            else:
                for c in range(len(self.plot.curves_x)):
                    if not self.plot.curves_visible[c]:
                        continue

                    curve_x = self.plot.curves_x[c]
                    curve_y = self.plot.curves_y[c]
                    path = QPainterPath()
                    lineTo = path.lineTo

                    if self.plot.curve_motion_granularity > 1:
                        start = max(
                            min(
                                bisect.bisect_left(curve_x,
                                                   inverted_event_rect.left()),
                                len(curve_x) - 1) - 1, 0)
                    else:
                        start = 0

                    path.moveTo(curve_x[start], curve_y[start])

                    for i in xrange(start + 1, len(curve_x)):
                        lineTo(curve_x[i], curve_y[i])

                    painter.setPen(self.plot.curve_configs[c].color)
                    painter.drawPath(path)

            painter.restore()