Exemplo n.º 1
0
 def drawRect(self):
     p = QPainter(self)
     in_bounds = QRect(self.pan_limits[0], self.size - self.tilt_limits[1],
                       self.pan_limits[1] - self.pan_limits[0],
                       self.tilt_limits[1] - self.tilt_limits[0])
     p.fillRect(in_bounds, QColor(0, 200, 0, 128))
     p.drawRect(in_bounds)
 def paintEvent(self, event):
     with self.lock:
         self.event = event
         rect = event.rect()
         qp = QPainter()
         qp.begin(self)
         radius = min(rect.width(), rect.height()) - 50
         qp.setFont(QFont('Helvetica', 100))
         qp.setPen(QPen(QBrush(QColor(255, 255, 255)), 20))
         
         if self.is_disabled:
             qp.fillRect(rect, self._DISABLED_COLOR)
             qp.drawText(rect, QtCore.Qt.AlignCenter, self._FROWN)
         elif self.is_blackout:
             qp.fillRect(rect, self._BLACKOUT_COLOR)
             qp.drawText(rect, QtCore.Qt.AlignCenter, self._FROWN)
             time_diff = (self.next_whiteout_time - rospy.Time.now()).to_sec()
             if time_diff < 0:
                 time_diff = 0
             time_ratio = time_diff / (self.next_whiteout_time - self.blackout_time).to_sec()
             qp.setFont(QFont('Helvetica', 30))
             qp.drawText(0, rect.height() - 150, rect.width(), 150, QtCore.Qt.AlignCenter, "%.1f sec" % time_diff)
             # 0-360
             if time_ratio > 0:
                 rad = int(math.fmod(time_ratio * 360 + 90*16, 360) * 16)
                 qp.drawArc((rect.width() - radius) / 2, (rect.height() - radius) / 2, radius, radius, 90*16, rad)
         else:
             qp.fillRect(rect, self._OK_COLOR)
             qp.drawText(rect, QtCore.Qt.AlignCenter, self._SMILEY)
         qp.end()
Exemplo n.º 3
0
 def paintEvent(self, event):
     with self.lock:
         self.event = event
         rect = event.rect()
         qp = QPainter()
         qp.begin(self)
         radius = min(rect.width(), rect.height()) - 50
         qp.setFont(QFont('Helvetica', 100))
         qp.setPen(QPen(QBrush(QColor(255, 255, 255)), 20))
         
         if self.is_disabled:
             qp.fillRect(rect, self._DISABLED_COLOR)
             qp.drawText(rect, QtCore.Qt.AlignCenter, self._FROWN)
         elif self.is_blackout:
             qp.fillRect(rect, self._BLACKOUT_COLOR)
             qp.drawText(rect, QtCore.Qt.AlignCenter, self._FROWN)
             time_diff = (self.next_whiteout_time - rospy.Time.now()).to_sec()
             if time_diff < 0:
                 time_diff = 0
             time_ratio = time_diff / (self.next_whiteout_time - self.blackout_time).to_sec()
             qp.setFont(QFont('Helvetica', 30))
             qp.drawText(0, rect.height() - 150, rect.width(), 150, QtCore.Qt.AlignCenter, "%.1f sec" % time_diff)
             # 0-360
             if time_ratio > 0:
                 rad = int(math.fmod(time_ratio * 360 + 90*16, 360) * 16)
                 qp.drawArc((rect.width() - radius) / 2, (rect.height() - radius) / 2, radius, radius, 90*16, rad)
         else:
             qp.fillRect(rect, self._OK_COLOR)
             qp.drawText(rect, QtCore.Qt.AlignCenter, self._SMILEY)
         qp.end()
Exemplo n.º 4
0
    def redraw(self, event):
        """
        
        Draw timeline's "cells" (ie. boxes that represent seconds). 
                
        Taken from robot_monitor.message_timeline.on_paint
        
        @deprecated: This way (using QPainter) didn't work as intended.
        """

        #super(TimelineView, self).paintEvent(event)

        # painter = QPainter(self)
        ## This yields warning that says:
        ## "QPainter::begin: Widget painting can only begin as a result of a paintEvent"

        painter = QPainter()
        painter.begin(self.viewport())
        pen = QPen(
            Qt.black,
            2)  #, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)  # Needs modified.
        painter.setPen(pen)

        is_enabled = self.isEnabled()

        #(width_tl, height_tl) = self.size()
        qsize = self.size()
        width_tl = qsize.width()
        height_tl = qsize.height()

        length_tl = self._max_num_seconds + 1 - self._min_num_seconds
        rospy.logdebug('paintEvent is_enabled=%s length_tl=%d', is_enabled,
                       length_tl)
        value_size = width_tl / float(length_tl)
        for i in xrange(0, length_tl):
            brush = None
            color_index = i + self._min_num_seconds
            if (is_enabled):
                qcolor = self._color_callback(color_index)
            else:
                qcolor = QColor('grey')
            end_color = QColor(0.5 * QColor('red').value(),
                               0.5 * QColor('green').value(),
                               0.5 * QColor('blue').value())
            #painter.setBrush(qcolor)
            painter.setBrush(QBrush(qcolor))
            start = i * value_size
            end = (i + 1) * value_size
            rect = QRect(start, 0, end, height_tl)

            # dc.GradientFillLinear(wx.Rect(start, 0, end, height_tl),
            #                       qcolor, end_color, wx.SOUTH)
            rospy.logdebug('paintEvent i=%d start=%s end=%s height_tl=%s', i,
                           start, end, height_tl)
            #painter.fillRect(QRect(start, end, 100, height_tl), qcolor)
            painter.fillRect(rect, qcolor)

            if (i > 0):
                # dc.SetPen(wx.BLACK_PEN)
                pen.setColor(Qt.black)
                # dc.DrawLine(start, 0, start, height_tl)
                painter.drawLine(start, 0, start, height_tl)

        size_marker = QSize(20, 20)
        marker_x = (
            (self._xpos_marker - 1) * value_size + (value_size / 2.0) -
            (self._timeline_marker.actualSize(size_marker).width() / 2.0))

        # dc.DrawBitmap(self._timeline_marker, marker_x, 0, True)
        qrect = QRect(marker_x, 0, size_marker.width(), size_marker.height())
        self._timeline_marker.paint(painter, qrect)
        rospy.logdebug(' paintEvent marker_x=%s', marker_x)

        painter.end()