Exemplo n.º 1
0
 def fromStr(name, a=255):
     if name in _Colorizer.__colorTable:
         c = QColor(_Colorizer.__colorTable[name])
     else:
         c = QColor(Qt.transparent)
     c.setAlpha(a)
     return c
Exemplo n.º 2
0
    def _draw_horizontal_ruler(self, painter, text, y_value, color):

        y = y_value * self.y_factor

        pen = QPen()
        pen.setCapStyle(Qt.SquareCap)
        pen.setColor(color)

        qp = QPainterPath()

        r = QRect(1,1,1000,1000)
        bb = painter.boundingRect(r,Qt.AlignLeft,text)
        bb = QRect(self.x_base,self.y_base - y - bb.height(), bb.width() + 2, bb.height())

        # print("{} {} {} {}".format(bb.x(),bb.y(),bb.width(),bb.height()))

        fill_color = QColor(0,0,0)
        fill_color.setAlpha(128)
        brush = QBrush(fill_color)

        painter.fillRect(bb,brush)

        qp.moveTo(self.x_base,self.y_base - y)
        qp.lineTo(self.total_width + self.x_base, self.y_base - y)

        painter.setPen(pen)
        painter.drawPath(qp)

        text_pen = QPen()
        text_pen.setCapStyle(Qt.RoundCap)
        text_pen.setColor(color) # alpha=255=fully opaque
        text_pen.setWidth(1)

        painter.setPen(text_pen)
        painter.drawText(self.x_base,self.y_base - y - 5,text)
Exemplo n.º 3
0
 def fromStr(name, a=255):
     if name in _Colorizer.__colorTable:
         c = QColor(_Colorizer.__colorTable[name])
     else:
         c = QColor(Qt.transparent)
     c.setAlpha(a)
     return c
Exemplo n.º 4
0
    def _draw_serie(self, painter, ndx_serie, color):

        serie = self.data[ndx_serie]

        #mainlog.debug(serie)

        fill_color = QColor(color)
        fill_color.setAlpha(64)
        brush = QBrush(fill_color)
        pen = QPen()
        pen.setCapStyle(Qt.SquareCap)
        pen.setColor(color)

        qp = QPainterPath()
        painter.setPen(pen)

        for i in range(len(serie)):
            x, y_top, y_below = self._item_coordinates(i)

            h = max(1, float(y_top - y_below - 1))
            qp.addRect( x,
                        float(self.y_base-y_top),
                        float(self.bar_width),
                        h)

        painter.fillPath(qp,brush)
        painter.drawPath(qp)

        #mainlog.debug("Drawing peak values, juste before {}".format(self._peak_values))
        if self._peak_values:
            #mainlog.debug("Drawing peak values")
            self._draw_peak_values(painter, self._peak_values )
Exemplo n.º 5
0
    def _draw_selected_items_in_series(self, painter):
        fm = painter.fontMetrics()

        pen = QPen()
        pen.setWidth(1)
        pen.setColor(Qt.GlobalColor.white)
        painter.setPen(pen)

        # We assume all series have the very same number of values
        # and all values on the same index are drawn on the same X
        # coordinate

        ndx_serie = self.best_serie_intra_ndx

        aesthetic_shift = 5

        if ndx_serie is not None:

            to_draw = []
            for i in range(len(self.data)):
                x, y = self._item_coordinates_lines(i, ndx_serie)
                #mainlog.debug("{} {}".format(ndx_serie,i))
                v = self.data[i][ndx_serie]

                text = str(int(v))

                to_draw.append( (self.y_base - y, text) )

            last_y = 100000
            for y, text in sorted( to_draw, key=lambda z : z[0], reverse=True):
                r = QRect(x + aesthetic_shift,0,1000,1000)
                bb = painter.boundingRect(r,Qt.AlignLeft,text)
                if bb.right() > self.width():
                    x = x - bb.width() - 2*aesthetic_shift# left align

                if y + bb.height() > last_y:
                    y = last_y - bb.height()

                fill_color = QColor(16, 16, 48)
                fill_color.setAlpha(196)
                brush = QBrush(fill_color)
                margin = 2
                r = QRect(x + aesthetic_shift - margin,
                          y - aesthetic_shift - bb.height() - margin,
                          bb.width() + 2*margin,
                          bb.height() + 2*margin)
                painter.fillRect(r, brush)

                painter.drawText(x + aesthetic_shift,
                                 y - aesthetic_shift,
                                 text)

                last_y = y

            x, y = self._item_coordinates_lines(0, ndx_serie)
            qp = QPainterPath()
            qp.moveTo(x, self.y_base)
            qp.lineTo(x, self.y_base - self.total_height)
            painter.drawPath(qp)
