Esempio n. 1
0
    def paintEvent(self, event):
        painter = QPainter(self)

        # Hello world
        # ブラシ(塗りつぶし)の色を黒に
        painter.setBrush(Qt.black)
        # ペン(線描画)の色も黒に
        painter.setPen(Qt.black)
        # 背景を描く
        # self.rect()はwidgetのサイズを返すので、widget全体を埋める四角形を描画する
        # ペンとブラシの色が黒なので背景色は真っ黒
        painter.drawRect(self.rect())

        # ペン(線描画)の色を白にする
        painter.setPen(Qt.white)

        # フォントサイズを変更する
        font = painter.font()
        # つらさはできるだけ大きく表現したほうが良い
        # 周りが気づくように
        font.setPointSize(80)
        painter.setFont(font)

        # テキストを描画する
        x = 0  # 左端
        y = self.rect().height() * 0.5  # 上下の中心
        painter.drawText(x, y, "TSU☆RA☆I")
Esempio n. 2
0
    def paintEvent(self,event):
        super(JoystickPointView,self).paintEvent(event)

        try:
            if self._initialized:
                pass
        except: 
            self._origPos = self.pos()
            self._initialized = True

        qp = QPainter()
        qp.begin(self)
        
        borderWidth = 2
        radius = self.height()/2
        center = QtCore.QPoint(self.height()/2,self.width()/2) 
        
        # Outer Circle
        qp.setRenderHint(QPainter.Antialiasing, True)
        qp.setPen(QPen(QtCore.Qt.darkGray, borderWidth, QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,QtCore.Qt.RoundJoin))
        qp.setBrush(QBrush(QtCore.Qt.white, QtCore.Qt.SolidPattern))
        qp.drawEllipse(center,radius-borderWidth,radius-borderWidth)

        # Inner Circle
        qp.setPen(QPen(QtCore.Qt.lightGray, borderWidth, QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,QtCore.Qt.RoundJoin))
        qp.setBrush(QBrush(QtCore.Qt.white, QtCore.Qt.SolidPattern))
        qp.drawEllipse(center,radius-borderWidth-1,radius-borderWidth-1)

        qp.end()
Esempio n. 3
0
    def paintEvent(self, event):
        painter = QPainter(self)

        # Hello world
        painter.setBrush(Qt.green)
        painter.setPen(Qt.black)
        painter.drawRect(self.rect())

        painter.drawText(self.rect().width() * 0.5,
                         self.rect().height() * 0.5, "Hello world!")
Esempio n. 4
0
    def paintEvent(self, event):
        p = QPainter()
        p.begin(self)
        if self.velocity < 0:
            p.setBrush(self.brushGreen)
            p.setPen(self.penGreen)
        else:
            p.setBrush(self.brushRed)
            p.setPen(self.penRed)

        p.drawPie(0, 0, self.width(), self.height(), self.angle, self.velocity)

        p.end()
Esempio n. 5
0
    def updateOverlay(self, rect=None):
        # Redraw the overlay image from scratch using the location image and current location.

        self.image.overlay_image.fill(Qt.transparent)
        painter = QPainter(self.image.overlay_image)
        painter.setBackgroundMode(Qt.TransparentMode)
        painter.setCompositionMode(QPainter.CompositionMode_Source)

        for location in self.locations:
            if self.draw_location[location]:
                color = self.location_colors[location]
                if self.edit_properties_location == location and self.editing_properties:
                    color = self.edit_area_selection_color
                lineColor = QColor(color)
                lineColor.setAlpha(255)
                brushColor = QColor(color)
                brushColor.setAlpha(128)
                painter.setPen(lineColor)
                painter.setBrush(brushColor)
                painter.drawPolygon(self.locations[location])

        if (self.current_selection is not None) or (self.new_selection
                                                    is not None):
            lineColor = QColor(self.edit_area_selection_color)
            lineColor.setAlpha(255)
            brushColor = QColor(self.edit_area_selection_color)
            brushColor.setAlpha(128)
            painter.setPen(lineColor)
            painter.setBrush(brushColor)
            if self.new_selection is not None:
                # Create a temporary polygon as the new selection is being drawn.
                if self.current_selection is not None:
                    current_selection = QPolygon(self.current_selection)
                    if self.subtract_new_selection:
                        current_selection = current_selection.subtracted(
                            self.new_selection)
                    else:
                        current_selection = current_selection.united(
                            self.new_selection)
                    painter.drawPolygon(current_selection)
                elif self.subtract_new_selection == False:
                    painter.drawPolygon(self.new_selection)
            else:
                painter.drawPolygon(self.current_selection)
        painter.end()

        if rect is None:
            self.image.update()
        else:
            self.image.update(rect)
    def updateOverlay(self, rect = None):
        # Redraw the overlay image from scratch using the location image and current location.

        self.image.overlay_image.fill(Qt.transparent)
        painter = QPainter(self.image.overlay_image)
        painter.setBackgroundMode(Qt.TransparentMode)
        painter.setCompositionMode(QPainter.CompositionMode_Source)

        for location in self.locations:
            if self.draw_location[location]:
                color = self.location_colors[location]
                if self.edit_properties_location == location and self.editing_properties:
                    color = self.edit_area_selection_color
                lineColor = QColor(color)
                lineColor.setAlpha(255)
                brushColor = QColor(color)
                brushColor.setAlpha(128)
                painter.setPen(lineColor)
                painter.setBrush(brushColor)
                painter.drawPolygon(self.locations[location])

        if (self.current_selection is not None) or (self.new_selection is not None):
            lineColor = QColor(self.edit_area_selection_color)
            lineColor.setAlpha(255)
            brushColor = QColor(self.edit_area_selection_color)
            brushColor.setAlpha(128)
            painter.setPen(lineColor)
            painter.setBrush(brushColor)
            if self.new_selection is not None:
                # Create a temporary polygon as the new selection is being drawn.
                if self.current_selection is not None:
                    current_selection = QPolygon(self.current_selection)
                    if self.subtract_new_selection:
                        current_selection = current_selection.subtracted(self.new_selection)
                    else:
                        current_selection = current_selection.united(self.new_selection)
                    painter.drawPolygon(current_selection)
                elif self.subtract_new_selection == False:
                    painter.drawPolygon(self.new_selection)
            else:
                painter.drawPolygon(self.current_selection)
        painter.end()

        if rect is None:
            self.image.update()
        else:
            self.image.update(rect)
