コード例 #1
1
ファイル: led_editor.py プロジェクト: UManPychron/pychron
    def init(self, parent):
        '''

        '''
        if self.control is None:
            self.control = qtLED()
            scene = QGraphicsScene()
            #             self.control.setStyleSheet("qtLED { border-style: none; }");
            #             self.control.setAutoFillBackground(True)

            # system background color
            scene.setBackgroundBrush(QBrush(QColor(237, 237, 237)))
            self.control.setStyleSheet("border: 0px")
            self.control.setMaximumWidth(35)
            self.control.setMaximumHeight(35)

            x, y = 10, 10
            rad = 20
            cx = x + rad / 1.75
            cy = y + rad / 1.75

            brush = self.get_color(self.value.state, cx, cy, rad / 2)
            pen = QPen()
            pen.setWidth(0)
            self.led = scene.addEllipse(x, y, rad, rad,
                                        pen=pen,
                                        brush=brush
            )

            self.control.setScene(scene)

            self.value.on_trait_change(self.update_object, 'state')
コード例 #2
0
ファイル: lines_chart.py プロジェクト: wiz21b/koi
    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)
コード例 #3
0
 def paintEvent(self, pe):
   painter = QPainter(self)
   painter.save()
   gradient = QLinearGradient()
   gradient.setStart(self._grad_start)
   gradient.setFinalStop(self._grad_end)
   gradient.setColorAt(0, QColor(230, 230, 230))
   gradient.setColorAt(1, QColor(247, 247, 247))
   brush = QBrush(gradient)
   painter.setBrush(brush)
   pen = QPen(Qt.black)
   pen.setWidth(1)
   painter.setPen(pen)
   painter.drawPath(self._painter_path)
   painter.restore()
   font = QFont()
   font.setFamily("Tahoma")
   font.setPixelSize(11)
   font.setBold(True)
   pen = QPen(Qt.darkGray)
   painter.setPen(pen)
   painter.setFont(font)
   self_rect = QRect(self.rect())
   self_rect.moveTo(self._hor_margin, self._ver_margin // 2)
   painter.drawText(self_rect, Qt.AlignLeft, self._text)
コード例 #4
0
    def _draw_edges(self, painter, topleft_point, bottomright_point):

        for edge in self._edges:
            edge_coords = edge.coordinates

            color = QColor(0x70, 0x70, 0x70)
            pen = QPen(color)
            pen.setWidth(1.5)
            painter.setPen(pen)

            for from_, to_ in zip(edge_coords, edge_coords[1:]):
                start_point = QPointF(*from_)
                end_point = QPointF(*to_)
                # optimization: don't draw edges that are outside of the current scope
                if (start_point.x() > bottomright_point.x() or start_point.y() > bottomright_point.y()) and \
                        (end_point.x() > bottomright_point.x() or end_point.y() > bottomright_point.y()):
                    continue
                elif (start_point.x() < topleft_point.x() or start_point.y() < topleft_point.y()) and \
                        (end_point.x() < topleft_point.x() or end_point.y() < topleft_point.y()):
                    continue
                painter.drawPolyline((start_point, end_point))

            # arrow
            # end_point = self.mapToScene(*edges[-1])
            end_point = (edge_coords[-1][0], edge_coords[-1][1])
            arrow = [
                QPointF(end_point[0] - 3, end_point[1]),
                QPointF(end_point[0] + 3, end_point[1]),
                QPointF(end_point[0], end_point[1] + 6)
            ]
            brush = QBrush(color)
            painter.setBrush(brush)
            painter.drawPolygon(arrow)
コード例 #5
0
ファイル: led_editor.py プロジェクト: waffle-iron/pychron
    def init(self, parent):
        """
        """
        rad = self.factory.radius
        if not rad:
            rad = 20

        if self.control is None:
            self.control = qtLED()
            scene = QGraphicsScene()
            #             self.control.setStyleSheet("qtLED { border-style: none; }");
            #             self.control.setAutoFillBackground(True)

            # system background color
            scene.setBackgroundBrush(QBrush(QColor(237, 237, 237)))
            self.control.setStyleSheet("border: 0px")
            self.control.setMaximumWidth(rad+15)
            self.control.setMaximumHeight(rad+15)

            x, y = 10, 10
            cx = x + rad / 1.75
            cy = y + rad / 1.75

            brush = self.get_color(self.value.state, cx, cy, rad / 2)
            pen = QPen()
            pen.setWidth(0)
            self.led = scene.addEllipse(x, y, rad, rad,
                                        pen=pen,
                                        brush=brush
                                        )

            self.control.setScene(scene)

            self.value.on_trait_change(self.update_object, 'state')
コード例 #6
0
    def paint(self, canvas, is_secondary_color=False, additional_flag=False):
        pen = QPen()
        pen.setWidth(self.data_singleton.pen_size)
        pen.setStyle(Qt.SolidLine)
        pen.setCapStyle(Qt.RoundCap)
        pen.setJoinStyle(Qt.RoundJoin)

        if is_secondary_color:
            pen.setBrush(self.data_singleton.secondary_color)
        else:
            pen.setBrush(self.data_singleton.primary_color)

        painter = QPainter(canvas.image)
        painter.setPen(pen)

        if self._start_point != self._end_point:
            painter.drawLine(self._start_point, self._end_point)

        if self._start_point == self._end_point:
            painter.drawPoint(self._start_point)

        painter.end()

        canvas.edited = True
        canvas.update()
コード例 #7
0
	def paintEvent(self, ev):
		if self.isEnabled():
			color = self.color
			colorBorder = [0.4, 0.4, 0.4]
		else:
			color = [0.8, 0.8, 0.8]
			colorBorder = [0.7, 0.7, 0.7]

		painter = QPainter(self)
		painter.setRenderHint(QPainter.Antialiasing)
		painter.setRenderHint(QPainter.HighQualityAntialiasing)

		if self.isChecked():
			pen = QPen(QColor.fromRgbF(0.2, 0.2, 0.2))
			pen.setWidth(2.0)
		else:
			pen = QPen(QColor.fromRgbF(colorBorder[0], colorBorder[1], colorBorder[2]))
			pen.setWidth(1.0)

		size = self.size()
		sizeCircle = 12.0
		x = size.width() / 2.0 - (sizeCircle / 2.0)
		y = size.height() / 2.0 - (sizeCircle / 2.0)
		rect = QRectF(x, y, sizeCircle, sizeCircle)
		painter.setPen(pen)
		painter.setBrush(QColor.fromRgbF(color[0], color[1], color[2]))
		painter.drawEllipse(rect)
コード例 #8
0
ファイル: lines_chart.py プロジェクト: wiz21b/koi
    def _draw_serie(self, painter, ndx_serie, color):

        serie = self.data[ndx_serie]

        if not serie:
            return

        qp = QPainterPath()
        # qp.addRect(2,2,total_width-4,total_height-4)

        x = float(0) * self.x_factor
        y = serie[0] * self.y_factor
        qp.moveTo(self.x_centers[0],self.y_base - y)
        # print y_base

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

            qp.lineTo(self.x_centers[i], self.y_base-y)

        pen = QPen()
        pen.setColor(color)

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

        painter.setPen(pen)
        painter.drawPath(qp)
コード例 #9
0
    def paintEvent(self, ev):
        if self.isEnabled():
            color = self.color
            colorBorder = [0.4, 0.4, 0.4]
        else:
            color = [0.8, 0.8, 0.8]
            colorBorder = [0.7, 0.7, 0.7]

        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setRenderHint(QPainter.HighQualityAntialiasing)

        if self.isChecked():
            pen = QPen(QColor.fromRgbF(0.2, 0.2, 0.2))
            pen.setWidth(2.0)
        else:
            pen = QPen(
                QColor.fromRgbF(colorBorder[0], colorBorder[1],
                                colorBorder[2]))
            pen.setWidth(1.0)

        size = self.size()
        sizeCircle = 12.0
        x = size.width() / 2.0 - (sizeCircle / 2.0)
        y = size.height() / 2.0 - (sizeCircle / 2.0)
        rect = QRectF(x, y, sizeCircle, sizeCircle)
        painter.setPen(pen)
        painter.setBrush(QColor.fromRgbF(color[0], color[1], color[2]))
        painter.drawEllipse(rect)
コード例 #10
0
    def paint(self, canvas, is_secondary_color=False, additional_flag=False):
        pen = QPen()

        if is_secondary_color:
            pen.setColor(self.data_singleton.secondary_color)
        else:
            pen.setColor(self.data_singleton.primary_color)

        painter = QPainter(canvas.image)
        painter.setRenderHint(QPainter.Antialiasing)
        pen.setWidth(self.data_singleton.pen_size)
        pen.setStyle(Qt.SolidLine)
        pen.setCapStyle(Qt.RoundCap)
        pen.setJoinStyle(Qt.RoundJoin)

        painter.setPen(pen)

        if is_secondary_color:
            painter.setBrush(self.data_singleton.primary_color)
        else:
            painter.setBrush(self.data_singleton.secondary_color)

        if self._start_point != self._end_point:
            painter.drawRect(QRect(self._start_point, self._end_point))

        painter.end()

        canvas.edited = True
        canvas.update()
コード例 #11
0
ファイル: noise_dialog.py プロジェクト: d42/Fourierism
        def p(painter, color):
            device = painter.device()
            width, height = device.width(), device.height()
            painter.setRenderHint(QPainter.Antialiasing)
            pen = QPen()
            pen.setWidth(thickness)
            if random:
                pen.setBrush(noise_brush)
            painter.setPen(pen)
            painter.setOpacity(opacity / 100)

            def getpoints(x, y):
                if angle in [0, 180]:
                    return (0, y), (width, y)
                if angle in [90, 270]:
                    return (x, 0), (x, height)
                derp = max(height, width)
                deg = math.radians(angle)
                p1 = (x - derp * math.cos(deg), y + derp * math.sin(deg))
                p2 = (x + derp * math.cos(deg), y - derp * math.sin(deg))
                return p1, p2

            for pos in range(spacing + thickness, max(height, width),
                             spacing + thickness):
                x = pos if angle < 90 else width - pos
                y = pos
                (x1, y1), (x2, y2) = getpoints(x, y)
                painter.drawLine(x1, y1, x2, y2)
            return
コード例 #12
0
 def paintEvent(self, pe):
     painter = QPainter(self)
     painter.save()
     gradient = QLinearGradient()
     gradient.setStart(self._grad_start)
     gradient.setFinalStop(self._grad_end)
     gradient.setColorAt(0, QColor(230, 230, 230))
     gradient.setColorAt(1, QColor(247, 247, 247))
     brush = QBrush(gradient)
     painter.setBrush(brush)
     pen = QPen(Qt.black)
     pen.setWidth(1)
     painter.setPen(pen)
     painter.drawPath(self._painter_path)
     painter.restore()
     font = QFont()
     font.setFamily("Tahoma")
     font.setPixelSize(11)
     font.setBold(True)
     pen = QPen(Qt.darkGray)
     painter.setPen(pen)
     painter.setFont(font)
     self_rect = QRect(self.rect())
     self_rect.moveTo(self._hor_margin, self._ver_margin // 2)
     painter.drawText(self_rect, Qt.AlignLeft, self._text)
コード例 #13
0
class EdgeWidget(QWidget):
    def __init__(self, parent=None, conditional=False):
        if conditional:
            self.pen = QPen(CONDITIONAL_TRANSITION_COLOR)
            self.brush = QBrush(CONDITIONAL_TRANSITION_COLOR)
        else:
            self.pen = QPen(NON_CONDITIONAL_TRANSITION_COLOR)
            self.brush = QBrush(NON_CONDITIONAL_TRANSITION_COLOR)

        self.pen.setWidth(4)
        QWidget.__init__(self, parent)

    def paintEvent(self, event):
        painter = QPainter(self)
        painter.setBrush(self.brush)
        painter.setPen(self.pen)
        painter.setRenderHint(QPainter.Antialiasing)
        rect = self.geometry()
        from_point = QPointF(0, rect.height() / 2)
        to_point = QPointF(rect.width(), rect.height() / 2)
        # from_point = QPointF(0, 0)
        # to_point = QPointF(rect.width(), rect.height())

        # noinspection PyProtectedMember
        ClassyEdge._draw_arrow(painter, from_point, to_point, 10)
コード例 #14
0
    def paintEvent(self, pe):
        p = QPainter(self)
        p.setRenderHint(QPainter.Antialiasing)

        pen = QPen()
        pen.setColor(Qt.GlobalColor.black)
        pen.setWidth(2)
        pen.setJoinStyle(Qt.MiterJoin)
        p.setPen(pen)

        h = self.associated_label.sizeHint().height()
        w = h
        pw = pen.width()

        b = self.italic_block(pw+0,w,h)
        p.translate(self.shadow_size,self.shadow_size)
        p.fillPath(b, QBrush(Qt.gray))
        p.translate(-self.shadow_size,-self.shadow_size)
        p.fillPath(b, QBrush(self.Colors[self.step]))
        p.drawPath(b)
        b = self.italic_block(pw+w*1.25,w*0.75,h)
        p.translate(self.shadow_size,self.shadow_size)
        p.fillPath(b, QBrush(Qt.gray))
        p.translate(-self.shadow_size,-self.shadow_size)
        p.fillPath(b, QBrush(self.Colors[self.step+1]))
        p.drawPath(b)
        b = self.italic_block(pw+w*2.25,w*0.4,h)
        p.translate(self.shadow_size,self.shadow_size)
        p.fillPath(b, QBrush(Qt.gray))
        p.translate(-self.shadow_size,-self.shadow_size)
        p.fillPath(b, QBrush(self.Colors[self.step+2]))
        p.drawPath(b)
コード例 #15
0
ファイル: noise_dialog.py プロジェクト: d42/Fourierism
        def p(painter, color):
            device = painter.device()
            width, height = device.width(), device.height()
            painter.setRenderHint(QPainter.Antialiasing)
            pen = QPen()
            pen.setWidth(thickness)
            if random:
                pen.setBrush(noise_brush)
            painter.setPen(pen)
            painter.setOpacity(opacity/100)

            def getpoints(x, y):
                if angle in [0, 180]:
                    return (0, y), (width, y)
                if angle in [90, 270]:
                    return (x, 0), (x, height)
                derp = max(height, width)
                deg = math.radians(angle)
                p1 = (x - derp*math.cos(deg), y + derp * math.sin(deg))
                p2 = (x+derp*math.cos(deg), y - derp * math.sin(deg))
                return p1, p2


            for pos in range(spacing+thickness, max(height, width), spacing+thickness):
                x = pos if angle < 90 else width-pos
                y = pos
                (x1, y1), (x2, y2) = getpoints(x, y)
                painter.drawLine(x1, y1, x2, y2)
            return
コード例 #16
0
 def paintEvent(self, pe):
   if not self._hover_rect:
     super(TrackerWebView, self).paintEvent(pe)
   else:
     super(TrackerWebView, self).paintEvent(pe)
     hover_rect = self._hover_rect
     self._fixRectForScroll(hover_rect)
     painter = QPainter(self)
     painter.save()
     pen = QPen(Qt.red)
     pen.setWidth(2)
     painter.setPen(pen)
     painter.drawRect(hover_rect)
     painter.restore()
     # draw green rects around the similar elements
     pen = QPen()
     pen.setWidth(2)
     for field_info in self._fields_info:
       painter.save()
       web_elements = field_info.web_elements
       color = field_info.color
       pen.setColor(color)
       painter.setPen(pen)
       for elem in web_elements:
         elem_rect = elem.absoluteGeometry()
         painter.drawRoundedRect(self._fixRectForScroll(elem_rect), 2, 2)
       painter.restore()
コード例 #17
0
ファイル: support.py プロジェクト: realmhamdy/VisualScrape
 def paintEvent(self, pe):
   # make an arrow polygon right in the middle
   painter = QPainter(self)
   painter.setPen(Qt.NoPen)
   # draw the background transparent rect
   painter.save()
   painter.setOpacity(self.BACKGROUND_OPACITY)
   # get the rectangle coordinates it should extend over the whole width with only a portion at the center
   painter.setBrush(Qt.black)
   empty_space_percent = 1 - self.BACKROUND_HEIGHT_PERCENT
   rect_top = empty_space_percent / 2 * self.height()
   rect_height = self.BACKROUND_HEIGHT_PERCENT * self.height()
   painter.drawRect(0, rect_top, self.width(), rect_height)
   painter.restore()
   painter.setRenderHint(QPainter.Antialiasing)
   pen = QPen()
   pen.setWidth(self.ARROW_LINE_WIDTH)
   pen.setCapStyle(Qt.RoundCap)
   if self._mouse_inside:
     pen.setColor(self._hover_color)
   else:
     pen.setColor(self._normal_color)
   # get the arrow coords
   painter.setPen(pen)
   self_center = QPointF(self.width() / 2, self.height() / 2) # use this as the arrow tip for now
   if self._direction == self.LEFT:
     h_shift = self._arrow_width
   elif self._direction == self.RIGHT:
     h_shift = - self._arrow_width
   v_shift = self._arrow_height / 2
   top_point = self_center + QPointF(h_shift, - v_shift)
   bottom_point = self_center + QPointF(h_shift, v_shift)
   painter.drawLine(top_point, self_center)
   painter.drawLine(self_center, bottom_point)
コード例 #18
0
ファイル: lines_chart.py プロジェクト: wiz21b/koi
    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)
コード例 #19
0
 def setChosen(self, ch):
     self.chosen = ch
     if ch:
         redPen = QPen(Qt.red)
         redPen.setWidth(2)
         self.setPen(redPen)
     else:
         self.setPen(QPen())
コード例 #20
0
ファイル: lines_chart.py プロジェクト: wiz21b/koi
    def draw_no_data(self, painter):
        text_pen = QPen()
        text_pen.setCapStyle(Qt.RoundCap)
        text_pen.setColor(QColor(128, 128, 128)) # alpha=255=fully opaque
        text_pen.setWidth(1)
        painter.setPen(text_pen)

        painter.setFont(self.title_font)
        r = QRect( self.margin, 0, self.width() - 2*self.margin, self.height())
        painter.drawText(r, (Qt.AlignCenter | Qt.AlignLeft) + Qt.TextWordWrap, _("No data"))
コード例 #21
0
ファイル: stacked_lines_chart.py プロジェクト: wiz21b/koi
    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)
