Example #1
0
    def paintEvent(self, event):
        """QToolBar.paintEvent reimplementation
        Draws buttons, dock icon and text
        """
        rect = self._spacer.rect()

        painter = QPainter(self)

        transform = QTransform()
        transform.translate(self._spacer.pos().x(), self._spacer.pos().y())
        painter.setTransform(transform)
        """ Not supported currently
        if  self._dock.features() & QDockWidget.DockWidgetVerticalTitleBar :
            transform = QTransform()

            rect.setSize(QSize(rect.height(), rect.width()))
            transform.rotate(-90)
            transform.translate(-rect.width(), 0)

            painter.setTransform(transform)
        """

        # icon / title
        optionB = QStyleOptionButton()
        optionB.initFrom(self._dock)
        optionB.rect = rect
        optionB.text = self._dock.windowTitle()
        optionB.iconSize = self.iconSize()
        optionB.icon = self._dock.windowIcon()

        self.style().drawControl(QStyle.CE_PushButtonLabel, optionB, painter,
                                 self._dock)
Example #2
0
    def paintEvent(self, event ):
        """QToolBar.paintEvent reimplementation
        Draws buttons, dock icon and text
        """
        rect = self._spacer.rect()

        painter = QPainter( self )

        transform = QTransform()
        transform.translate(self._spacer.pos().x(), self._spacer.pos().y())
        painter.setTransform( transform )

        """ Not supported currently
        if  self._dock.features() & QDockWidget.DockWidgetVerticalTitleBar :
            transform = QTransform()

            rect.setSize( QSize( rect.height(), rect.width() ) )
            transform.rotate( -90 )
            transform.translate( -rect.width(), 0 )

            painter.setTransform( transform )
        """

        # icon / title
        optionB = QStyleOptionButton()
        optionB.initFrom( self._dock )
        optionB.rect = rect
        optionB.text = self._dock.windowTitle()
        optionB.iconSize = self.iconSize()
        optionB.icon = self._dock.windowIcon()

        self.style().drawControl( QStyle.CE_PushButtonLabel, optionB, painter, self._dock )
Example #3
0
    def paintEvent(self, event):
        painter = QPainter(self)
        painter.fillRect(self.rect(), QColor('#101010'))

        image = self._image

        if image is not None:
            if self.height() < 240:
                fast_scaler = QTransform()
                scale = 297 / image.height()
                if self.mirror:
                    fast_scaler.scale(-scale, scale)
                else:
                    fast_scaler.scale(scale, scale)
                rect = event.rect()
                painter.drawPixmap(
                    rect,
                    QPixmap.fromImage(
                        image.transformed(fast_scaler)).scaledToHeight(
                            self.height(), Qt.SmoothTransformation), rect)
            else:
                transform = QTransform()
                scale = min(self.width() / image.width(),
                            self.height() / image.height())
                if self.mirror:
                    transform.translate(
                        (self.width() + image.width() * scale) / 2,
                        (self.height() - image.height() * scale) / 2)
                    transform.scale(-scale, scale)
                else:
                    transform.translate(
                        (self.width() - image.width() * scale) / 2,
                        (self.height() - image.height() * scale) / 2)
                    transform.scale(scale, scale)

                inverse_transform, invertible = transform.inverted()
                rect = inverse_transform.mapRect(event.rect()).adjusted(
                    -1, -1, 1, 1).intersected(image.rect())

                painter.setTransform(transform)

                if self.height() > 400:
                    painter.drawPixmap(rect, QPixmap.fromImage(image), rect)
                else:
                    painter.drawImage(rect, image, rect)

        painter.end()
Example #4
0
 def paintEvent(self, e):
   w, h = self.width() / Player.N, self.height() / Player.N
   painter = QPainter(self)
   for j in range(0, Player.N):
     for i in range(0, Player.N):
       self.panel.render(painter, QRectF(i * w, j * h, w, h))
   if self.visible:
     for i in range(0, self.ship.__len__()):
       ship = self.ship[i]
       x, y, vertical = self.player.getShip(i)
       if not i == self.moving:
         dx, dy = 0, 0
       else:
         dx, dy = self.dx, self.dy
       if not vertical:
         ship.render(painter, QRectF(x * w + dx, y * h + dy, w * Player.LENGTH[i], h))
       else:
         painter.setTransform(QTransform(0, 1, 1, 0, 0, 0))
         ship.render(painter, QRectF(y * h + dy, x * w + dx, h * Player.LENGTH[i], w))
         painter.resetTransform()
