예제 #1
0
    def paintEvent(self, e):
        Part.paintEvent(self, e)
        painter = QPainter(self)
        color = QColor(self._base.dark(150))
        color.setAlpha(150)
        painter.setPen(color)
        painter.pen().setWidth(2)
        painter.drawPolyline(*tuple(self._SYNTH_POINTS))
        
        if not self.songpart is None and self.activeLED.isHidden():
            color = QColor('black')
            color.setAlpha(200)
            painter.setPen(color)
            rect = QRect(0, 5, self.width() - 5, self.height() - 5)
            painter.drawText(rect,
                             Qt.AlignRight | Qt.AlignTop,
                             '[%s]' % self.songpart)

        painter.setPen(self._base.light(150))
        painter.pen().setWidth(self.margin)
        y = self.height() - self.margin
        synth = self.data
        for start, stop in self.paintNotes:
            ratio = 1 - ((stop - synth.localclock.time()) / (stop - start))
            if ratio > 0 and ratio <= 1:
                width = (self.width() - self.margin * 2) * ratio
                painter.drawLine(self.margin, y, width, y)
                y -= (self.margin + 3)

        painter = None
        self.drawText()
예제 #2
0
 def paintEvent(self, e):
     Part.paintEvent(self, e)
     painter = QPainter(self)
     color = QColor(self._base.dark(150))
     color.setAlpha(150)
     painter.setPen(color)
     painter.pen().setWidth(2)
     painter.drawPolyline(*tuple(self._SYNTH_POINTS))
     painter = None
     self.drawText()
예제 #3
0
    def drawSkel(self, worm_img, worm_qimg, row_data, roi_corner=(0, 0)):
        if not self.skel_file or not isinstance(self.trajectories_data,
                                                pd.DataFrame):
            return

        c_ratio_y = worm_qimg.width() / worm_img.shape[1]
        c_ratio_x = worm_qimg.height() / worm_img.shape[0]

        skel_id = int(row_data['skeleton_id'])

        qPlg = {}

        with tables.File(self.skel_file, 'r') as ske_file_id:
            for tt in ['skeleton', 'contour_side1', 'contour_side2']:
                dat = ske_file_id.get_node('/' + tt)[skel_id]
                dat[:, 0] = (dat[:, 0] - roi_corner[0]) * c_ratio_x
                dat[:, 1] = (dat[:, 1] - roi_corner[1]) * c_ratio_y

                qPlg[tt] = QPolygonF()
                for p in dat:
                    qPlg[tt].append(QPointF(*p))

        if 'is_good_skel' in row_data and row_data['is_good_skel'] == 0:
            self.skel_colors = {
                'skeleton': (102, 0, 0),
                'contour_side1': (102, 0, 0),
                'contour_side2': (102, 0, 0)
            }
        else:
            self.skel_colors = {
                'skeleton': (27, 158, 119),
                'contour_side1': (217, 95, 2),
                'contour_side2': (231, 41, 138)
            }

        pen = QPen()
        pen.setWidth(2)

        painter = QPainter()
        painter.begin(worm_qimg)

        for tt, color in self.skel_colors.items():
            pen.setColor(QColor(*color))
            painter.setPen(pen)
            painter.drawPolyline(qPlg[tt])

        pen.setColor(Qt.black)
        painter.setBrush(Qt.white)
        painter.setPen(pen)

        radius = 3
        painter.drawEllipse(qPlg['skeleton'][0], radius, radius)

        painter.end()