コード例 #22
0
    def drawPolyline(self):
        path = [mark.coordinate() for mark in self.markerObjects]

        pen = QPen(Qt.white)
        pen.setWidth(2)
        pen.setCosmetic(True)
        polyline = QGeoMapPolylineObject()
        polyline.setPen(pen)
        polyline.setPath(path)

        self.mapWidget.addMapObject(polyline)
コード例 #23
0
ファイル: lines_chart.py プロジェクト: wiz21b/koi
    def draw_title(self, painter):
        text_pen = QPen()
        text_pen.setCapStyle(Qt.RoundCap)
        text_pen.setColor(QColor(255, 255, 255)) # alpha=255=fully opaque
        text_pen.setWidth(1)
        painter.setPen(text_pen)

        painter.setFont(self.title_font)

        r = QRect(self.margin,0,self.width() - 2*self.margin,self.height())
        painter.drawText(r, Qt.AlignLeft + Qt.TextWordWrap, self.title)
コード例 #24
0
    def init(self, parent):
        """
        """
        rad = self.factory.radius
        if not rad:
            rad = 20

        if self.control is None:

            ctrl = qtLED()
            layout = QVBoxLayout()

            layout.addWidget(ctrl)

            scene = QGraphicsScene()
            #             ctrl.setStyleSheet("qtLED { border-style: none; }");
            #             ctrl.setAutoFillBackground(True)

            # system background color
            scene.setBackgroundBrush(QBrush(QColor(237, 237, 237)))
            ctrl.setStyleSheet("border: 0px")
            ctrl.setMaximumWidth(rad + 15)
            ctrl.setMaximumHeight(rad + 15)

            x, y = 10, 10
            cx = x + rad / 1.75
            cy = y + rad / 1.75

            brush = self.get_color(self.value.state, cx, cy, rad / 2)
            pen = QPen()
            pen.setWidth(0)
            self.led = scene.addEllipse(x, y, rad, rad,
                                        pen=pen,
                                        brush=brush)

            if self.factory.label:
                txt = QLabel(self.factory.label)
                layout.addWidget(txt)
                layout.setAlignment(txt, Qt.AlignHCenter)
                # txt = scene.addText(self.factory.label, QFont('arial 6'))
                # txt.setPos(cx, 10)

            ctrl.setScene(scene)

            layout.setAlignment(ctrl, Qt.AlignHCenter)

            self.value.on_trait_change(self.update_object, 'state')

            self.control = QWidget()
            self.control.setLayout(layout)