Esempio n. 7
0
    def paintEvent(self,event=None):
	#global mouse_is_pressed

	w_height = self.frameGeometry().height()
	w_width = self.frameGeometry().width()
	if w_height > w_width:
	    diam = w_width
	else:
	    diam = w_height
	radius = int(diam / 2) - 10

	start_x = w_width/2 - radius
	start_y = w_height/2 - radius

	line1_x1 = w_width/2 + radius*0.707
	line1_x2 = w_width/2 - radius*0.707
	line1_y1 = w_height/2 - radius*0.707
	line1_y2 = w_height/2 + radius*0.707
	line2_x1 = w_width/2 - radius*0.707
	line2_x2 = w_width/2 + radius*0.707
	line2_y1 = line1_y1
	line2_y2 = line1_y2

        painter=QPainter()
        painter.begin(self)
        painter.setPen(QPen(Qt.black))
        painter.drawLine(line1_x1, line1_y1, line1_x2, line1_y2) #cross
	painter.drawLine(line2_x1, line2_y1, line2_x2, line2_y2)
	painter.drawEllipse(start_x,start_y , (radius*2), (radius*2))

	if self.mouse_is_pressed == True:
	    painter.setBrush(Qt.blue)
	    rad = self.get_radius(w_width, w_height, self.cursor_pos)
            pos = self.get_pos(w_width, w_height, self.cursor_pos)
	    if (radius < rad):
	        rad = radius
	    self.draw_arc(painter, w_width, w_height, pos, rad)
	    self.cur_nradius = rad*1.0/radius
	    self.cur_sector = pos
	else:
	    self.cur_nradius = 0.0
	    self.cur_sector = 0.0
        painter.end()
	#print self.mouse_is_pressed
        pass
 def paintEvent(self, event):
     with self.lock:
         if self.status == 1:
             color = self._SUCCESS_COLOR
         elif self.status == 2:
             color = self._WARN_COLOR
         else:
             color = self._UNKNOWN_COLOR
         rect = event.rect()
         qp = QPainter()
         qp.begin(self)
         radius = min(rect.width(), rect.height()) - 100
         qp.setFont(QFont('Helvetica', 100))
         qp.setPen(QPen(QBrush(color), 50))
         qp.setBrush(color)
         qp.drawEllipse((rect.width() - radius) / 2, (rect.height() - radius) / 2, 
                        radius, radius)
         qp.end()
         return
Esempio n. 9
0
 def paintEvent(self, event):
     with self.lock:
         if self.status == 1:
             color = self._SUCCESS_COLOR
         elif self.status == 2:
             color = self._WARN_COLOR
         else:
             color = self._UNKNOWN_COLOR
         rect = event.rect()
         qp = QPainter()
         qp.begin(self)
         radius = min(rect.width(), rect.height()) - 100
         qp.setFont(QFont('Helvetica', 100))
         qp.setPen(QPen(QBrush(color), 50))
         qp.setBrush(color)
         qp.drawEllipse((rect.width() - radius) / 2,
                        (rect.height() - radius) / 2, radius, radius)
         qp.end()
         return