예제 #4
0
    def paintEvent(self, event):

        # -------------------------------------------------------------------
        Painter = QPainter()
        Painter.begin(self)
        
        # -------------------------------------------------------------------
        # Draw CROSS-MOUSE-POS
        if self.DRAW_CROSS:

            Painter.setPen( QPen( QColor(255,255,255, 255), 1, Qt.DashLine ) );
            Painter.drawPolyline( QPoint(self.MOUSE_X-600, self.MOUSE_Y), QPoint( self.MOUSE_X+600, self.MOUSE_Y) ); 
            Painter.drawPolyline( QPoint(self.MOUSE_X, self.MOUSE_Y-400), QPoint( self.MOUSE_X, self.MOUSE_Y+400) ); 

        # -------------------------------------------------------------------
        Painter.end();
    def drawSkel(self, worm_img, worm_qimg, row_data, roi_corner = (0,0)):
        if not self.skel_file or not isinstance(self.trajectories_data, pd.DataFrame):
            return

        c_ratio_y = worm_qimg.width()/worm_img.shape[1];
        c_ratio_x = worm_qimg.height()/worm_img.shape[0];
        
        skel_id = int(row_data['skeleton_id'])

        qPlg = {}

        with tables.File(self.skel_file, 'r') as ske_file_id:
            for tt in ['skeleton', 'contour_side1', 'contour_side2']:
                dat = ske_file_id.get_node('/' + tt)[skel_id];
                dat[:,0] = (dat[:,0]-roi_corner[0])*c_ratio_x
                dat[:,1] = (dat[:,1]-roi_corner[1])*c_ratio_y
            
                qPlg[tt] = QPolygonF()
                for p in dat:
                    qPlg[tt].append(QPointF(*p))
        
        if 'is_good_skel' in row_data and row_data['is_good_skel'] == 0:
            self.skel_colors = {'skeleton':(102, 0, 0 ), 
            'contour_side1':(102, 0, 0 ), 'contour_side2':(102, 0, 0 )}
        else:
            self.skel_colors = {'skeleton':(27, 158, 119 ), 
            'contour_side1':(217, 95, 2), 'contour_side2':(231, 41, 138)}

        pen = QPen()
        pen.setWidth(2)
        
        painter = QPainter()
        painter.begin(worm_qimg)
    
        for tt, color in self.skel_colors.items():
            pen.setColor(QColor(*color))
            painter.setPen(pen)
            painter.drawPolyline(qPlg[tt])
        
        pen.setColor(Qt.black)
        painter.setBrush(Qt.white)
        painter.setPen(pen)
    
        radius = 3
        painter.drawEllipse(qPlg['skeleton'][0], radius, radius)

        painter.end()
예제 #6
0
    def paintEvent(self, event):

        # -------------------------------------------------------------------
        Painter = QPainter()
        Painter.begin(self)

        # -------------------------------------------------------------------
        # Draw CROSS-MOUSE-POS
        if self.DRAW_CROSS:

            Painter.setPen(QPen(QColor(255, 255, 255, 255), 1, Qt.DashLine))
            Painter.drawPolyline(QPoint(self.MOUSE_X - 600, self.MOUSE_Y),
                                 QPoint(self.MOUSE_X + 600, self.MOUSE_Y))
            Painter.drawPolyline(QPoint(self.MOUSE_X, self.MOUSE_Y - 400),
                                 QPoint(self.MOUSE_X, self.MOUSE_Y + 400))

        # -------------------------------------------------------------------
        Painter.end()