コード例 #25
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)
コード例 #26
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)
コード例 #27
0
    def _draw_edges(self, painter, topleft_point, bottomright_point):

        # draw edges
        if self._edges:
            for edge in self._edges:
                edge_coords = edge.coordinates

                if edge.sort == EdgeSort.BACK_EDGE:
                    # it's a back edge
                    # Honey
                    color = QColor(0xf9, 0xd5, 0x77)
                elif edge.sort == EdgeSort.TRUE_BRANCH:
                    # True branch
                    # Aqar
                    color = QColor(0x79, 0xcc, 0xcd)
                elif edge.sort == EdgeSort.FALSE_BRANCH:
                    # False branch
                    # Tomato
                    color = QColor(0xf1, 0x66, 0x64)
                else:
                    # Dark Gray
                    color = QColor(0x56, 0x5a, 0x5c)
                pen = QPen(color)
                pen.setWidth(2)
                painter.setPen(pen)

                for from_, to_ in zip(edge_coords, edge_coords[1:]):
                    start_point = QPointF(*from_)
                    end_point = QPointF(*to_)
                    # optimization: don't draw edges that are outside of the current scope
                    if (start_point.x() > bottomright_point.x() or start_point.y() > bottomright_point.y()) and \
                            (end_point.x() > bottomright_point.x() or end_point.y() > bottomright_point.y()):
                        continue
                    elif (start_point.x() < topleft_point.x() or start_point.y() < topleft_point.y()) and \
                            (end_point.x() < topleft_point.x() or end_point.y() < topleft_point.y()):
                        continue
                    painter.drawPolyline((start_point, end_point))

                # arrow
                # end_point = self.mapToScene(*edges[-1])
                end_point = (edge_coords[-1][0], edge_coords[-1][1])
                arrow = [
                    QPointF(end_point[0] - 3, end_point[1]),
                    QPointF(end_point[0] + 3, end_point[1]),
                    QPointF(end_point[0], end_point[1] + 6)
                ]
                brush = QBrush(color)
                painter.setBrush(brush)
                painter.drawPolygon(arrow)