Exemplo n.º 6
0
    def _init_ui(self, txt):
        self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint | QtCore.Qt.FramelessWindowHint)

        pal = QPalette()
        color = QColor()
        color.setNamedColor(self._window_bgcolor)
        color.setAlpha(255 * self._opacity)
        pal.setColor(QPalette.Background, color)

        self.setAutoFillBackground(True)
        self.setPalette(pal)

        wm, hm = 5, 5
        spacing = 8
        layout = QVBoxLayout()
        layout.setSpacing(spacing)
        layout.setContentsMargins(wm, hm, wm, hm)

        nlines, ts = self._generate_text(txt)

        qlabel = QLabel('\n'.join(ts))

        ss = 'QLabel {{color: {}; font-family:{}, sans-serif; font-size: {}px}}'.format(self._color,
                                                                                        self._font,
                                                                                        self._fontsize)
        qlabel.setStyleSheet(ss)
        layout.addWidget(qlabel)

        hlabel = QLabel('double click to dismiss')
        hlabel.setStyleSheet('QLabel {font-size: 10px}')

        hlayout = QHBoxLayout()

        hlayout.addStretch()
        hlayout.addWidget(hlabel)
        hlayout.addStretch()

        layout.addLayout(hlayout)

        self.setLayout(layout)

        font = QFont(self._font, self._fontsize)
        fm = QFontMetrics(font)

        pw = max([fm.width(ti) for ti in ts])
        ph = (fm.height() + 2) * nlines

        w = pw + wm * 2
        h = ph + (hm + spacing + 1) * 2

        self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        self.setFixedWidth(w)
        self.setFixedHeight(h)

        self.setMask(mask(self.rect(), 10))
Exemplo n.º 7
0
    def _draw_serie(self, painter, ndx_serie, color):

        last_item = len(self.data) - 1

        serie = self.data[ndx_serie]

        serie_below = [0] * len(self.data[last_item])
        if ndx_serie < len(self.data) - 1:
            serie_below = self.data[ ndx_serie + 1 ]

        qlp = QPainterPath() # The top line path
        qfp = QPainterPath() # the filled region path


        x = float(0) * self.x_factor
        y = serie[0] * self.y_factor
        qlp.moveTo(self.x_base + x,self.y_base - y)
        qfp.moveTo(self.x_base + x,self.y_base - y)

        for i in range(1,len(serie)):
            x = float(i) * self.x_factor
            y = float(serie[i]) * self.y_factor

            #print i,y

            qlp.lineTo(self.x_base + x, self.y_base-y)
            qfp.lineTo(self.x_base + x, self.y_base-y)



        for i in reversed(range(0,len(serie_below))):
            x = float(i) * self.x_factor
            y = float(serie_below[i]) * self.y_factor

            qfp.lineTo(self.x_base + x, self.y_base-y)

        qfp.closeSubpath()


        fill_color = QColor(color)
        fill_color.setAlpha(64)
        brush = QBrush(fill_color)
        painter.fillPath(qfp,brush)

        pen = QPen()
        pen.setColor(color)
        if ndx_serie == self.ndx_best_serie:
            pen.setWidth(6)
        else:
            pen.setWidth(2)

        painter.setPen(pen)

        painter.drawPath(qlp)
Exemplo n.º 8
0
    def _draw_box_under_text(self,painter,x,y,text):
        r = QRect(1,1,1000,1000)
        bb = painter.boundingRect(r,Qt.AlignLeft,text)
        bb = QRect(x,y - bb.height() +2 , bb.width() + 2, bb.height())

        # print("{} {} {} {}".format(bb.x(),bb.y(),bb.width(),bb.height()))

        fill_color = QColor(0,0,0)
        fill_color.setAlpha(170)
        brush = QBrush(fill_color)

        painter.fillRect(bb,brush)