예제 #7
0
 def updateColor(self, item):
    pixmap = QPixmap(16, 16)
    color = QColor()
    if item:
       color = item.backgroundColor()
    if not color.isValid():
       color = self.palette().base().color()
    painter = QPainter(pixmap)
    painter.fillRect(0, 0, 16, 16, color)
    lighter = color.lighter()
    painter.setPen(lighter)
    # light frame
    painter.drawPolyline(QPoint(0, 15), QPoint(0, 0), QPoint(15, 0))
    painter.setPen(color.darker())
    # dark frame
    painter.drawPolyline(QPoint(1, 15), QPoint(15, 15), QPoint(15, 1))
    painter.end()
    self.colorAction.setIcon(QIcon(pixmap))
	def paintEvent(self, event = None):
		
		LogicalSize = 100.0

		def logicalFromPhysical(length, side):
			return (length / side) * LogicalSize

		fm = QFontMetricsF(self.font())
		ymargin = ((LogicalSize / 30.0) + logicalFromPhysical(self.leftSpinBox.height(), self.height()))
		ymax = (LogicalSize - logicalFromPhysical(fm.height() * 2, self.height()))
		width = LogicalSize / 4.0
		
		cx, cy = LogicalSize / 2.0, LogicalSize / 3.0
		ax, ay = cx - (2 * width), ymargin
		bx, by = cx - width, ay
		dx, dy = cx + width, ay
		ex, ey = cx + (2 * width), ymargin
		fx, fy = cx + (width / 2), cx + (LogicalSize / 24.0)
		gx, gy = fx, ymax
		hx, hy = cx - (width / 2), ymax
		ix, iy = hx, fy

		painter = QPainter(self)
		painter.setRenderHint(QPainter.Antialiasing)
		side = min(self.width(), self.height())
		painter.setViewport((self.width() - side) / 2, (self.height() - side) / 2, side, side)
		painter.setWindow(0, 0, LogicalSize, LogicalSize)

		painter.setPen(Qt.NoPen)

		gradient = QLinearGradient(QPointF(0, 0), QPointF(0, 100))
		gradient.setColorAt(0, Qt.white)
		a = self.leftSpinBox.value()
		gradient.setColorAt(1, (Qt.red if a != 0 else Qt.white))
		painter.setBrush(QBrush(gradient))
		painter.drawPolygon(QPolygon([ax, ay, bx, by, cx, cy, ix, iy]))

		gradient = QLinearGradient(QPointF(0, 0), QPointF(0, 100))
		gradient.setColorAt(0, Qt.white)
		b = self.rightSpinBox.value()
		gradient.setColorAt(1, (Qt.blue if b != 0 else Qt.white))
		painter.setBrush(QBrush(gradient))
		painter.drawPolygon(QPolygon([cx, cy, dx, dy, ex, ey, fx, fy]))

		if (a + b) == 0:
			color = QColor(Qt.white)
		else:
			ashare = (a / (a + b)) * 255.0
			bshare = 255.0 - ashare
			color = QColor(ashare, 0, bshare)

		gradient = QLinearGradient(QPointF(0, 0), QPointF(0, 100))
		gradient.setColorAt(0, Qt.white)
		gradient.setColorAt(1, color)
		painter.setBrush(QBrush(gradient))
		painter.drawPolygon(QPolygon([cx, cy, fx, fy, gx, gy, hx, hy, ix, iy]))

		painter.setPen(Qt.black)
		painter.drawPolyline(QPolygon([ax, ay, ix, iy, hx, hy]))
		painter.drawPolyline(QPolygon([gx, gy, fx, fy, ex, ey]))
		painter.drawPolyline(QPolygon([bx, by, cx, cy, dx, dy]))