コード例 #28
0
ファイル: WinViewer.py プロジェクト: benoxoft/seagoatvision-1
    def draw_widget(self, qp):
        size = self.size()
        radx = size.width()
        rady = size.height()
        dot = min(radx, rady) / 2

        pen = QPen()
        pen.setWidth(dot)
        # pen.setStyle(Qt.SolidLine)
        pen.setBrush(self.color)
        # pen.setCapStyle(Qt.RoundCap)
        # pen.setJoinStyle(Qt.RoundJoin)
        qp.setPen(pen)

        qp.drawLine(dot, dot, dot, dot)
コード例 #29
0
    def drawWidget(self, qp):
        size = self.size()
        radx = size.width()
        rady = size.height()
        dot = min(radx, rady) / 2

        pen = QPen()
        pen.setWidth(dot)
        # pen.setStyle(Qt.SolidLine)
        pen.setBrush(self.color)
        # pen.setCapStyle(Qt.RoundCap)
        # pen.setJoinStyle(Qt.RoundJoin)
        qp.setPen(pen)

        qp.drawLine(dot, dot, dot, dot)
コード例 #30
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)
コード例 #31
0
ファイル: led_editor.py プロジェクト: stephen-e-cox/pychron
    def init(self, parent):
        """
        """
        rad = self.factory.radius
        if not rad:
            rad = 20

        if self.control is None:

            ctrl = qtLED()
            layout = QVBoxLayout()

            layout.addWidget(ctrl)

            scene = QGraphicsScene()
            #             ctrl.setStyleSheet("qtLED { border-style: none; }");
            #             ctrl.setAutoFillBackground(True)

            # system background color
            scene.setBackgroundBrush(QBrush(QColor(237, 237, 237)))
            ctrl.setStyleSheet("border: 0px")
            ctrl.setMaximumWidth(rad + 15)
            ctrl.setMaximumHeight(rad + 15)

            x, y = 10, 10
            cx = x + rad / 1.75
            cy = y + rad / 1.75

            brush = self.get_color(self.value.state, cx, cy, rad / 2)
            pen = QPen()
            pen.setWidth(0)
            self.led = scene.addEllipse(x, y, rad, rad, pen=pen, brush=brush)

            if self.factory.label:
                txt = QLabel(self.factory.label)
                layout.addWidget(txt)
                layout.setAlignment(txt, Qt.AlignHCenter)
                # txt = scene.addText(self.factory.label, QFont('arial 6'))
                # txt.setPos(cx, 10)

            ctrl.setScene(scene)

            layout.setAlignment(ctrl, Qt.AlignHCenter)

            self.value.on_trait_change(self.update_object, 'state')

            self.control = QWidget()
            self.control.setLayout(layout)
