Ejemplo n.º 1
0
def drag_icon(self, cover, multiple):
    cover = cover.scaledToHeight(120, Qt.SmoothTransformation)
    if multiple:
        base_width = cover.width()
        base_height = cover.height()
        base = QImage(base_width + 21, base_height + 21,
                      QImage.Format_ARGB32_Premultiplied)
        base.fill(QColor(255, 255, 255, 0).rgba())
        p = QPainter(base)
        rect = QRect(20, 0, base_width, base_height)
        p.fillRect(rect, QColor('white'))
        p.drawRect(rect)
        rect.moveLeft(10)
        rect.moveTop(10)
        p.fillRect(rect, QColor('white'))
        p.drawRect(rect)
        rect.moveLeft(0)
        rect.moveTop(20)
        p.fillRect(rect, QColor('white'))
        p.save()
        p.setCompositionMode(p.CompositionMode_SourceAtop)
        p.drawImage(rect.topLeft(), cover)
        p.restore()
        p.drawRect(rect)
        p.end()
        cover = base
    return QPixmap.fromImage(cover)
Ejemplo n.º 2
0
 def __init__(self,
              name,
              color0=QColor("black"),
              color1=QColor("white"),
              alpha=(1, 1)):
     QObject.__init__(self)
     self.name = name
     # color is either specified as one argument (which should then be a [3,n] or [4,n] array),
     # or as two QColors orstring names.
     if isinstance(color0, (list, tuple)):
         self._rgb = numpy.array(color0)
         if self._rgb.shape[1] != 3 or self._rgb.shape[0] < 2:
             raise TypeError(
                 "expected [N,3] (N>=2) array as first argument")
     else:
         if isinstance(color0, str):
             color0 = QColor(color0)
         if isinstance(color1, str):
             color1 = QColor(color1)
         self._rgb = numpy.array([[
             color0.red(), color0.green(),
             color0.blue()
         ], [color1.red(), color1.green(),
             color1.blue()]]) / 255.
     self._rgb_arg = numpy.arange(
         self._rgb.shape[0]) / (self._rgb.shape[0] - 1.0)
     # alpha array
     self._alpha = numpy.array(alpha).astype(float)
     self._alpha_arg = numpy.arange(len(alpha)) / (len(alpha) - 1.0)
     # background brush
     self._brush = None
Ejemplo n.º 3
0
    def set_style(self, style):
        pf = PF(style=style)
        self.styles = {}
        self.normal = self.base_fmt()
        self.background_color = pf.style.background_color
        self.color = 'black'

        for ttype, ndef in pf.style:
            fmt = self.base_fmt()
            fmt.setProperty(fmt.UserProperty, str(ttype))
            if ndef['color']:
                fmt.setForeground(QBrush(QColor('#%s'%ndef['color'])))
                fmt.setUnderlineColor(QColor('#%s'%ndef['color']))
                if ttype == Generic.Output:
                    self.color = '#%s'%ndef['color']
            if ndef['bold']:
                fmt.setFontWeight(QFont.Bold)
            if ndef['italic']:
                fmt.setFontItalic(True)
            if ndef['underline']:
                fmt.setFontUnderline(True)
            if ndef['bgcolor']:
                fmt.setBackground(QBrush(QColor('#%s'%ndef['bgcolor'])))
            if ndef['border']:
                pass # No support for borders

            self.styles[ttype] = fmt
