def generatePicture(self): self.picture = QtGui.QPicture() painter = QtGui.QPainter(self.picture) painter.setFont(QtGui.QFont('times', 50)) painter.scale(1, -1) paint_discovered(painter, distances=self.distances, walls=self.walls) painter.end()
def paintEvent(self, event): painter = QtGui.QPainter(self) width = self.width() height = self.height() top, bottom = height * .1, height * .8 left, right = width * .1, width * .8 rect = QtCore.QRect(left, top, right, bottom) painter.fillRect(rect, QtGui.QColor('black')) #painter.setWindow(rect) dist = bottom - top relval = self.threshold.signal.buffer[-1] / self.MAX relval = min(1.0, relval) reltop = (1.0 - relval) * bottom + top relbottom = height * 0.9 - reltop rect = QtCore.QRect(left, reltop, right, relbottom) color = QtGui.QColor( 'green' if self.threshold.passfail.buffer[-1] else 'red') painter.fillRect(rect, color) thr_height = self.threshold.threshold / self.MAX thr_top = (1.0 - thr_height) * bottom + top rect = QtCore.QRect(left, thr_top, right, 2) painter.fillRect(rect, QtGui.QColor('white'))
def generatePicture(self): ## pre-computing a QPicture object allows paint() to run much more quickly, ## rather than re-drawing the shapes every time. global last_pf self.picture = QtGui.QPicture() p = QtGui.QPainter(self.picture) w = 1.0/3 #(self.data[1][0] - self.data[0][0]) / 3. #last_pf = self.data[0][2] first = True for (t, open, close, min, max, pf) in self.data: if open > close: #p.setBrush(pg.mkBrush('g')) p.setPen(pg.mkPen('g')) elif open < close: #p.setBrush(pg.mkBrush('r')) p.setPen(pg.mkPen('r')) else: p.setPen(pg.mkPen('w')) if min < max: p.drawLine(QtCore.QPointF(t, min), QtCore.QPointF(t, max)) p.drawRect(QtCore.QRectF(t-w, open, w*2, close-open)) p.setPen(pg.mkPen('y', width=1.5, style=QtCore.Qt.DashLine)) if not first: p.drawLine(QtCore.QPointF(t-1, last_pf), QtCore.QPointF(t, pf)) first = False last_pf = pf p.end()
def generatePicture(self): # pre-computing a QPicture object allows paint() to run much more quickly, # rather than re-drawing the shapes every time. self.picture = QtGui.QPicture() p = QtGui.QPainter(self.picture) for bi in self.data: if bi.biType == 'up': p.setPen(pg.mkPen('r')) p.drawLine( QtCore.QPointF( chan.chanBars[bi.barIndex1].closeIndex, chan.lowBar[chan.chanBars[bi.barIndex1].closeIndex]), QtCore.QPointF( chan.chanBars[bi.barIndex2].closeIndex, chan.highBar[chan.chanBars[bi.barIndex2].closeIndex])) else: p.setPen(pg.mkPen('g')) p.drawLine( QtCore.QPointF( chan.chanBars[bi.barIndex1].closeIndex, chan.highBar[chan.chanBars[bi.barIndex1].closeIndex]), QtCore.QPointF( chan.chanBars[bi.barIndex2].closeIndex, chan.lowBar[chan.chanBars[bi.barIndex2].closeIndex])) p.end()
def generatePicture(self): self.picture = QtGui.QPicture() p = QtGui.QPainter(self.picture) p.setPen(pg.mkPen('w')) p = self._generate(p) p.end()
def generatePicture(self): self.picture = QtGui.QPicture() p = QtGui.QPainter(self.picture) p.setPen(pg.mkPen('w', width=1 / 2.)) for (t, v) in self.data: p.drawLine(QtCore.QPointF(t, v - 2), QtCore.QPointF(t, v + 2)) p.end()
def generatePicture(self): ## pre-computing a QPicture object allows paint() to run much more quickly, ## rather than re-drawing the shapes every time. self.picture = QtGui.QPicture() p = QtGui.QPainter(self.picture) p.setPen(pg.mkPen('w')) # w = (self.data[1][0] - self.data[0][0]) / 3. x = self.xdat[:5] y = self.ydat[:5] self.path = pg.arrayToQPath(self.xdat, self.ydat, self.connect) # self.path = pg.arrayToQPath(np.array([0, 1, 1, 0, 3, 1]), np.array([0, 0, 1, 1, 3, 1])) p2 = QtGui.QPainterPath(self.path) p.fillPath(p2, pg.mkBrush((100, 100, 100))) # for (t, open, close, min, max) in self.data: # p.drawLine(QtCore.QPointF(t, min), QtCore.QPointF(t, max)) # self.path = pg.arrayToQPath(np.array([0, 1, 2, 1]), np.array([0, 0, 1, 1])) # # self.path = self.generatePath([0, 1, 2, 1], [0, 0, 1, 1]) # p2 = QtGui.QPainterPath(self.path) # p.fillPath(p2, pg.mkBrush((100, 100, 100))) # if open > close: # p.setBrush(pg.mkBrush('r')) # else: # p.setBrush(pg.mkBrush('g')) # p.drawRect(QtCore.QRectF(t - w, open, w * 2, close - open)) # p.drawPolygon(QtCore.) # p.drawLine(QtCore.QPointF(*pts[i][0]), QtCore.QPointF(*pts[i][1])) p.end()
def __init__(self, datasrc): super().__init__() self.datasrc = datasrc self.picture = QtGui.QPicture() self.painter = QtGui.QPainter() self.dirty = True # generate picture visibleRect = QtCore.QRectF(self.datasrc.init_x0, 0, self.datasrc.init_x1-self.datasrc.init_x0, 0) self._generate_picture(visibleRect)
def update_picture(self): self._picture = QtGui.QPicture() pen = QtGui.QPainter(self._picture) pen.setPen(pg.mkPen(self._border_color)) pen.setBrush(pg.mkBrush(self._color_bar)) width = 1 / 3. for ind, bar in enumerate(self._data): pen.drawRect(QtCore.QRectF(ind - width, 0, width * 2, bar[0])) pen.end() self.update()
def _get_line_chart(self): """Return QPicture() with line chart by self._data""" picture = QtGui.QPicture() pen = QtGui.QPainter(picture) pen.setPen(pg.mkPen(self.border_color)) for ind in range(0, len(self._data) - 1): pen.drawLine(QtCore.QPointF(ind, self._data[ind][3]), QtCore.QPointF(ind + 1, self._data[ind + 1][3])) pen.end() return picture
def generatePicture(self): """generatePicture(self) -> None generate items for box plot """ self.picture = QtGui.QPicture() self.p = QtGui.QPainter(self.picture) self.p.setPen(pg.mkPen('#FFFFFF')) for row in self.data: self.draw(row) self.p.end()
def get_repr_png_image(self): # put this in in the hope that it would apply the layout resizing # before converting to PNG. It still doesn't. So in notebook, have to # use separate cells QtGui.QApplication.processEvents() # Need to keep a reference to the image, otherwise Qt segfaults image = QtGui.QImage(self.viewRect().size().toSize(), QtGui.QImage.Format_RGB32) painter = QtGui.QPainter(image) self.render(painter) return image
def generatePicture(self): # pre-computing a QPicture object allows paint() to run much more quickly, # rather than re-drawing the shapes every time. self.picture = QtGui.QPicture() p = QtGui.QPainter(self.picture) p.setPen(pg.mkPen('w',width=15)) p.setPen(pg.mkColor("#FF0000")) p.setBrush(pg.mkBrush(None)) for i in self.data: p.drawPoint(i, chan.closeBar[i]) p.end()
def generatePicture(self): self.picture = QtGui.QPicture() p = QtGui.QPainter(self.picture) p.setPen(pg.mkPen('w')) w = (self.data[1][0] - self.data[0][0]) / 3. for (t, open, close, min, max) in self.data: p.drawLine(QtCore.QPointF(t, min), QtCore.QPointF(t, max)) if open > close: p.setBrush(pg.mkBrush('r')) else: p.setBrush(pg.mkBrush('g')) p.drawRect(QtCore.QRectF(t - w, open, w * 2, close - open)) p.end()
def generatePicture(self): # pre-computing a QPicture object allows paint() to run much more quickly, # rather than re-drawing the shapes every time. self.picture = QtGui.QPicture() p = QtGui.QPainter(self.picture) p.setPen(pg.mkPen('w')) p.setBrush(pg.mkBrush(None)) for zhongshu in self.data: p.drawRect(QtCore.QRectF(chan.chanBars[zhongshu.barIndex1].closeIndex, zhongshu.low, chan.chanBars[ zhongshu.barIndex2].closeIndex - chan.chanBars[zhongshu.barIndex1].closeIndex, zhongshu.high - zhongshu.low)) p.end()
def generatePicture(self): # pre-computing a QPicture object allows paint() to run much more quickly, # rather than re-drawing the shapes every time. self.picture = QtGui.QPicture() painter = QtGui.QPainter(self.picture) if self.grid: # 'k' seems to be black painter.setPen(pg.mkPen("k")) else: painter.setPen(pg.mkPen(None)) self.bmi_state.draw_picture(painter, self.headcolors) painter.end()
def generatePicture(self): ## pre-computing a QPicture object allows paint() to run much more quickly, ## rather than re-drawing the shapes every time. self.picture = QtGui.QPicture() p = QtGui.QPainter(self.picture) p.setPen(pg.mkPen('w')) for i in range(int(len(self.xdat) / 5)): print(self.xdat[i*5:(i+1) * 5], self.ydat[i*5:(i+1) * 5]) self.path = pg.arrayToQPath(self.xdat[i * 5:(i+1) * 5], self.ydat[i * 5:(i+1) * 5]) # self.path = pg.arrayToQPath(np.array([0, 1, 1, 0, 3, 1]), np.array([0, 0, 1, 1, 3, 1])) p2 = QtGui.QPainterPath(self.path) p.fillPath(p2, pg.mkBrush((100, 100, 10 + i * 10))) p.end()
def generatePicture(self): ## pre-computing a QPicture object allows paint() ## to run much more quickly, rather than ## re-drawing the shapes every time. self.picture = QtGui.QPicture() p = QtGui.QPainter(self.picture) #outline color p.setPen(pg.mkPen('w')) start_angle = int(-90 * 16) for (myfrac, mycolor) in self.slices: p.setBrush(pg.mkBrush(mycolor)) p.drawPie(self.boundingRect(), start_angle, int(myfrac * 360 * 16)) start_angle += int(myfrac * 360 * 16) p.end()
def generatePicture(self): """ Pre-compute a QPicture object to allow paint() to run much more quickly, :return: """ self.picture = QtGui.QPicture() p = QtGui.QPainter(self.picture) p.setPen(pg.mkPen('w')) for i in range(len(self.xdata)): path = pg.arrayToQPath(self.xdata[i], self.ydata[i]) p2 = QtGui.QPainterPath(path) p.fillPath(p2, pg.mkBrush((100, 100, 10 + i * 1))) p.end()
def generatePicture(self): self.picture = QtGui.QPicture() p = QtGui.QPainter(self.picture) p.setPen(pg.mkPen('#555555')) p.setBrush(pg.mkBrush(None)) # Posts for x, y in product((0, 1), (0, 1, 2)): p.drawRect(post(x * CELL_SIZE, y * CELL_SIZE)) # Vertical walls for x, y in product((0, 1), (0, 1)): p.drawRect(wall(x * CELL_SIZE, y * CELL_SIZE + WALL_WIDTH, True)) # Horizontal walls for i in range(3): p.drawRect(wall(WALL_WIDTH, i * CELL_SIZE)) p.end()
def generatePicture(self): ## pre-computing a QPicture object allows paint() to run much more quickly, ## rather than re-drawing the shapes every time. self.picture = QtGui.QPicture() p = QtGui.QPainter(self.picture) p.setPen(pg.mkPen('w')) w = (self.data[1][0] - self.data[0][0]) / 3. for (t, open, close, min, max) in self.data: p.drawLine(QtCore.QPointF(t, min), QtCore.QPointF(t, max)) if open > close: p.setBrush(pg.mkBrush('r')) else: p.setBrush(pg.mkBrush('g')) p.drawRect(QtCore.QRectF(t-w, open, w*2, close-open)) p.end()
def generatePicture(self): ## pre-computing a QPicture object allows paint() to run much more quickly, ## rather than re-drawing the shapes every time. self.picture = QtGui.QPicture() p = QtGui.QPainter(self.picture) p.setPen(pg.mkPen('w')) barWidth = (self.data[1][0] - self.data[0][0]) / 3. for (time, open, high, low, close) in self.data: p.drawLine(QtCore.QPointF(time, low), QtCore.QPointF(time, high)) if open > high: p.setBrush(pg.mkBrush('r')) else: p.setBrush(pg.mkBrush('g')) p.drawRect( QtCore.QRectF(time - barWidth, open, barWidth * 2, high - open)) p.end()
def generatePicture(self): """generatePicture(self) -> None generate items for candlesticks """ self.picture = QtGui.QPicture() self.p = QtGui.QPainter(self.picture) self.p.setPen(pg.mkPen('w')) if len(self.data.shape) == 1: self.draw(self.data) elif self.data.shape[0] == 1: self.draw(self.data[0]) else: w = (self.data[1][0] - self.data[0][0]) / 3. for row in self.data: self.draw(row, w) self.p.end()
def createCandlestick(self, isVolume, showTrendBars): if not self.isOHLC: return if isVolume and not self.hasVolume: return picture = self.candleStickPictures[isVolume][showTrendBars] if picture: return picture picture = QtGui.QPicture() p = QtGui.QPainter(picture) w = self.timeInterval / 3. for e in xrange(self.count()): t = self.plotTimes[e] open, high, low, close, volume = self.getOHLCV(e) upBar = close >= open if showTrendBars: upTrend = self.upTrend[e] color = 'cyan' if upTrend else 'red' else: color = OPEN_CLOSE_COLOR[upBar] color = color[0] p.setPen(pg.mkPen(color)) if showTrendBars and upTrend == upBar: p.setBrush(pg.mkBrush(color))# Solid body else: p.setBrush(pg.mkBrush('#000000'))# Make the body hollow if isVolume: y = 0. height = volume else: # Candlestick if low != high:# Weird long lines can happen on 5m Yahoo if the OHLC is all the same p.drawLine(QtCore.QPointF(t, low), QtCore.QPointF(t, high)) y = open height = close - open p.drawRect(QtCore.QRectF(t-w, y, w*2, height)) p.end() self.candleStickPictures[isVolume][showTrendBars] = picture return picture
def generatePicture(self): # pre-computing a QPicture object allows paint() to run much more quickly, # rather than re-drawing the shapes every time. self.picture = QtGui.QPicture() p = QtGui.QPainter(self.picture) p.setPen(pg.mkPen('w')) ################################################################################ w = (self.day2num(self.data[1][0]) - self.day2num(self.data[0][0])) / 3 ################################################################################ for (t, open, close, high, low, vol, code) in self.data: t = self.day2num(str(t)) p.drawLine(QtCore.QPointF(t, high), QtCore.QPointF(t, low)) if open > close: p.setBrush(pg.mkBrush('g')) else: p.setBrush(pg.mkBrush('r')) p.drawRect(QtCore.QRectF(t - w, open, w * 2, close - open)) p.end()
def setData(self, toclh): # toclh is a tuple of (time, open, close, min, max) self.data.append(toclh) p = QtGui.QPainter(self.picture) p.setPen(pg.mkPen('w')) w = 1. / 3. for (t, open, close, min, max) in self.data: p.drawLine(QtCore.QPointF(t, min), QtCore.QPointF(t, max)) if open > close: p.setBrush(pg.mkBrush('r')) else: p.setBrush(pg.mkBrush('g')) p.drawRect(QtCore.QRectF(t - w, open, w * 2, close - open)) p.end() self.update()
def generatePicture(self): """ Pre-compute a QPicture object to allow paint() to run much more quickly, :return: """ self.picture = QtGui.QPicture() p = QtGui.QPainter(self.picture) p.setPen(pg.mkPen(self.pen_col)) for i in range(len(self.xdata)): path = pg.arrayToQPath(self.xdata[i], self.ydata[i]) p2 = QtGui.QPainterPath(path) if self.brushes is None: brush = pg.mkBrush((100, 100, 10 + i * 1)) else: brush = self.brushes[i] p.fillPath(p2, brush) p.drawPath(p2) p.end()
def generatePicture(self): self.picture = QtGui.QPicture() p = QtGui.QPainter(self.picture) p.setBrush(pg.mkBrush(None)) # Mouse center p.setPen(pg.mkPen('b')) for i in range(4): p.drawLine( QtCore.QPointF(0, 0), QtCore.QPointF(cos(i * pi / 2) * 30, sin(i * pi / 2) * 30)) # Emitters p.setPen(pg.mkPen('#ffd70080')) for x, y, rotation in self.configuration['emitters']: for i in [1, 0, -1]: diff = i * self.configuration['half_emission_angle'] angle = radians(rotation + diff) p.drawLine( QtCore.QPointF(x, y), QtCore.QPointF(x + sin(angle) * 400, y + cos(angle) * 400)) p.end()
def _get_bar_chart(self): """Return QPicture() with bar chart by self._data""" picture = QtGui.QPicture() pen = QtGui.QPainter(picture) pen.setPen(pg.mkPen(self.border_color)) width = 1 / 3. for ind, candle in enumerate(self._data): if candle[0] > candle[3]: pen.setPen(pg.mkPen(self.negative_color, width=5)) else: pen.setPen(pg.mkPen(self.positive_color, width=5)) # Warning. if paint line x->y | x==y, then pyqtgraph will paint white rectangle (bug?) if candle[1] != candle[2]: pen.drawLine(QtCore.QPointF(ind, candle[2]), QtCore.QPointF(ind, candle[1])) pen.drawLine(QtCore.QPointF(ind - width, candle[0]), QtCore.QPointF(ind, candle[0])) pen.drawLine(QtCore.QPointF(ind, candle[3]), QtCore.QPointF(ind + width, candle[3])) pen.end() return picture
def get_repr_png_image(self): # Does non-OpenGL parts nicely, but OpenGL parts aren't rendered correctly # i.e. transparency doesn't work pixmap = QtGui.QPixmap.grabWidget(self) image = pixmap.toImage() # Calling paintGL removes overlays and mixes things up with multiple # QGLWidgets. Removed it - TODO thorough test # for w in self.findChildren(pg.Qt.QtOpenGL.QGLWidget): # w.paintGL() OpenGL.GL.glFlush() # Not sure if needed # Overwrite regions of image containing QGLWidgets painter = QtGui.QPainter(image) #n=0 for w in self.findChildren(pg.Qt.QtOpenGL.QGLWidget): w.makeOverlayCurrent() # needed for text produced by renderText w.makeCurrent() # don't know if needed but doesn't hurt subimage = w.grabFrameBuffer(True) #subimage.save('s%d.png'%n) painter.drawImage(w.pos(), subimage) #n+=1 painter.end() return image