コード例 #32
0
 def draw_uvs(self):
     self.img = QPixmap(QSize(self.w, self.h))
     pen = QPen()
     pen.setWidth(int(self.pen_w.text()))
     pen.setBrush(QBrush(Qt.white))
     pen.setColor(QColor('white'))
     painter = QPainter()
     painter.begin(self.img)
     painter.setPen(pen)
     coords = self.get_coords()
     for face in coords:
         for n in xrange(len(face) - 1):
             print face[n][0], face[n][1], face[n + 1][0], face[n + 1][1]
             painter.drawLine(face[n][0], face[n][1], face[n + 1][0], face[n + 1][1])
     painter.end()
     self.view.scene().addPixmap(self.img)
コード例 #33
0
ファイル: cachemap.py プロジェクト: juhanaj/Cacher
 def setRoute(self, route):
     t = route.strip("{}")
     cs = t.split(";")
     path = list()
     for c in cs:
         c = c.strip("()")
         latitude = c[0:c.rfind(",")]
         longitude = c[c.rfind(",")+1:len(c)]
         path.append(QGeoCoordinate(float(latitude), float(longitude)))
     self.route = QGeoRoute()
     self.route.setPath(path)
     self.route_object = QGeoMapPolylineObject()
     self.route_object.setPath(path)
     pen = QPen(QtCore.Qt.red)
     pen.setWidth(5)
     self.route_object.setPen(pen)
     self.route_object.setZValue(1)
     self.addMapObject(self.route_object)