Ejemplo n.º 4
0
 def paintEvent(self, event):
     canvas_size = self.rect()
     width = self.current_pixmap_size.width()
     extrax = canvas_size.width() - width
     if extrax < 0: extrax = 0
     x = int(extrax / 2.)
     height = self.current_pixmap_size.height()
     extray = canvas_size.height() - height
     if extray < 0: extray = 0
     y = int(extray / 2.)
     target = QRect(x, y, width, height)
     p = QPainter(self)
     p.setRenderHints(QPainter.Antialiasing
                      | QPainter.SmoothPixmapTransform)
     p.drawPixmap(
         target,
         self.pixmap.scaled(target.size(), Qt.KeepAspectRatio,
                            Qt.SmoothTransformation))
     if gprefs['bd_overlay_cover_size']:
         sztgt = target.adjusted(0, 0, 0, -4)
         f = p.font()
         f.setBold(True)
         p.setFont(f)
         sz = u'\u00a0%d x %d\u00a0' % (self.pixmap.width(),
                                        self.pixmap.height())
         flags = Qt.AlignBottom | Qt.AlignRight | Qt.TextSingleLine
         szrect = p.boundingRect(sztgt, flags, sz)
         p.fillRect(szrect.adjusted(0, 0, 0, 4), QColor(0, 0, 0, 200))
         p.setPen(QPen(QColor(255, 255, 255)))
         p.drawText(sztgt, flags, sz)
     p.end()
Ejemplo n.º 5
0
Archivo: diff.py Proyecto: sss/calibre
    def paintEvent(self, event):
        pmap = self.blank if self.pixmap is None or self.pixmap.isNull(
        ) else self.pixmap
        target = self.rect()
        scaled, width, height = fit_image(pmap.width(), pmap.height(),
                                          target.width(), target.height())
        target.setRect(target.x(), target.y(), width, height)
        p = QPainter(self)
        p.setRenderHints(QPainter.Antialiasing
                         | QPainter.SmoothPixmapTransform)
        p.drawPixmap(target, pmap)

        if self.pixmap is not None and not self.pixmap.isNull():
            sztgt = target.adjusted(0, 0, 0, -4)
            f = p.font()
            f.setBold(True)
            p.setFont(f)
            sz = u'\u00a0%d x %d\u00a0' % (self.pixmap.width(),
                                           self.pixmap.height())
            flags = Qt.AlignBottom | Qt.AlignRight | Qt.TextSingleLine
            szrect = p.boundingRect(sztgt, flags, sz)
            p.fillRect(szrect.adjusted(0, 0, 0, 4), QColor(0, 0, 0, 200))
            p.setPen(QPen(QColor(255, 255, 255)))
            p.drawText(sztgt, flags, sz)
        p.end()
Ejemplo n.º 6
0
 def set_color(self):
     r, g, b = gprefs['cover_grid_color']
     pal = QPalette()
     col = QColor(r, g, b)
     pal.setColor(pal.Base, col)
     dark = (r + g + b) / 3.0 < 128
     pal.setColor(pal.Text, QColor(Qt.white if dark else Qt.black))
     self.setPalette(pal)
     self.delegate.highlight_color = pal.color(pal.Text)
Ejemplo n.º 7
0
    def __init__(self,
            prompt='>>> ',
            continuation='... ',
            parent=None):
        QTextEdit.__init__(self, parent)
        self.shutting_down = False
        self.compiler = CommandCompiler()
        self.buf = self.old_buf = []
        self.history = History([''], dynamic.get('console_history', []))
        self.prompt_frame = None
        self.allow_output = False
        self.prompt_frame_format = QTextFrameFormat()
        self.prompt_frame_format.setBorder(1)
        self.prompt_frame_format.setBorderStyle(QTextFrameFormat.BorderStyle_Solid)
        self.prompt_len = len(prompt)

        self.doc.setMaximumBlockCount(int(prefs['scrollback']))
        self.lexer = PythonLexer(ensurenl=False)
        self.tb_lexer = PythonTracebackLexer()

        self.context_menu = cm = QMenu(self) # {{{
        cm.theme = ThemeMenu(cm)
        # }}}

        self.formatter = Formatter(prompt, continuation, style=prefs['theme'])
        p = QPalette()
        p.setColor(p.Base, QColor(self.formatter.background_color))
        p.setColor(p.Text, QColor(self.formatter.color))
        self.setPalette(p)

        self.key_dispatcher = { # {{{
                Qt.Key_Enter : self.enter_pressed,
                Qt.Key_Return : self.enter_pressed,
                Qt.Key_Up : self.up_pressed,
                Qt.Key_Down : self.down_pressed,
                Qt.Key_Home : self.home_pressed,
                Qt.Key_End : self.end_pressed,
                Qt.Key_Left : self.left_pressed,
                Qt.Key_Right : self.right_pressed,
                Qt.Key_Backspace : self.backspace_pressed,
                Qt.Key_Delete : self.delete_pressed,
        } # }}}

        motd = textwrap.dedent('''\
        # Python {0}
        # {1} {2}
        '''.format(sys.version.splitlines()[0], __appname__,
            __version__))

        sys.excepthook = self.unhandled_exception

        self.controllers = []
        QTimer.singleShot(0, self.launch_controller)


        with EditBlock(self.cursor):
            self.render_block(motd)