예제 #9
0
    def paintEvent(self, event=None):
        LogicalSize = 100.0

        def logicalFromPhysical(length, side):
            return (length / side) * LogicalSize

        fm = QFontMetricsF(self.font())
        ymargin = (
            (LogicalSize / 30.0) +
            logicalFromPhysical(self.leftSpinBox.height(), self.height()))
        ymax = (LogicalSize -
                logicalFromPhysical(fm.height() * 2, self.height()))
        width = LogicalSize / 4.0
        cx, cy = LogicalSize / 2.0, LogicalSize / 3.0
        ax, ay = cx - (2 * width), ymargin
        bx, by = cx - width, ay
        dx, dy = cx + width, ay
        ex, ey = cx + (2 * width), ymargin
        fx, fy = cx + (width / 2), cx + (LogicalSize / 24.0)
        gx, gy = fx, ymax
        hx, hy = cx - (width / 2), ymax
        ix, iy = hx, fy

        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)
        side = min(self.width(), self.height())
        painter.setViewport((self.width() - side) / 2,
                            (self.height() - side) / 2, side, side)
        painter.setWindow(0, 0, LogicalSize, LogicalSize)

        painter.setPen(Qt.NoPen)

        gradient = QLinearGradient(QPointF(0, 0), QPointF(0, 100))
        gradient.setColorAt(0, Qt.white)
        a = self.leftSpinBox.value()
        gradient.setColorAt(1, (Qt.red if a != 0 else Qt.white))
        painter.setBrush(QBrush(gradient))
        painter.drawPolygon(QPolygon([ax, ay, bx, by, cx, cy, ix, iy]))

        gradient = QLinearGradient(QPointF(0, 0), QPointF(0, 100))
        gradient.setColorAt(0, Qt.white)
        b = self.rightSpinBox.value()
        gradient.setColorAt(1, (Qt.blue if b != 0 else Qt.white))
        painter.setBrush(QBrush(gradient))
        painter.drawPolygon(QPolygon([cx, cy, dx, dy, ex, ey, fx, fy]))

        if (a + b) == 0:
            color = QColor(Qt.white)
        else:
            ashare = (a / (a + b)) * 255.0
            bshare = 255.0 - ashare
            color = QColor(ashare, 0, bshare)
        gradient = QLinearGradient(QPointF(0, 0), QPointF(0, 100))
        gradient.setColorAt(0, Qt.white)
        gradient.setColorAt(1, color)
        painter.setBrush(QBrush(gradient))
        painter.drawPolygon(QPolygon([cx, cy, fx, fy, gx, gy, hx, hy, ix, iy]))

        painter.setPen(Qt.black)
        painter.drawPolyline(QPolygon([ax, ay, ix, iy, hx, hy]))
        painter.drawPolyline(QPolygon([gx, gy, fx, fy, ex, ey]))
        painter.drawPolyline(QPolygon([bx, by, cx, cy, dx, dy]))