コード例 #34
0
ファイル: lines_chart.py プロジェクト: wiz21b/koi
    def _draw_y_axis(self,painter, y_base, width, height, steps):

        text_pen = QPen()
        text_pen.setCapStyle(Qt.RoundCap)
        text_pen.setColor(QColor(200, 200, 200)) # alpha=255=fully opaque
        text_pen.setWidth(1)
        painter.setPen(text_pen)


        if self.rounded_step_size < 1:
            fmt = "{:.1f}"
        else:
            fmt = "{:.0f}"

        if self.rounded_step_size > 0:
            for i in range(int(self.maxi / self.rounded_step_size) + 1):

                y = y_base - self.rounded_step_size * i * self.y_factor
                painter.drawText(self.margin,y, fmt.format(self.rounded_step_size * i))
コード例 #35
0
    def paintEvent(self, pe):
        if self.left_view and self.right_view and self.right_view.model():
            vr = self.left_view.visualRect(self.left_view.currentIndex())

            self.left_top = self.mapFromGlobal(
                self.left_view.viewport().mapToGlobal(vr.topRight())).y()
            self.left_bottom = self.mapFromGlobal(
                self.left_view.viewport().mapToGlobal(vr.bottomRight())).y()

            vr_top = self.right_view.visualRect(self.right_view.model().index(
                0, 0))
            vr = self.right_view.visualRect(self.right_view.model().index(
                self.right_view.model().rowCount() - 1, 0))

            self.right_top = self.mapFromGlobal(
                self.left_view.viewport().mapToGlobal(vr_top.topLeft())).y()
            self.right_bottom = self.mapFromGlobal(
                self.left_view.viewport().mapToGlobal(vr.bottomLeft())).y()

            w = self.minimumWidth() - 1

            p = QPainter(self)
            p.setBrush(QBrush(QColor(210, 255, 210)))

            pen = QPen()
            pen.setColor(Qt.transparent)
            p.setPen(pen)

            poly = QPolygon()
            poly.append(QPoint(0, self.left_top))
            poly.append(QPoint(w, self.right_top))
            poly.append(QPoint(w, self.right_bottom))
            poly.append(QPoint(0, self.left_bottom))
            p.drawConvexPolygon(poly)

            p.setRenderHint(QPainter.Antialiasing)
            pen.setColor(Qt.GlobalColor.black)
            pen.setWidth(2)
            p.setPen(pen)
            p.drawLine(0, self.left_top, w, self.right_top)
            p.drawLine(0, self.left_bottom, w, self.right_bottom)