Ejemplo n.º 8
0
    def add_image(self, img, cache_key):
        ref = self.get_image(cache_key)
        if ref is not None:
            return ref

        fmt = img.format()
        image = QImage(img)
        if (image.depth() == 1 and img.colorTable().size() == 2 and
            img.colorTable().at(0) == QColor(Qt.black).rgba() and
            img.colorTable().at(1) == QColor(Qt.white).rgba()):
            if fmt == QImage.Format_MonoLSB:
                image = image.convertToFormat(QImage.Format_Mono)
            fmt = QImage.Format_Mono
        else:
            if (fmt != QImage.Format_RGB32 and fmt != QImage.Format_ARGB32):
                image = image.convertToFormat(QImage.Format_ARGB32)
                fmt = QImage.Format_ARGB32

        w = image.width()
        h = image.height()
        d = image.depth()

        if fmt == QImage.Format_Mono:
            bytes_per_line = (w + 7) >> 3
            data = image.constBits().asstring(bytes_per_line * h)
            return self.write_image(data, w, h, d, cache_key=cache_key)

        has_alpha = False
        soft_mask = None

        if fmt == QImage.Format_ARGB32:
            tmask = image.constBits().asstring(4*w*h)[self.alpha_bit::4]
            sdata = bytearray(tmask)
            vals = set(sdata)
            vals.discard(255)  # discard opaque pixels
            has_alpha = bool(vals)
            if has_alpha:
                # Blend image onto a white background as otherwise Qt will render
                # transparent pixels as black
                background = QImage(image.size(), QImage.Format_ARGB32_Premultiplied)
                background.fill(Qt.white)
                painter = QPainter(background)
                painter.drawImage(0, 0, image)
                painter.end()
                image = background

        ba = QByteArray()
        buf = QBuffer(ba)
        image.save(buf, 'jpeg', 94)
        data = bytes(ba.data())

        if has_alpha:
            soft_mask = self.write_image(tmask, w, h, 8)

        return self.write_image(data, w, h, 32, dct=True,
                                soft_mask=soft_mask, cache_key=cache_key)
Ejemplo n.º 9
0
 def __init__(self):
     self.labels_font = QFont('Verdana', 10)
     self.helper_font = self.labels_font
     self.helpers_color = QColor(0, 0, 0, 255)
     self.background_color = QColor(255, 255, 255, 255)
     self.axis_title_font = QFont('Verdana', 11, QFont.Bold)
     self.axis_font = QFont('Verdana', 10)
     self.labels_color = QColor(0, 0, 0, 255)
     self.axis_color = QColor(30, 30, 30, 255)
     self.axis_values_color = QColor(30, 30, 30, 255)