Example #5
0
 def paintEvent(self, event):
     event_rect = event.rect()
     image = self.client.image
     painter = QPainter(self)
     if image is None or image.isNull():
         pass
     elif self.scale:
         inverse_transform, invertible = self.transform.inverted()
         image_rect = inverse_transform.mapRect(event_rect).adjusted(-1, -1, 1, 1).intersected(image.rect())
         painter.setRenderHint(QPainter.SmoothPixmapTransform, True)
         painter.setTransform(self.transform)
         if image.format() == QImage.Format_Indexed8:
             image_area = image.copy(image_rect)
             image_area.setColorTable(self.colors_8bit)
             painter.drawImage(image_rect, image_area)
         else:
             painter.drawImage(image_rect, image, image_rect)
     elif image.format() == QImage.Format_Indexed8:
         image_area = image.copy(event_rect)
         image_area.setColorTable(self.colors_8bit)
         painter.drawImage(event_rect, image_area)
     else:
         painter.drawImage(event_rect, image, event_rect)
Example #6
0
    def paintEvent(self, event):
        painter = QPainter(self)
        painter.fillRect(self.rect(), QColor('#101010'))

        image = self._image

        if image is not None:
            if self.height() < 240:
                fast_scaler = QTransform()
                scale = 297/image.height()
                if self.mirror:
                    fast_scaler.scale(-scale, scale)
                else:
                    fast_scaler.scale(scale, scale)
                rect = event.rect()
                painter.drawPixmap(rect, QPixmap.fromImage(image.transformed(fast_scaler)).scaledToHeight(self.height(), Qt.SmoothTransformation), rect)
            else:
                transform = QTransform()
                scale = min(self.width()/image.width(), self.height()/image.height())
                if self.mirror:
                    transform.translate((self.width() + image.width()*scale)/2, (self.height() - image.height()*scale)/2)
                    transform.scale(-scale, scale)
                else:
                    transform.translate((self.width() - image.width()*scale)/2, (self.height() - image.height()*scale)/2)
                    transform.scale(scale, scale)

                inverse_transform, invertible = transform.inverted()
                rect = inverse_transform.mapRect(event.rect()).adjusted(-1, -1, 1, 1).intersected(image.rect())

                painter.setTransform(transform)

                if self.height() > 400:
                    painter.drawPixmap(rect, QPixmap.fromImage(image), rect)
                else:
                    painter.drawImage(rect, image, rect)

        painter.end()
Example #7
0
 def paintEvent(self, event):
     event_rect = event.rect()
     image = self.client.image
     painter = QPainter(self)
     if image is None or image.isNull():
         pass
     elif self.scale:
         inverse_transform, invertible = self.transform.inverted()
         image_rect = inverse_transform.mapRect(event_rect).adjusted(
             -1, -1, 1, 1).intersected(image.rect())
         painter.setRenderHint(QPainter.SmoothPixmapTransform, True)
         painter.setTransform(self.transform)
         if image.format() == QImage.Format_Indexed8:
             image_area = image.copy(image_rect)
             image_area.setColorTable(self.colors_8bit)
             painter.drawImage(image_rect, image_area)
         else:
             painter.drawImage(image_rect, image, image_rect)
     elif image.format() == QImage.Format_Indexed8:
         image_area = image.copy(event_rect)
         image_area.setColorTable(self.colors_8bit)
         painter.drawImage(event_rect, image_area)
     else:
         painter.drawImage(event_rect, image, event_rect)
Example #8
0
    def paintEvent(self, event):
        painter = QPainter(self)
        width = self.width()
        height = self.height()

        if DEBUG:
            painter.fillRect(0, 0, width, height, Qt.blue)
        else:
            painter.fillRect(event.rect(), self.plot.canvas_color)

        y_min_scale = self.plot.y_scale.value_min
        y_max_scale = self.plot.y_scale.value_max

        factor_x = float(width) / self.plot.history_length_x
        factor_y = float(height - 1) / max(
            y_max_scale - y_min_scale, EPSILON
        )  # -1 to accommodate the 1px width of the curve

        if self.plot.x_min != None and self.plot.x_max != None:
            x_min = self.plot.x_min
            x_max = self.plot.x_max

            if self.plot.curve_start == "left":
                curve_x_offset = 0
            else:
                curve_x_offset = round((self.plot.history_length_x - (x_max - x_min)) * factor_x)

            transform = QTransform()

            transform.translate(
                curve_x_offset, height - 1 + self.plot.curve_y_offset
            )  # -1 to accommodate the 1px width of the curve
            transform.scale(factor_x, -factor_y)
            transform.translate(-x_min, -y_min_scale)

            if self.plot.curve_motion_granularity > 1:
                self.plot.partial_update_width = math.ceil(transform.map(QLineF(0, 0, 1.5, 0)).length())
                inverted_event_rect = transform.inverted()[0].mapRect(QRectF(event.rect()))

            painter.save()
            painter.setTransform(transform)

            for c in range(len(self.plot.curves_x)):
                if not self.plot.curves_visible[c]:
                    continue

                curve_x = self.plot.curves_x[c]
                curve_y = self.plot.curves_y[c]
                path = QPainterPath()
                lineTo = path.lineTo

                if self.plot.curve_motion_granularity > 1:
                    start = max(min(bisect.bisect_left(curve_x, inverted_event_rect.left()), len(curve_x) - 1) - 1, 0)
                else:
                    start = 0

                path.moveTo(curve_x[start], curve_y[start])

                for i in xrange(start + 1, len(curve_x)):
                    lineTo(curve_x[i], curve_y[i])

                painter.setPen(self.plot.configs[c][1])
                painter.drawPath(path)

            painter.restore()
