Пример #1
0
    def paintEvent(self, e):
        """
        Draw to the Agg backend and then copy the image to the qt.drawable.
        In Qt, all drawing should be done inside of here when a widget is
        shown onscreen.
        """

        FigureCanvasQT.paintEvent(self, e)
        if DEBUG:            print 'FigureCanvasQtAgg.paintEvent: ', self, \
     self.get_width_height()

        p = qt.QPainter(self)

        # only replot data when needed
        if type(self.replot) is bool:  # might be a bbox for blitting
            if self.replot:
                FigureCanvasAgg.draw(self)
                #stringBuffer = str( self.buffer_rgba(0,0) )

                # matplotlib is in rgba byte order.
                # qImage wants to put the bytes into argb format and
                # is in a 4 byte unsigned int.  little endian system is LSB first
                # and expects the bytes in reverse order (bgra).
                if (qt.QImage.systemByteOrder() == qt.QImage.LittleEndian):
                    stringBuffer = self.renderer._renderer.tostring_bgra()
                else:
                    stringBuffer = self.renderer._renderer.tostring_argb()

                qImage = qt.QImage(stringBuffer, self.renderer.width,
                                   self.renderer.height, 32, None, 0,
                                   qt.QImage.IgnoreEndian)

                self.pixmap.convertFromImage(qImage, qt.QPixmap.Color)

            p.drawPixmap(qt.QPoint(0, 0), self.pixmap)

            # draw the zoom rectangle to the QPainter
            if (self.drawRect):
                p.setPen(qt.QPen(qt.Qt.black, 1, qt.Qt.DotLine))
                p.drawRect(self.rect[0], self.rect[1], self.rect[2],
                           self.rect[3])

        # we are blitting here
        else:
            bbox = self.replot
            l, t = int(bbox.ll().x().get()), int(bbox.ur().y().get())
            r, b = int(bbox.ur().x().get()), int(bbox.ll().y().get())
            w = r - l
            h = t - b
            reg = self.copy_from_bbox(bbox)
            stringBuffer = reg.to_string_argb()
            qImage = qt.QImage(stringBuffer, w, h, 32, None, 0,
                               qt.QImage.IgnoreEndian)
            self.pixmap.convertFromImage(qImage, qt.QPixmap.Color)
            p.drawPixmap(qt.QPoint(l, self.renderer.height - t), self.pixmap)

        p.end()
        self.replot = False
        self.drawRect = False
Пример #2
0
 def __init__( self, figure ):
     if DEBUG: print 'FigureCanvasQtAgg: ', figure
     FigureCanvasQT.__init__( self, figure )
     FigureCanvasAgg.__init__( self, figure )
     self.drawRect = False
     self.rect = []
     self.replot = True
     self.pixmap = qt.QPixmap()
Пример #3
0
 def __init__( self, figure ):
     if DEBUG: print 'FigureCanvasQtAgg: ', figure
     FigureCanvasQT.__init__( self, figure )
     FigureCanvasAgg.__init__( self, figure )
     self.drawRect = False
     self.rect = []
     self.replot = True
     self.pixmap = qt.QPixmap()