Ejemplo n.º 10
0
def colorTagToQtColor(_colorTag, outputAlpha=False):

    if _colorTag is None:
        return QColor(Qt.yellow)

    colorTag = _colorTag.lower()

    if (colorTag == "red"):
        qtColor = QColor(Qt.red)
    elif (colorTag == "green"):
        qtColor = QColor(Qt.green)
    elif (colorTag == "blue"):
        qtColor = QColor(Qt.blue)
    elif (colorTag == "cyan"):
        qtColor = QColor(Qt.cyan)
    elif (colorTag == "darkGray"):
        qtColor = QColor(Qt.darkGray)
    elif (colorTag == "magenta"):
        qtColor = QColor(Qt.magenta)
    elif (colorTag == "yellow"):
        return QColor(Qt.yellow)
    elif (colorTag[0] == "#"):
        qtColor = hexColorStrToQtColor(colorTag, outputAlpha)
    else:
        qtColor = QColor(Qt.yellow)
    return qtColor
Ejemplo n.º 11
0
Archivo: test.py Proyecto: sss/calibre
def brush(p, xmax, ymax):
    x = 0
    y = 0
    w = xmax / 2
    g = QLinearGradient(QPointF(x, y + w / 3), QPointF(x, y + (2 * w / 3)))
    g.setColorAt(0, QColor('#f00'))
    g.setColorAt(0.5, QColor('#fff'))
    g.setColorAt(1, QColor('#00f'))
    g.setSpread(g.ReflectSpread)
    p.fillRect(x, y, w, w, QBrush(g))
    p.drawRect(x, y, w, w)
Ejemplo n.º 12
0
def read_color(col):
    if QColor.isValidColor(col):
        return QBrush(QColor(col))
    if col.startswith('rgb('):
        r, g, b = map(int, (x.strip() for x in col[4:-1].split(',')))
        return QBrush(QColor(r, g, b))
    try:
        r, g, b = col[0:2], col[2:4], col[4:6]
        r, g, b = int(r, 16), int(g, 16), int(b, 16)
        return QBrush(QColor(r, g, b))
    except Exception:
        pass
Ejemplo n.º 13
0
Archivo: test.py Proyecto: sss/calibre
def full(p, xmax, ymax):
    p.drawRect(0, 0, xmax, ymax)
    p.drawPolyline(QPoint(0, 0), QPoint(xmax, 0), QPoint(xmax, ymax),
                   QPoint(0, ymax), QPoint(0, 0))
    pp = QPainterPath()
    pp.addRect(0, 0, xmax, ymax)
    p.drawPath(pp)
    p.save()
    for i in xrange(3):
        col = [0, 0, 0, 200]
        col[i] = 255
        p.setOpacity(0.3)
        p.fillRect(0, 0, xmax / 10, xmax / 10, QBrush(QColor(*col)))
        p.setOpacity(1)
        p.drawRect(0, 0, xmax / 10, xmax / 10)
        p.translate(xmax / 10, xmax / 10)
        p.scale(1, 1.5)
    p.restore()

    # p.scale(2, 2)
    # p.rotate(45)
    p.drawPixmap(0, 0, xmax / 4, xmax / 4, QPixmap(I('library.png')))
    p.drawRect(0, 0, xmax / 4, xmax / 4)

    f = p.font()
    f.setPointSize(20)
    # f.setLetterSpacing(f.PercentageSpacing, 200)
    f.setUnderline(True)
    # f.setOverline(True)
    # f.setStrikeOut(True)
    f.setFamily('Calibri')
    p.setFont(f)
    # p.setPen(QColor(0, 0, 255))
    # p.scale(2, 2)
    # p.rotate(45)
    p.drawText(QPoint(xmax / 3.9, 30), 'Some—text not By’s ū --- Д AV ff ff')

    b = QBrush(Qt.HorPattern)
    b.setColor(QColor(Qt.blue))
    pix = QPixmap(I('console.png'))
    w = xmax / 4
    p.fillRect(0, ymax / 3, w, w, b)
    p.fillRect(xmax / 3, ymax / 3, w, w, QBrush(pix))
    x, y = 2 * xmax / 3, ymax / 3
    p.drawTiledPixmap(QRectF(x, y, w, w), pix, QPointF(10, 10))

    x, y = 1, ymax / 1.9
    g = QLinearGradient(QPointF(x, y), QPointF(x + w, y + w))
    g.setColorAt(0, QColor('#00f'))
    g.setColorAt(1, QColor('#fff'))
    p.fillRect(x, y, w, w, QBrush(g))