예제 #10
0
 def drawImage(self, imageid):
     cache = image_cache.cache
     cellColoring = self.cellColoring
     wallColoring = self.wallColoring
     pointColoring = self.pointColoring
     ellipsisDraw = self.ellipsisDraw
     overSampling = self.overSampling
     extraDrawing = self.extraDrawing
     bgColor = self.bgColor.rgb()
     result = self.result
     if self.result_type == "Data":
         data = result
         img_name = result.images_name[imageid]
     else:
         data = result.data
         img_name = result.images[imageid]
     #scale = data.images_scale[img_name]
     min_scale = data.minScale()
     img = cache.image(data.image_path(img_name))
     img_data = data[img_name]
     size = self._crop.size()
     pix = QImage(size*overSampling, QImage.Format_ARGB32)
     pix.fill(bgColor)
     painter = QPainter()
     if not painter.begin(pix):
         self.abort("Cannot create painter on QImage")
         return None, None, None
     painter.setRenderHints(QPainter.SmoothPixmapTransform, True)
     painter.setRenderHints(QPainter.Antialiasing, True)
     if overSampling > 1:
         painter.scale(overSampling, overSampling)
     painter.translate(-self._crop.topLeft())
     painter.save()
     painter.translate(self.translate)
     log_debug("Translating: %gx%g" % (self.translate.x(), self.translate.y()) )
     painter.scale(1/min_scale, 1/min_scale)
     painter.save()
     matrix = img_data.matrix()
     painter.setWorldTransform(matrix, True)
     painter.drawImage(QPoint(0,0), img)
     painter.restore()
     #pt_matrix = QTransform()
     #pt_matrix.scale(1/min_scale, 1/min_scale)
     #painter.setTransform(pt_matrix, True)
     cellColoring.startImage(painter, imageid)
     wallColoring.startImage(painter, imageid)
     for ed in extraDrawing:
         ed.startImage(painter, imageid)
     if self.result_type == "Growth":
         cells = result.cells[imageid]
         walls = result.walls[imageid]
     else:
         cells = img_data.cells
         walls = set()
         for cid in img_data.cells:
             pts = [ pt for pt in data.cells[cid] if pt in img_data ]
             if len(pts) > 1:
                 for i in range(len(pts)):
                     walls.add(data.wallId(pts[i-1], pts[i]))
     # Now, draw the cells and the ellipsis
     for cid in cells:
         painter.setPen(Qt.NoPen)
         color = cellColoring(imageid, cid)
         painter.setBrush(color)
         pts = data.cellAtTime(cid, img_data.index)
         if pts:
             pts.append(pts[0])
             ppts = []
             for p1,p2 in zip(pts[:-1], pts[1:]):
                 ppts.append(img_data[p1])
                 ppts.extend(img_data.walls[p1,p2])
             ppts.append(ppts[0])
             poly = QPolygonF(ppts)
             painter.drawPolygon(poly)
     # And draw the walls
     wallThickness = self.wallThickness*min_scale
     for wid in walls:
         color = wallColoring(imageid, wid)
         if color.alpha() > 0:
             pen = QPen(color)
             pen.setWidthF(wallThickness)
             painter.setPen(pen)
             pts = [img_data[wid[0]]] + img_data.walls[wid[0], wid[1]] + [img_data[wid[1]]]
             #painter.drawLine(img_data[wid[0]], img_data[wid[1]])
             painter.drawPolyline(*pts)
     # Then, draw the points
     pointSize = self.pointSize*min_scale
     pointLineColor = self.pointLineColor
     pointLineThickness = self.pointLineThickness*min_scale
     log_debug("pointSize = %g" % pointSize)
     for pid in img_data:
         color = pointColoring(imageid, pid)
         if color.alpha() > 0:
             pen = QPen(pointLineColor)
             pen.setWidthF(pointLineThickness)
             brush = QBrush(color)
             painter.setPen(pen)
             painter.setBrush(brush)
             pos = img_data[pid]
             rect = QRectF(pos.x()-pointSize, pos.y()-pointSize, 2*pointSize, 2*pointSize)
             painter.drawEllipse(rect)
     if ellipsisDraw.plot:
         for cid in cells:
             pts = data.cellAtTime(cid, img_data.index)
             if pts:
                 pts.append(pts[0])
                 ppts = []
                 for p1,p2 in zip(pts[:-1], pts[1:]):
                     ppts.append(img_data[p1])
                     ppts.extend(img_data.walls[p1,p2])
                 ppts.append(ppts[0])
                 #poly = QPolygonF(ppts)
                 #painter.drawPolygon(poly)
                 ellipsisDraw(painter, imageid, cid, ppts, min_scale)
     # At last, draw the extra data
     for ed in extraDrawing:
         ed(painter, imageid)
     tr = painter.worldTransform()
     painter.restore()
     pic_w = wallColoring.finalizeImage(painter, imageid, tr, self.crop)
     pic_c = cellColoring.finalizeImage(painter, imageid, tr, self.crop)
     for ed in extraDrawing:
         ed.finalizeImage(painter, imageid, tr, self.crop)
     painter.end()
     return pix, pic_w, pic_c
예제 #11
0
     QPen(QBrush(QColor(255, 0, 0, 255), Qt.SolidPattern), 5.0,
          Qt.SolidLine, Qt.SquareCap, Qt.MiterJoin))
 testpainter.drawRect(QRectF(5.0, 255.0, 240.0, 240.0))
 testpainter.setBrush(QBrush(QColor(0, 0, 255, 255), Qt.SolidPattern))
 testpainter.setPen(
     QPen(QBrush(QColor(0, 0, 0, 255), Qt.SolidPattern), 5.0, Qt.DashLine,
          Qt.RoundCap, Qt.RoundJoin))
 testpainter.drawPolygon(
     QPolygonF([
         QPointF(.25 * ptx, .25 * pty + 250) for (ptx, pty) in pentagonpts
     ]))
 testpainter.setBrush(Qt.NoBrush)
 testpainter.setPen(
     QPen(QBrush(QColor(255, 255, 255, 255), Qt.SolidPattern), 3.0,
          Qt.DashLine, Qt.RoundCap, Qt.RoundJoin))
 testpainter.drawPolyline(
     QPolygonF([QPointF(pts, pty) for (pts, pty) in linepts]))
 testpainter.end()
 # add the image command
 testimgwidth = testimage.width()
 testimgheight = testimage.height()
 testimgstride = testimage.bytesPerLine()
 # not a good way to get the pixel data
 testimgdata = bytearray(testimgheight * testimgstride)
 k = 0
 for pty in xrange(testimgheight):
     for ptx in xrange(testimgwidth):
         pixval = testimage.pixel(ptx, pty)
         (aval, rgbval) = divmod(pixval, 256 * 256 * 256)
         (rval, gbval) = divmod(rgbval, 256 * 256)
         (gval, bval) = divmod(gbval, 256)
         testimgdata[k] = bval