Exemplo n.º 9
0
    def drawPolygon(self):
        path = [mark.coordinate() for mark in self.markerObjects]

        pen = QPen(Qt.white)
        pen.setWidth(2)
        pen.setCosmetic(True)
        polygon = QGeoMapPolygonObject()
        polygon.setPen(pen)
        fill = QColor(Qt.black)
        fill.setAlpha(65)
        polygon.setBrush(QBrush(fill))
        polygon.setPath(path)

        self.mapWidget.addMapObject(polygon)
Exemplo n.º 10
0
    def routeFinished(self):

        if not self.routeReply.routes():
            return

        route = QGeoMapRouteObject(self.routeReply.routes()[0])
        routeColor = QColor(Qt.blue)
        routeColor.setAlpha(127)
        pen = QPen(routeColor)
        pen.setWidth(7)
        pen.setCosmetic(True)
        pen.setCapStyle(Qt.RoundCap)
        route.setPen(pen)
        self.mapWidget.addMapObject(route)
Exemplo n.º 11
0
    def drawRect(self):
        if len(self.markerObjects) < 2:
            return

        p1, p2 = self.markerObjects[:2]

        pen = QPen(Qt.white)
        pen.setWidth(2)
        pen.setCosmetic(True)
        fill = QColor(Qt.black)
        fill.setAlpha(65)
        rectangle = QGeoMapRectangleObject(p1.coordinate(), p2.coordinate())
        rectangle.setPen(pen)
        rectangle.setBrush(QBrush(fill))
        self.mapWidget.addMapObject(rectangle)
Exemplo n.º 12
0
class WeekCalendar(QCalendarWidget):

    def __init__(self, *args):

        QCalendarWidget.__init__(self, *args)
        self.color = QColor(self.palette().color(QPalette.Highlight))
        self.color.setAlpha(64)
        self.selectionChanged.connect(self.updateCells)

    def paintCell(self, painter, rect, date):

        QCalendarWidget.paintCell(self, painter, rect, date)
        filelist = glob.glob('journal_[0-9]*')
        datelist = []
        for i in filelist:
            l = tuple(i[i.index('_') + 1:].split('_'))
            datelist.append(QDate(int(l[2]), int(l[1]), int(l[0])))
        if date in datelist:
            painter.fillRect(rect, self.color)
Exemplo n.º 13
0
    def createPixmapIcon(self):
        self.markerIcon = QPixmap(MARKER_WIDTH, MARKER_HEIGHT)
        self.markerIcon.fill(Qt.transparent)

        painter = QPainter(self.markerIcon)

        p1 = QPoint(MARKER_WIDTH / 2, MARKER_HEIGHT - 1)
        p2 = QPoint(MARKER_WIDTH / 2, MARKER_HEIGHT - 1 - MARKER_PIN_LEN)
        pen = QPen(Qt.black)
        pen.setWidth(2)
        pen.setCosmetic(True)
        painter.setPen(pen)
        painter.drawLine(p1, p2)
        ellipse = QRect(0, 0, MARKER_WIDTH - 1, MARKER_HEIGHT - 1)
        pen.setWidth(1)
        painter.setPen(pen)
        color = QColor(Qt.green)
        color.setAlpha(127)
        brush = QBrush(color)
        painter.setBrush(brush)
        painter.drawEllipse(ellipse)
Exemplo n.º 14
0
    def drawCircle(self):

        if not len(self.markerObjects):
            return

        p1 = self.markerObjects[0]
        center = p1.coordinate()

        radius = 3000 # Meters

        if len(self.markerObjects) >= 2:
            radius = center.distanceTo(self.markerObjects[1].coordinate())

        pen = QPen(Qt.white)
        pen.setWidth(2)
        pen.setCosmetic(True)
        circle = QGeoMapCircleObject(center, radius)
        circle.setPen(pen)
        fill = QColor(Qt.black)
        fill.setAlpha(65)
        circle.setBrush(QBrush(fill))

        self.mapWidget.addMapObject(circle)