Ejemplo n.º 14
0
 def paintEvent(self, painter, width, height):
     painter.setBrush(QBrush(QColor(255, 0, 0), Qt.SolidPattern))
     if self.alive == False:
         painter.setBrush(QBrush(QColor(255, 0, 255), Qt.SolidPattern))
     painter.drawRect(self.headX * width, self.headY * height, width,
                      height)
     pX = self.headX
     pY = self.headY
     for pX, pY in self.getTailPoints():
         painter.drawRect(pX * width, pY * height, width, height)
     painter.setBrush(QBrush(QColor(0, 0, 255), Qt.SolidPattern))
     if self.alive == True:
         painter.drawRect(self.fruitX * width, self.fruitY * height, width,
                          height)
Ejemplo n.º 15
0
def getColorDesc(_colorTag, outputAlpha=False):

    if _colorTag is None:
        return QColor(Qt.yellow), "#FFFF00"

    colorTag = _colorTag.lower()
    if (colorTag == "red"):
        qtColor = QColor(Qt.red)
    elif (colorTag == "green"):
        qtColor = QColor(Qt.green)
    elif (colorTag == "blue"):
        qtColor = QColor(Qt.blue)
    elif (colorTag == "cyan"):
        qtColor = QColor(Qt.cyan)
    elif (colorTag == "darkGray"):
        qtColor = QColor(Qt.darkGray)
    elif (colorTag == "magenta"):
        qtColor = QColor(Qt.magenta)
    elif (colorTag[0] == "#"):
        colorHexDesc = colorTag
        qtColor = hexColorStrToQtColor(colorTag, outputAlpha)
    else:
        qtColor = QColor(Qt.yellow)
        colorHexDesc = "#FFFF00"

    if qtColor is not None:
        colorHexDesc = "#%02x%02x%02x" % (qtColor.red(), qtColor.green(),
                                          qtColor.blue())

    # LOG.info("qtColor = {}, colorHexDesc = {}".format(qtColor, colorHexDesc))
    return qtColor, colorHexDesc
Ejemplo n.º 16
0
 def set_color(self):
     r, g, b = gprefs['cover_grid_color']
     pal = QPalette()
     col = QColor(r, g, b)
     pal.setColor(pal.Base, col)
     tex = gprefs['cover_grid_texture']
     if tex:
         from calibre.gui2.preferences.texture_chooser import texture_path
         path = texture_path(tex)
         if path:
             pal.setBrush(pal.Base, QBrush(QPixmap(path)))
     dark = (r + g + b)/3.0 < 128
     pal.setColor(pal.Text, QColor(Qt.white if dark else Qt.black))
     self.setPalette(pal)
     self.delegate.highlight_color = pal.color(pal.Text)