Esempio n. 10
0
    def writeLocationsToFile(self):

        out_dict = {}
        out_dict["locations"] = self.locations.keys()
        out_dict["locations"] = sorted(out_dict["locations"])
        out_dict["polygons"] = []
        for index, key in enumerate(sorted(self.locations)):
            out_dict["polygons"].append([])
            polygon = self.locations[key]
            for i in range(polygon.size()):
                pt = polygon.point(i)
                scaled_pt = scalePoint(pt, self.image_size, self.map_size)
                out_dict["polygons"][index].append(scaled_pt.x())
                out_dict["polygons"][index].append(scaled_pt.y())

        data_directory = os.path.dirname(os.path.realpath(self.location_file))
        image_file = getLocationsImageFileLocationFromDataDirectory(
            data_directory)

        # Create an image with the location data, so that C++ programs don't need to rely on determining regions using polygons.
        out_dict["data"] = 'locations.pgm'
        location_image = QImage(self.map_size, QImage.Format_RGB32)
        location_image.fill(Qt.white)
        painter = QPainter(location_image)
        for index, key in enumerate(self.locations):
            if index > 254:
                rospy.logerr(
                    "You have more than 254 locations, which is unsupported by the bwi_planning_common C++ code!"
                )
            painter.setPen(Qt.NoPen)
            painter.setBrush(QColor(index, index, index))
            scaled_polygon = scalePolygon(self.locations[key], self.image_size,
                                          self.map_size)
            painter.drawPolygon(scaled_polygon)
        painter.end()
        location_image.save(image_file)

        stream = open(self.location_file, 'w')
        yaml.dump(out_dict, stream)
        stream.close()

        self.is_modified = False
Esempio n. 11
0
    def paintEvent(self, event):
        painter = QPainter(self)
        #painter.begin(self)

        # puts the arrow in the middle
        painter.translate(self.width() / 2, self.height() / 2)
        painter.rotate(self.angleRobo + self.angleVel)

        line = QLineF(0, 0, self.width() / 2 - 3, 0)

        headSize = min(self.width() / 20, 4)
        points = QPolygonF()
        points.append(QPointF(self.width() / 2 - headSize * 2, headSize))
        points.append(QPointF(self.width() / 2 - headSize * 2, -headSize))
        points.append(QPointF(self.width() / 2 - 3, 0))

        pen = QPen(self.color, 2)
        painter.setPen(pen)
        brush = QBrush(self.color)
        painter.setBrush(brush)

        painter.drawLine(line)
        painter.drawConvexPolygon(points)
Esempio n. 12
0
    def writeLocationsToFile(self):

        out_dict = {}
        out_dict["locations"] = self.locations.keys()
        out_dict["polygons"] = []
        for index, location in enumerate(self.locations):
            out_dict["polygons"].append([])
            for i in range(self.locations[location].size()):
                pt = self.locations[location].point(i)
                scaled_pt = scalePoint(pt, self.image_size, self.map_size)
                out_dict["polygons"][index].append(scaled_pt.x())
                out_dict["polygons"][index].append(scaled_pt.y())

        data_directory = os.path.dirname(os.path.realpath(self.location_file))
        image_file = getLocationsImageFileLocationFromDataDirectory(data_directory)

        # Create an image with the location data, so that C++ programs don't need to rely on determining regions using polygons.
        out_dict["data"] = 'locations.pgm'
        location_image = QImage(self.map_size, QImage.Format_RGB32)
        location_image.fill(Qt.white)
        painter = QPainter(location_image) 
        for index, location in enumerate(self.locations):
            if index > 254:
                rospy.logerr("You have more than 254 locations, which is unsupported by the bwi_planning_common C++ code!")
            painter.setPen(Qt.NoPen)
            painter.setBrush(QColor(index, index, index))
            scaled_polygon = scalePolygon(self.locations[location], self.image_size, self.map_size)
            painter.drawPolygon(scaled_polygon)
        painter.end()
        location_image.save(image_file)

        stream = open(self.location_file, 'w')
        yaml.dump(out_dict, stream)
        stream.close()

        self.is_modified = False
Esempio n. 13
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()
Esempio n. 14
0
 def paintEvent(self, event):
     qp = QPainter(self)
     br = QBrush(QColor(100, 10, 10, 40))
     qp.setBrush(br)
     qp.drawRect(QtCore.QRect(self.begin, self.end))
Esempio n. 15
0
 def drawCircle(self, pnt, color, fill=True):
     p = QPainter(self)
     p.setPen(color)
     if (fill):
         p.setBrush(QBrush(color))
     p.drawEllipse(pnt, 3, 3)