Exemplo n.º 15
0
 def fromQcolor(qtColor, a=255):
     c = QColor(qtColor)
     c.setAlpha(a)
     return c
Exemplo n.º 16
0
    def _draw_legend(self, painter, labels):
        text_pen = QPen()
        text_pen.setCapStyle(Qt.RoundCap)
        text_pen.setColor(QColor(200, 200, 200)) # alpha=255=fully opaque
        text_pen.setWidth(1)

        highlighted_text_pen = QPen()
        highlighted_text_pen.setColor(QColor(255, 255, 255)) # alpha=255=fully opaque
        highlighted_text_pen.setWidth(1)

        line_pen = QPen()
        line_pen.setCapStyle(Qt.RoundCap)
        line_pen.setColor(QColor(200, 200, 200)) # alpha=255=fully opaque
        line_pen.setWidth(2)

        max_width = 0
        fm = painter.fontMetrics()
        for label in labels:
            max_width = max(fm.boundingRect(label).width(), max_width)

        y_room = int(self.height() * 0.5 / self.text_height)

        nb_columns = int( len(labels)  / y_room)
        if len(labels) % y_room > 0:
            nb_columns += 1

        y_room = y_room * self.text_height

        x = self.margin + self.total_width - nb_columns * (max_width + 10)



        # 100 / 20 = 5 entry per column
        # 17 / 5 = 3 => 4 columns
        # print self.height() * 0.5, "  ", len(labels), "   ", nb_columns, " y_room:", y_room

        y = 0
        i = 0
        y_offset = self.yoffset
        self.legend_labels_bounding_boxes = []

        # Draw a background rectanlge behin the legend

        fill_color = QColor(16,16,48)
        fill_color.setAlpha(196)
        brush = QBrush(fill_color)

        h = y_room
        w = nb_columns * (max_width + 10)
        if nb_columns == 1:
            h = len(labels) * self.text_height

        r = QRect(x-3, y_offset - self.text_height , w, h + 6)
        painter.fillRect(r,brush)

        sorted_labels = sorted( zip( range(len(labels)), labels, map(id,self.data)),
                                lambda a,b:cmp(a[1],b[1]))

        # mainlog.debug( sorted_labels)

        # We sort labels on their names (but keep the indices right)
        for data_ndx, label in sorted( zip(range(len(labels)),labels), lambda a,b:cmp(a[1],b[1])):

            # Draw coloured line

            line_pen.setColor(self.graph_colors[data_ndx % len(self.graph_colors)]) # alpha=255=fully opaque
            painter.setPen(line_pen)

            if data_ndx == self.ndx_best_serie:
                r = QRect(x-3, y_offset+ y-self.text_height+3, max_width + 6, self.text_height)
                painter.drawRect(r)
                painter.setPen(highlighted_text_pen)
            else:
                painter.drawLine(x,y_offset+y+3,x+max_width,y_offset+y + 3)
                painter.setPen(text_pen)

            painter.drawText(x,y_offset+y,label)

            # Remember text bounding box
            r = QRect(x,y_offset+y - self.text_height,max_width,self.text_height)

            # if label == "TO":
            #    painter.drawRect(r)

            bb = painter.boundingRect(r,Qt.AlignLeft,label)
            # bb.adjust(-5,-5,+5,+5)
            # print label,label_ndx,r.x(), r.y(), r.width(), r.height()

            self.legend_labels_bounding_boxes.append( (data_ndx,bb) )


            if y >= y_room - self.text_height:
                y = 0
                x += max_width + 10
            else:
                y += self.text_height


            i += 1
Exemplo n.º 17
0
 def draw(self, painter, offset=Point()):
     painter.setPen(self.pen)
     color = QColor(self.pen.color())
     color.setAlpha(50)
     painter.setBrush(QColor(color))
     painter.drawRect(self.origin.x + offset.x, self.origin.y + offset.y, self.size.width, self.size.height)
Exemplo n.º 18
0
def QcolorA(color, alpha):
    col = QColor(color)
    col.setAlpha(alpha)
    return col
Exemplo n.º 19
0
 def fromQcolor(qtColor, a=255):
     c = QColor(qtColor)
     c.setAlpha(a)
     return c