Ejemplo n.º 17
0
 def paint(self, painter, option,index):
     if index.column() ==1:
         painter.save()
         model = index.model()
         userNameIndex = model.index(index.row(),LabelDelegate.USER_NAME_COLUMN)
         msgCountIndex = model.index(index.row(),LabelDelegate.MSG_COUNT_COLUMN)
         
         userName = model.data(userNameIndex).toString()
         msgCount = model.data(msgCountIndex).toString()
         
         if option.state & QStyle.State_Selected:
             painter.fillRect(option.rect, option.palette.highlight())
         rect_x = option.rect.x()
         rect_y = option.rect.y()
         head_image_x_offset = 5
         head_image_y_offset = 10
         head_image_x = rect_x + head_image_x_offset
         head_image_y = rect_y + head_image_y_offset
         image = ("%s/.wechat/%s/%s.jpg")%(LabelDelegate.USER_HOME,LabelDelegate.CONTACT_HEAD_HOME,userName)
         if not os.path.exists(image):
             image = LabelDelegate.DEFAULT_IMAGE
         painter.drawPixmap(head_image_x,head_image_y,LabelDelegate.HEAD_IMG_WIDTH,LabelDelegate.HEAD_IMG_HEIGHT, QPixmap(image))
         if msgCount and msgCount > 0:
             white = QColor(255, 0, 0)
             painter.setPen(white)
             painter.setBrush(white)
             ellipse_r = 20
             ellipse_x = rect_x+LabelDelegate.HEAD_IMG_WIDTH-5
             ellipse_y = rect_y+head_image_y_offset-7.5
             
             painter.drawEllipse(ellipse_x,ellipse_y,ellipse_r,ellipse_r)
             red = QColor(255, 255, 255)
             painter.setPen(red)
             painter.setBrush(red)
             
             msg_count_x = rect_x+LabelDelegate.HEAD_IMG_WIDTH+2.5
             
             if msgCount >= 10 and msgCount < 100:
                 msg_count_x = msg_count_x - 0.5
             elif msgCount >= 100 and msgCount < 1000:
                 msg_count_x = msg_count_x - 3.5
             elif msgCount >= 1000 and msgCount < 10000:
                 msg_count_x = msg_count_x - 5
             msg_count_y = rect_y+head_image_y_offset + 5
             painter.drawText(msg_count_x,msg_count_y, str(msgCount))
         painter.restore()
     else:
         super(LabelDelegate, self).paint(painter, option, index)
Ejemplo n.º 18
0
 def logError(self, msg):
     self.ui.logger.setFontWeight(90)
     self.ui.logger.setColor(QColor("red"))
     self.ui.logger.append(msg)
     self.ui.listOfModules.clear()
     self.modulesToUpload = []
     self.ui.uploadButton.setEnabled(True)
Ejemplo n.º 19
0
    def penMoveEvent(self, pos, pressure, liftedDeque):
        pen_x = pos[0]
        pen_y = pos[1]
        pen_pressure = pressure

        # print(liftedDeque)
        # print(self.__lastPos)

        if self.__lastPos is None:
            self.__lastPos = QPoint(pen_x, pen_y)

        self.__currentPos = QPoint(pen_x, pen_y)
        self.__painter.begin(self.__board)

        if self.EraserMode == False:
            #Non-Eraser mode
            self.__penColor = QColor("blue")
            self.__painter.setPen(QPen(
                self.__penColor, self.__thickness))  #Set pen color, thickness
        else:
            #Eraser mode: pen color is white, thickness is 6
            self.__painter.setPen(QPen(Qt.white, 6))

        self.__painter.drawLine(self.__lastPos, self.__currentPos)
        self.__painter.end()
        self.__lastPos = self.__currentPos

        self.update()  #Show updates

        # If ever detected the pen is lifted, reset the __lastPos variable in order to reposition the pen
        if (True in liftedDeque):
            self.__lastPos = None
Ejemplo n.º 20
0
    def paintArc(self, center_x, center_y, start_x, start_y, end_x, end_y):
        radius = math.sqrt(
            math.pow(center_x - start_x, 2) + math.pow(center_y - start_y, 2))
        rect = QRectF(center_x - radius, center_y - radius, radius * 2,
                      radius * 2)
        # start angle calculation
        startAngle = math.degrees(
            math.atan2(center_y - start_y, start_x - center_x))
        # end angle calculation
        endAngle = math.degrees(math.atan2(center_y - end_y, end_x - center_x))

        # span angle calculation
        spanAngle = endAngle - startAngle
        # assume user always wants to draw clock-wise
        if spanAngle > 0:
            spanAngle = -1 * (360 - spanAngle)
        #print("start angle is " + str(startAngle))
        #print("span angle is " + str(spanAngle))

        self.__painter.begin(self.__board)
        self.__penColor = QColor("black")
        self.__painter.setPen(QPen(self.__penColor, self.__thickness))
        self.__painter.drawArc(rect, 16 * startAngle, 16 * spanAngle)
        self.__painter.end()

        self.update()  #Show updates