コード例 #36
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)
コード例 #37
0
 def paintEvent(self, pe):
   painter = QPainter(self)
   painter.save()
   background = QColor(55, 55, 55)
   brush = QBrush(background)
   painter.setOpacity(self._opacity)
   painter.setBrush(brush)
   painter.setPen(Qt.NoPen)
   painter.drawRect(self.rect())
   painter.restore()
   # draw a bottom border
   painter.setPen(Qt.black)
   painter.drawLine(0, self.height(), self.width(), self.height())
   # now the text
   pen = QPen(Qt.white)
   pen.setWidth(16)
   painter.setPen(pen)
   painter.setFont(QFont("Trebuchet MS", 16, QFont.Bold))
   text_rect = QRect(self.rect())
   text_rect.adjust(self._margin, self._margin, self._margin, self._margin)
   painter.drawText(text_rect, Qt.AlignLeft, self._message_str)
コード例 #38
0
ファイル: painting.py プロジェクト: xkronosua/snippets
    def paintEvent(self, evt):
        # create a painter
        with paint(self) as painter:
            # adjust the width of the pen
            pen = QPen()
            pen.setWidth(5)
            painter.setPen(pen)
            # enable high quality antialiasing
            painter.setRenderHint(QPainter.Antialiasing)
            painter.setRenderHint(QPainter.HighQualityAntialiasing)
            # move the center of the coordinate system to the widgets center
            painter.translate(self.width() / 2, self.height() / 2)
            # rotate the coordinate system by the given angle
            painter.rotate(self.angle)
            # draw the spiral
            painter.drawPolyline(self.spiral)
            # end painting and free resources

        # update the angle
        self.angle += 30
        self.angle %= 360