Пример #4
0
    def paintEvent( self, e ):
        """
        Draw to the Agg backend and then copy the image to the qt.drawable.
        In Qt, all drawing should be done inside of here when a widget is
        shown onscreen.
        """

        FigureCanvasQT.paintEvent( self, e )
        if DEBUG: print 'FigureCanvasQtAgg.paintEvent: ', self, \
           self.get_width_height()

        p = qt.QPainter( self )

        # only replot data when needed
        if type(self.replot) is bool: # might be a bbox for blitting
            if self.replot:
                FigureCanvasAgg.draw( self )
                #stringBuffer = str( self.buffer_rgba(0,0) )

                # matplotlib is in rgba byte order.
                # qImage wants to put the bytes into argb format and
                # is in a 4 byte unsigned int.  little endian system is LSB first
                # and expects the bytes in reverse order (bgra).
                if ( qt.QImage.systemByteOrder() == qt.QImage.LittleEndian ):
                    stringBuffer = self.renderer._renderer.tostring_bgra()
                else:
                    stringBuffer = self.renderer._renderer.tostring_argb()

                qImage = qt.QImage( stringBuffer, self.renderer.width,
                                    self.renderer.height, 32, None, 0,
                                    qt.QImage.IgnoreEndian )

                self.pixmap.convertFromImage( qImage, qt.QPixmap.Color )

            p.drawPixmap( qt.QPoint( 0, 0 ), self.pixmap )

            # draw the zoom rectangle to the QPainter
            if ( self.drawRect ):
                p.setPen( qt.QPen( qt.Qt.black, 1, qt.Qt.DotLine ) )
                p.drawRect( self.rect[0], self.rect[1], self.rect[2], self.rect[3] )

        # we are blitting here
        else:
            bbox = self.replot
            l, t = int(bbox.ll().x().get()), int(bbox.ur().y().get())
            r, b = int(bbox.ur().x().get()), int(bbox.ll().y().get())
            w = r - l
            h = t - b
            reg = self.copy_from_bbox(bbox)
            stringBuffer = reg.to_string_argb()
            qImage = qt.QImage(stringBuffer, w, h, 32, None, 0, qt.QImage.IgnoreEndian)
            self.pixmap.convertFromImage(qImage, qt.QPixmap.Color)
            p.drawPixmap(qt.QPoint(l, self.renderer.height-t), self.pixmap)

        p.end()
        self.replot = False
        self.drawRect = False
Пример #5
0
 def resizeEvent( self, e ):
     FigureCanvasQT.resizeEvent( self, e )
     w = e.size().width()
     h = e.size().height()
     if DEBUG: print "FigureCanvasQtAgg.resizeEvent(", w, ",", h, ")"
     dpival = self.figure.dpi.get()
     winch = w/dpival
     hinch = h/dpival
     self.figure.set_figsize_inches( winch, hinch )
     self.draw()
Пример #6
0
 def resizeEvent( self, e ):
     FigureCanvasQT.resizeEvent( self, e )
     w = e.size().width()
     h = e.size().height()
     if DEBUG: print "FigureCanvasQtAgg.resizeEvent(", w, ",", h, ")"
     dpival = self.figure.dpi.get()
     winch = w/dpival
     hinch = h/dpival
     self.figure.set_size_inches( winch, hinch )
     self.draw()
Пример #7
0
 def paintEvent( self, e ):
     """
     Draw to the Agg backend and then copy the image to the qt.drawable.
     In Qt, all drawing should be done inside of here when a widget is
     shown onscreen.
     """
     FigureCanvasQT.paintEvent( self, e )
     if DEBUG: print 'FigureCanvasQtAgg.paintEvent: ', self, \
        self.get_width_height()
     p = qt.QPainter( self )
     if type(self.replot) is bool: # might be a bbox for blitting
         if self.replot:
             FigureCanvasAgg.draw( self )
             if ( qt.QImage.systemByteOrder() == qt.QImage.LittleEndian ):
                 stringBuffer = self.renderer._renderer.tostring_bgra()
             else:
                 stringBuffer = self.renderer._renderer.tostring_argb()
             qImage = qt.QImage( stringBuffer, self.renderer.width,
                                 self.renderer.height, 32, None, 0,
                                 qt.QImage.IgnoreEndian )
             self.pixmap.convertFromImage( qImage, qt.QPixmap.Color )
         p.drawPixmap( qt.QPoint( 0, 0 ), self.pixmap )
         if ( self.drawRect ):
             p.setPen( qt.QPen( qt.Qt.black, 1, qt.Qt.DotLine ) )
             p.drawRect( self.rect[0], self.rect[1], self.rect[2], self.rect[3] )
     else:
         bbox = self.replot
         l, b, r, t = bbox.extents
         w = int(r) - int(l)
         h = int(t) - int(b)
         reg = self.copy_from_bbox(bbox)
         stringBuffer = reg.to_string_argb()
         qImage = qt.QImage(stringBuffer, w, h, 32, None, 0, qt.QImage.IgnoreEndian)
         self.pixmap.convertFromImage(qImage, qt.QPixmap.Color)
         p.drawPixmap(qt.QPoint(l, self.renderer.height-t), self.pixmap)
     p.end()
     self.replot = False
     self.drawRect = False
Пример #8
0
 def resizeEvent( self, e ):
     FigureCanvasQT.resizeEvent( self, e )
Пример #9
0
 def resizeEvent( self, e ):
     FigureCanvasQT.resizeEvent( self, e )