Example #9
0
    def paintEvent(self, event):
        painter = QPainter(self)
        width = self.width()
        height = self.height()

        if DEBUG:
            painter.fillRect(0, 0, width, height, Qt.blue)
        else:
            painter.fillRect(event.rect(), self.plot.canvas_color)

        y_min_scale = self.plot.y_scale.value_min
        y_max_scale = self.plot.y_scale.value_max

        factor_x = float(width) / self.plot.x_diff
        factor_y = float(height - 1) / max(
            y_max_scale - y_min_scale,
            EPSILON)  # -1 to accommodate the 1px width of the curve

        if self.plot.x_min != None and self.plot.x_max != None:
            x_min = self.plot.x_min
            x_max = self.plot.x_max

            if self.plot.curve_start == 'left':
                curve_x_offset = 0
            else:
                curve_x_offset = round(
                    (self.plot.x_diff - (x_max - x_min)) * factor_x)

            transform = QTransform()

            transform.translate(
                curve_x_offset, height - 1 + self.plot.curve_y_offset
            )  # -1 to accommodate the 1px width of the curve
            transform.scale(factor_x, -factor_y)
            transform.translate(-x_min, -y_min_scale)

            if self.plot.curve_motion_granularity > 1:
                self.plot.partial_update_width = math.ceil(
                    transform.map(QLineF(0, 0, 1.5, 0)).length())
                inverted_event_rect = transform.inverted()[0].mapRect(
                    QRectF(event.rect()))

            painter.save()
            painter.setTransform(transform)

            if False and self.plot.curves_visible[0]:
                # Currently unused support for bar graphs.
                # If we need this later on we should add an option to the
                # PlotWidget for it.
                # I tested this for the Sound Pressure Level Bricklet and it works,
                # but it didnt't look good.
                curve_x = self.plot.curves_x[0]
                curve_y = self.plot.curves_y[0]

                t = time.time()
                if self.max_points == None:
                    self.max_points = []
                    for y in curve_y:
                        self.max_points.append((t, y))
                else:
                    for i in range(len(curve_y)):
                        if (curve_y[i] > self.max_points[i][1]) or (
                            (t - self.max_points[i][0]) > 5):
                            self.max_points[i] = (t, curve_y[i])

                for i in range(len(self.plot.curves_x[0])):
                    painter.setPen(self.plot.curve_configs[0].color)
                    painter.drawLine(QPoint(curve_x[i], 0),
                                     QPoint(curve_x[i], curve_y[i]))
                    painter.setPen(Qt.white)
                    painter.drawLine(QPoint(curve_x[i], curve_y[i]),
                                     QPoint(curve_x[i], y_max_scale))
                    painter.setPen(Qt.darkGreen)
                    painter.drawPoint(QPoint(curve_x[i],
                                             self.max_points[i][1]))
            else:
                for c in range(len(self.plot.curves_x)):
                    if not self.plot.curves_visible[c]:
                        continue

                    curve_x = self.plot.curves_x[c]
                    curve_y = self.plot.curves_y[c]
                    path = QPainterPath()
                    lineTo = path.lineTo

                    if self.plot.curve_motion_granularity > 1:
                        start = max(
                            min(
                                bisect.bisect_left(curve_x,
                                                   inverted_event_rect.left()),
                                len(curve_x) - 1) - 1, 0)
                    else:
                        start = 0

                    path.moveTo(curve_x[start], curve_y[start])

                    for i in xrange(start + 1, len(curve_x)):
                        lineTo(curve_x[i], curve_y[i])

                    painter.setPen(self.plot.curve_configs[c].color)
                    painter.drawPath(path)

            painter.restore()