コード例 #39
0
ファイル: material.py プロジェクト: ethanhs/material
 def paintEvent(self, event):
     painter = QPainter()
     painter.begin(self)
     painter.setRenderHint(QPainter.HighQualityAntialiasing)
     painter.setRenderHint(QPainter.Antialiasing)
     painter.setRenderHint(QPainter.SmoothPixmapTransform)
     self.img = QPixmap()
     if self.isChecked():
         painter.setBrush(self.color1)
         painter.drawRoundedRect(QRect(-1, -1, 31, 31), 7, 7)
         painter.drawPixmap(QRect(-2, -5, 35, 40), self.img.fromImage(self.check))
     else:
         pen = QPen()
         pen.setWidth(2)
         painter.setPen(pen)
         # hand draw rect
         painter.drawLine(QPoint(0, 0), QPoint(30, 0))
         painter.drawLine(QPoint(30, 0), QPoint(30, 30))
         painter.drawLine(QPoint(0, 0), QPoint(0, 30))
         painter.drawLine(QPoint(0, 30), QPoint(30, 30))
     painter.end()
コード例 #40
0
ファイル: material.py プロジェクト: xuyi2008yi/material
 def paintEvent(self, event):
     painter = QPainter()
     painter.begin(self)
     painter.setRenderHint(QPainter.HighQualityAntialiasing)
     painter.setRenderHint(QPainter.Antialiasing)
     painter.setRenderHint(QPainter.SmoothPixmapTransform)
     self.img = QPixmap()
     if self.isChecked():
         painter.setBrush(self.color1)
         painter.drawRoundedRect(QRect(-1, -1, 31, 31), 7, 7)
         painter.drawPixmap(QRect(-2, -5, 35, 40),
                            self.img.fromImage(self.check))
     else:
         pen = QPen()
         pen.setWidth(2)
         painter.setPen(pen)
         # hand draw rect
         painter.drawLine(QPoint(0, 0), QPoint(30, 0))
         painter.drawLine(QPoint(30, 0), QPoint(30, 30))
         painter.drawLine(QPoint(0, 0), QPoint(0, 30))
         painter.drawLine(QPoint(0, 30), QPoint(30, 30))
     painter.end()
コード例 #41
0
 def paintEvent(self, pe):
     painter = QPainter(self)
     painter.save()
     background = QColor(55, 55, 55)
     brush = QBrush(background)
     painter.setOpacity(self._opacity)
     painter.setBrush(brush)
     painter.setPen(Qt.NoPen)
     painter.drawRect(self.rect())
     painter.restore()
     # draw a bottom border
     painter.setPen(Qt.black)
     painter.drawLine(0, self.height(), self.width(), self.height())
     # now the text
     pen = QPen(Qt.white)
     pen.setWidth(16)
     painter.setPen(pen)
     painter.setFont(QFont("Trebuchet MS", 16, QFont.Bold))
     text_rect = QRect(self.rect())
     text_rect.adjust(self._margin, self._margin, self._margin,
                      self._margin)
     painter.drawText(text_rect, Qt.AlignLeft, self._message_str)
コード例 #42
0
ファイル: bars_chart.py プロジェクト: wiz21b/koi
    def _draw_peak_values(self, painter, labels):
        #mainlog.debug('_draw_peak_values : {}'.format(labels))
        text_pen = QPen()
        text_pen.setCapStyle(Qt.RoundCap)
        text_pen.setColor(Qt.GlobalColor.white) # alpha=255=fully opaque
        text_pen.setWidth(1)
        fm = painter.fontMetrics()

        rects = []

        painter.setPen(text_pen)

        # The sort allow to draw the peak values which are lower first.
        # We do that to visually connect a peak value to its bar in a
        # (hopefully) better way

        for i in sorted( range(len(labels)), key=lambda i:self._item_coordinates(i)[1]):
            x, y_top, y_below = self._item_coordinates(i)

            label = labels[i]

            w = fm.boundingRect(label).width()
            h = fm.boundingRect(label).height()

            r = QRect(self.x_centers[i] - int(w/2), self.y_base-y_top - 5 - h, w, h)

            i = 0
            while i < len(rects):
                old_r = rects[i]
                if r.intersect(old_r):
                    i = 0
                    # Move r atop old_r
                    r.translate(0, -(r.bottom() - old_r.y()) - 2)
                else:
                    i += 1
            rects.append(r)

            self._draw_box_under_text(painter, r.x(), r.y() + h,label)
            painter.drawText( r.x(), r.y() + h,label)
コード例 #43
0
ファイル: mapviewer.py プロジェクト: AmerGit/Examples
    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)