Ejemplo n.º 1
0
    def reset(self, template):
        self.distances = None
        self.walls = None
        self.template = template
        self.x = 0
        self.y = 0
        self.direction = 0

        self.picture = QtGui.QPicture()
        self.position_picture = QtGui.QPicture()

        self.generateTemplate()
        self.update()
Ejemplo n.º 2
0
 def __init__(self):
     pg.GraphicsObject.__init__(self)
     #self.lastbar = None
     # self.picture = QtGui.QPicture()
     self.picturemain = QtGui.QPicture()  #主K線圖
     self.picturelast = QtGui.QPicture()  #最後一根K線圖
     self.pictures = []
     self.setFlag(self.ItemUsesExtendedStyleOption)
     self.rect = None
     self.low = 0
     self.high = 0
     self.timelist = []
     self.countK = 60  #設定要顯示多少K線
Ejemplo n.º 3
0
 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()
Ejemplo n.º 4
0
    def generatePicture(self):

        self.picture = QtGui.QPicture()
        p = QtGui.QPainter(self.picture)
        p.setPen(pg.mkPen('w'))
        p = self._generate(p)
        p.end()
Ejemplo n.º 5
0
 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()
Ejemplo n.º 6
0
    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()
Ejemplo n.º 7
0
    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()
Ejemplo n.º 8
0
 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()
Ejemplo n.º 9
0
 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)
Ejemplo n.º 10
0
 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
Ejemplo n.º 12
0
    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()
Ejemplo n.º 13
0
 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()
Ejemplo n.º 14
0
 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()
Ejemplo n.º 15
0
 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()
Ejemplo n.º 18
0
    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()
Ejemplo n.º 19
0
 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()
Ejemplo n.º 20
0
 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()
Ejemplo n.º 21
0
 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()
Ejemplo n.º 22
0
    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()
Ejemplo n.º 23
0
 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()
Ejemplo n.º 24
0
    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
Ejemplo n.º 25
0
 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()
Ejemplo n.º 26
0
    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()
Ejemplo n.º 27
0
 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
Ejemplo n.º 29
0
    def updateData(self):
        self.picture = QtGui.QPicture()
        p = QtGui.QPainter(self.picture)

        for x, y, df, step, alpha in self.data:
            p.setPen(pg.mkPen(63, 63, 63, alpha))
            p.setBrush(pg.mkBrush(63, 63, 63, alpha))
            p.drawRect(QtCore.QRectF(x[0], y[1], x[1] - x[0], y[0] - y[1]))

            x_length = x[1] - x[0]
            x_pos = minmax_scale(df.to_numpy(), (0.1 * x_length, x_length / 2))
            for interval, width in zip(df.index, x_pos):
                p.setBrush(pg.mkBrush(0, 255, 0, alpha))
                p.drawRect(QtCore.QRectF(x[0], interval.left, width[0], step))

                p.setBrush(pg.mkBrush(255, 0, 0, alpha))
                p.drawRect(
                    QtCore.QRectF(x[0] + width[0], interval.left, width[1],
                                  step))

        p.end()
        self.update()
    def _get_candles_chart(self):
        """Return QPicture() with candlestick chart by self._data"""
        picture = QtGui.QPicture()
        pen = QtGui.QPainter(picture)
        pen.setPen(pg.mkPen(self.border_color, width=2))
        width = 1 / 3.
        for ind, candle in enumerate(self._data):
            # Warning. if you paint line x -> y if x == y, then on pyqtgraph will paint white rectangle (bug?)
            if candle[1] != candle[2]:
                # paint shadow
                pen.drawLine(QtCore.QPointF(ind, candle[2]),
                             QtCore.QPointF(ind, candle[1]))

            if candle[0] > candle[3]:
                pen.setBrush(pg.mkBrush(self.negative_color))
            else:
                pen.setBrush(pg.mkBrush(self.positive_color))
            # paint body
            pen.drawRect(
                QtCore.QRectF(ind - width, candle[0], width * 2,
                              candle[3] - candle[0]))
        pen.end()
        return picture