예제 #12
0
 def drawImage(self, imageid):
     cache = image_cache.cache
     cellColoring = self.cellColoring
     wallColoring = self.wallColoring
     pointColoring = self.pointColoring
     ellipsisDraw = self.ellipsisDraw
     overSampling = self.overSampling
     extraDrawing = self.extraDrawing
     bgColor = self.bgColor.rgb()
     result = self.result
     if self.result_type == "Data":
         data = result
         img_name = result.images_name[imageid]
     else:
         data = result.data
         img_name = result.images[imageid]
     #scale = data.images_scale[img_name]
     min_scale = data.minScale()
     img = cache.image(data.image_path(img_name))
     img_data = data[img_name]
     size = self._crop.size()
     pix = QImage(size * overSampling, QImage.Format_ARGB32)
     pix.fill(bgColor)
     painter = QPainter()
     if not painter.begin(pix):
         self.abort("Cannot create painter on QImage")
         return None, None, None
     painter.setRenderHints(QPainter.SmoothPixmapTransform, True)
     painter.setRenderHints(QPainter.Antialiasing, True)
     if overSampling > 1:
         painter.scale(overSampling, overSampling)
     painter.translate(-self._crop.topLeft())
     painter.save()
     painter.translate(self.translate)
     log_debug("Translating: %gx%g" %
               (self.translate.x(), self.translate.y()))
     painter.scale(1 / min_scale, 1 / min_scale)
     painter.save()
     matrix = img_data.matrix()
     painter.setWorldTransform(matrix, True)
     painter.drawImage(QPoint(0, 0), img)
     painter.restore()
     #pt_matrix = QTransform()
     #pt_matrix.scale(1/min_scale, 1/min_scale)
     #painter.setTransform(pt_matrix, True)
     cellColoring.startImage(painter, imageid)
     wallColoring.startImage(painter, imageid)
     for ed in extraDrawing:
         ed.startImage(painter, imageid)
     if self.result_type == "Growth":
         cells = result.cells[imageid]
         walls = result.walls[imageid]
     else:
         cells = img_data.cells
         walls = set()
         for cid in img_data.cells:
             pts = [pt for pt in data.cells[cid] if pt in img_data]
             if len(pts) > 1:
                 for i in range(len(pts)):
                     walls.add(data.wallId(pts[i - 1], pts[i]))
     # Now, draw the cells and the ellipsis
     for cid in cells:
         painter.setPen(Qt.NoPen)
         color = cellColoring(imageid, cid)
         painter.setBrush(color)
         pts = data.cellAtTime(cid, img_data.index)
         if pts:
             pts.append(pts[0])
             ppts = []
             for p1, p2 in zip(pts[:-1], pts[1:]):
                 ppts.append(img_data[p1])
                 ppts.extend(img_data.walls[p1, p2])
             ppts.append(ppts[0])
             poly = QPolygonF(ppts)
             painter.drawPolygon(poly)
     # And draw the walls
     wallThickness = self.wallThickness * min_scale
     for wid in walls:
         color = wallColoring(imageid, wid)
         if color.alpha() > 0:
             pen = QPen(color)
             pen.setWidthF(wallThickness)
             painter.setPen(pen)
             pts = [img_data[wid[0]]
                    ] + img_data.walls[wid[0], wid[1]] + [img_data[wid[1]]]
             #painter.drawLine(img_data[wid[0]], img_data[wid[1]])
             painter.drawPolyline(*pts)
     # Then, draw the points
     pointSize = self.pointSize * min_scale
     pointLineColor = self.pointLineColor
     pointLineThickness = self.pointLineThickness * min_scale
     log_debug("pointSize = %g" % pointSize)
     for pid in img_data:
         color = pointColoring(imageid, pid)
         if color.alpha() > 0:
             pen = QPen(pointLineColor)
             pen.setWidthF(pointLineThickness)
             brush = QBrush(color)
             painter.setPen(pen)
             painter.setBrush(brush)
             pos = img_data[pid]
             rect = QRectF(pos.x() - pointSize,
                           pos.y() - pointSize, 2 * pointSize,
                           2 * pointSize)
             painter.drawEllipse(rect)
     if ellipsisDraw.plot:
         for cid in cells:
             pts = data.cellAtTime(cid, img_data.index)
             if pts:
                 pts.append(pts[0])
                 ppts = []
                 for p1, p2 in zip(pts[:-1], pts[1:]):
                     ppts.append(img_data[p1])
                     ppts.extend(img_data.walls[p1, p2])
                 ppts.append(ppts[0])
                 #poly = QPolygonF(ppts)
                 #painter.drawPolygon(poly)
                 ellipsisDraw(painter, imageid, cid, ppts, min_scale)
     # At last, draw the extra data
     for ed in extraDrawing:
         ed(painter, imageid)
     tr = painter.worldTransform()
     painter.restore()
     pic_w = wallColoring.finalizeImage(painter, imageid, tr, self.crop)
     pic_c = cellColoring.finalizeImage(painter, imageid, tr, self.crop)
     for ed in extraDrawing:
         ed.finalizeImage(painter, imageid, tr, self.crop)
     painter.end()
     return pix, pic_w, pic_c