Ejemplo n.º 21
0
    def __init__(self,
                 parent,
                 x=0,
                 y=0,
                 width=None,
                 height=None,
                 img=None,
                 text=None,
                 togglable=False,
                 imgoff=None,
                 action=None,
                 params=None):
        Action.__init__(self, action, params)
        GLFrame.__init__(self, parent, x, y, width, height)

        self.img = img
        self.setText(text)
        self.textColor = QColor(0, 0, 0)
        self.togglable = togglable
        self.toggled = False
        self.imgoff = imgoff

        self.focus = False
        self.enabled = True
        self.__initialized__ = False
Ejemplo n.º 22
0
 def draw_image_error(self, painter):
     font = painter.font()
     font.setPointSize(3 * font.pointSize())
     font.setBold(True)
     painter.setFont(font)
     painter.setPen(QColor(Qt.black))
     painter.drawText(self.rect(), Qt.AlignCenter, _('Not a valid image'))
Ejemplo n.º 23
0
    def __init__(self, gui):
        QWidget.__init__(self, gui)
        self.setObjectName('jobs_pointer')
        self.setVisible(False)
        self.resize(100, 80)
        self.animation = QPropertyAnimation(self, "geometry", self)
        self.animation.setDuration(750)
        self.animation.setLoopCount(2)
        self.animation.setEasingCurve(QEasingCurve.Linear)
        self.animation.finished.connect(self.hide)

        taily, heady = 0, 55
        self.arrow_path = QPainterPath(QPointF(40, taily))
        self.arrow_path.lineTo(40, heady)
        self.arrow_path.lineTo(20, heady)
        self.arrow_path.lineTo(50, self.height())
        self.arrow_path.lineTo(80, heady)
        self.arrow_path.lineTo(60, heady)
        self.arrow_path.lineTo(60, taily)
        self.arrow_path.closeSubpath()

        c = self.palette().color(QPalette.Active, QPalette.WindowText)
        self.color = QColor(c)
        self.color.setAlpha(100)
        self.brush = QBrush(self.color, Qt.SolidPattern)
Ejemplo n.º 24
0
    def initializeFormats(self):
        Config = self.Config
        Config["fontfamily"] = "monospace"
        #Config["fontsize"] = 10
        for name, color, bold, italic in (
                ("normal", "#000000", False, False),
                ("keyword", "#000080", True, False),
                ("builtin", "#0000A0", False, False),
                ("comment", "#007F00", False, True),
                ("string", "#808000", False, False),
                ("number", "#924900", False, False),
                ("lparen", "#000000", True, True),
                ("rparen", "#000000", True, True)):
            Config["%sfontcolor" % name] = color
            Config["%sfontbold" % name] = bold
            Config["%sfontitalic" % name] = italic

        baseFormat = QTextCharFormat()
        baseFormat.setFontFamily(Config["fontfamily"])
        #baseFormat.setFontPointSize(Config["fontsize"])

        for name in ("normal", "keyword", "builtin", "comment",
                     "string", "number", "lparen", "rparen"):
            format = QTextCharFormat(baseFormat)
            format.setForeground(QColor(Config["%sfontcolor" % name]))
            if Config["%sfontbold" % name]:
                format.setFontWeight(QFont.Bold)
            format.setFontItalic(Config["%sfontitalic" % name])
            self.Formats[name] = format
    def drawScaleContents(self, painter, center, radius):
        dir = 90  #360 - int(roud(self.origin() - self.value()))
        arc = 90  #+ int(round(self.gradient * 90))
        skyColor = QColor(38, 151, 221)
        painter.save()
        painter.setBrush(skyColor)
        painter.drawChord(self.scaleContentsRect(), (dir - arc) * 16,
                          2 * arc * 16)
        direction1 = self.value() * M_PI / 180.0
        direction2 = self.value() * M_PI / 180.0 + M_PI_2

        triangleSize = qRound(radius * 0.15)
        p0 = (QPoint(center.x() + 0, center.y() + 0))
        p1 = qwtPolar2Pos(p0, 2, direction2)
        pa = QPolygon(3)
        pa.setPoint(0, qwtPolar2Pos(p1, 2 * triangleSize, direction2))
        pa.setPoint(1, qwtPolar2Pos(p1, triangleSize, direction2 + M_PI_2))
        pa.setPoint(2, qwtPolar2Pos(p1, triangleSize, direction2 - M_PI_2))
        color = self.palette().color(QPalette.Text)
        painter.setBrush(color)
        painter.drawPolygon(pa)

        p0 = (QPoint(center.x() + 0, center.y() + 0))
        color = self.palette().color(QPalette.Text)
        painter.setBrush(color)
        painter.setPen(QPen(color, 3))
        painter.drawLine(qwtPolar2Pos(p0, radius - 3, direction1),
                         qwtPolar2Pos(p0, radius - 3, direction1 - M_PI))

        painter.restore()