Exemplo n.º 20
0
from PySide.QtGui import QColor, QBrush, QPen
from PySide.QtCore import Qt

print "Initializing Color"

colorHexLine        = QColor(Qt.green)
colorHexBrush       = QColor(192,255,192)
colorHexRoute       = QColor(255,192,0)
colorHexRoute.setAlpha(128)
colorHexRouteSel    = QColor(192,128,0)
colorHexRouteSel.setAlpha(128)


penLine             = QPen(colorHexLine)
penLine.setWidthF(2.0)
penRoute            = QPen(colorHexRoute)
penRoute.setWidthF(12.0)
penRouteSel         = QPen(colorHexRouteSel)
penRouteSel.setWidthF(12.0)

brushHex            = QBrush(colorHexBrush) 
Exemplo n.º 21
0
    def _draw_serie(self, painter, ndx_serie, color):

        last_item = len(self.data) - 1

        serie = self.data[ndx_serie]

        serie_below = [0] * len(self.data[last_item])
        if ndx_serie < len(self.data) - 1:
            serie_below = self.data[ndx_serie + 1]

        fill_color = QColor(color)
        fill_color.setAlpha(64)
        brush = QBrush(fill_color)
        pen = QPen()
        pen.setCapStyle(Qt.SquareCap)
        pen.setColor(color)

        for i in range(len(serie)):
            x, y_top, y_below = self._item_coordinates(ndx_serie, i)

            qp = QPainterPath()

            h = float(y_top - y_below - 1)
            if h > 0:
                qp.addRect(x, float(self.y_base - y_top),
                           float(self.bar_width), h)

                painter.fillPath(qp, brush)

                if self.ndx_best_serie == ndx_serie and (
                        self.best_serie_intra_ndx is None or
                    (self.best_serie_intra_ndx >= 0
                     and self.best_serie_intra_ndx == i)):
                    pen.setWidth(3)
                else:
                    pen.setWidth(1)

                painter.setPen(pen)
                painter.drawPath(qp)

        if ndx_serie == self.ndx_best_serie:
            fm = painter.fontMetrics()
            pen.setWidth(1)
            painter.setPen(pen)

            serie_below = None
            if ndx_serie < len(self.data) - 1:
                serie_below = self.data[ndx_serie + 1]

            for i in range(len(serie)):
                if (self.best_serie_intra_ndx
                        == i) or self.best_serie_intra_ndx is None:
                    x, y_top, y_below = self._item_coordinates(ndx_serie, i)
                    l_len = 15

                    v = serie[i]
                    if serie_below:
                        v = v - serie_below[i]
                    v = str(int(v))
                    bb = fm.boundingRect(v)

                    pen.setColor(color)
                    y = 0
                    if i < len(serie) - 1:
                        # small diagonal going top, right
                        painter.drawLine(x + self.bar_width,
                                         self.y_base - y_top,
                                         x + self.bar_width + l_len,
                                         self.y_base - (y_top + l_len))

                        x = x + self.bar_width + l_len
                        y = y_top + l_len
                    else:
                        # small diagonal going top, left
                        painter.drawLine(x, self.y_base - y_top, x - l_len,
                                         self.y_base - (y_top - l_len))

                        x = x - l_len - bb.width()
                        y = y_top - l_len

                    bb.moveTo(int(x), int(self.y_base - y - bb.height()))

                    brush = QBrush(Qt.GlobalColor.red)
                    bb.adjust(-2, +2, +4, +4)

                    bb.adjust(-2, -2, +2, +2)
                    painter.fillRect(bb, brush)

                    bb.adjust(+2, +2, -2, -2)
                    painter.drawRect(bb)

                    pen.setColor(Qt.GlobalColor.white)
                    painter.setPen(pen)
                    painter.drawText(x, self.y_base - y, str(int(v)))
Exemplo n.º 22
0
def QcolorA(color, alpha):
    col = QColor(color)
    col.setAlpha(alpha)
    return col
Exemplo n.º 23
0
def _display_color(color, selected):
    alpha = 0.7 if selected else 0.4
    color = QColor(color)
    color.setAlpha(255 * alpha)  # Set alpha to half for display
    return color