예제 #13
-37
 def paintEvent(self, event):
     QWidget.paintEvent(self, event)
     width, height = self.width(), self.height()
     polygon = QPolygon()
     for i, rate in enumerate(self.loads):
         x = width - i * self.pointDistance
         y = height - rate * height
         if x < self.boxWidth:
             break
         polygon.append(QPoint(x, y))
     painter = QPainter(self)
     pen = QPen()
     pen.setColor(Qt.darkGreen)
     painter.setPen(pen)
     painter.setRenderHint(QPainter.Antialiasing, True)
     #画网格
     painter.setOpacity(0.5)
     gridSize = self.pointDistance * 4
     deltaX = (width - self.boxWidth) % gridSize + self.boxWidth
     deltaY = height % gridSize
     for i in range(int(width / gridSize)):
         x = deltaX + gridSize * i
         painter.drawLine(x, 0, x, height)
     for j in range(int(height / gridSize)):
         y = j * gridSize + deltaY
         painter.drawLine(self.boxWidth, y, width, y)
     #画折线
     pen.setColor(Qt.darkCyan)
     pen.setWidth(2)
     painter.setPen(pen)
     painter.setOpacity(1)
     painter.drawPolyline(polygon)
     #画展示框
     if len(self.loads) > 0:
         rate = self.loads[0]
     else:
         rate = 1.0
     rect1 = QRect(4, height * 0.05, self.boxWidth - 9, height * 0.7)
     rect2 = QRect(4, height * 0.8, self.boxWidth - 9, height * 0.2)
     centerX = int(rect1.width() / 2) + 1
     pen.setWidth(1)
     for i in range(rect1.height()):
         if i % 4 == 0:
             continue
         if (rect1.height() - i) / rect1.height() > rate:
             pen.setColor(Qt.darkGreen)
         else:
             pen.setColor(Qt.green)
         painter.setPen(pen)
         for j in range(rect1.width()):
             if centerX - 1 <= j <= centerX + 1:
                 continue
             painter.drawPoint(rect1.x() + j, rect1.y() + i)
     pen.setColor(Qt.black)
     painter.setPen(pen)
     painter.drawText(rect2, Qt.AlignHCenter | Qt.AlignVCenter, str(int(rate * 100)) + "%")