Ejemplo n.º 26
0
    def draw_spinner(self, painter, rect):
        width = rect.width()

        outer_radius = (width - 1) * 0.5
        inner_radius = (width - 1) * 0.5 * 0.38

        capsule_height = outer_radius - inner_radius
        capsule_width = int(capsule_height * (0.23 if width > 32 else 0.35))
        capsule_radius = capsule_width // 2

        painter.save()
        painter.setRenderHint(painter.Antialiasing)

        for i in xrange(12):
            color = QColor(self.color)
            color.setAlphaF(1.0 - (i / 12.0))
            painter.setPen(Qt.NoPen)
            painter.setBrush(color)
            painter.save()
            painter.translate(rect.center())
            painter.rotate(self.angle - i * 30.0)
            painter.drawRoundedRect(-capsule_width * 0.5,
                                    -(inner_radius + capsule_height),
                                    capsule_width, capsule_height,
                                    capsule_radius, capsule_radius)
            painter.restore()
        painter.restore()
Ejemplo n.º 27
0
 def data(self, role):
     if role == Qt.DisplayRole:
         return QVariant(self.cdata + ' [%d]' % len(self.children))
     elif role == Qt.FontRole:
         return self.bold_font
     elif role == Qt.ForegroundRole and self.category == _('Scheduled'):
         return QVariant(QColor(0, 255, 0))
     return NONE
Ejemplo n.º 28
0
def colorStrToQtColor(colorStr, outputAlpha=False):
    if colorStr is None:
        return QColor(Qt.yellow)

    if colorStr[0] == '#':
        return hexColorStrToQtColor(colorStr, outputAlpha)
    else:
        return colorTagToQtColor(colorStr, outputAlpha)
Ejemplo n.º 29
0
 def value_as_QColor(self, value=None):  ###k untested??
     #e API is getting a bit klugy... we're using a random instance as knowing about the superset of colors,
     # and using its default value as the value here...
     if value is None:
         value = self.get_defaultValue()
     rgb = self.value_as_int_tuple(value)
     from PyQt4.Qt import QColor
     return QColor(rgb[0], rgb[1], rgb[2])  #k guess
Ejemplo n.º 30
0
 def changeGridColor(self):
     """
     Open the stand color chooser dialog to change grid line color
     """
     c = QColorDialog.getColor(QColor(222, 148, 0), self)
     if c.isValid():
         self.gridColorLabel.setPaletteBackgroundColor(c)
         self.command.setGridLineColor(c)