Пример #1
0
    def paintEvent(self, event):
        painter = QPainter(self)

        # 描画の中心をWidgetの中心に持ってくる
        cx = float(self.width()) * 0.5
        cy = float(self.height()) * 0.5
        painter.translate(cx, cy)

        # これ以降にトランスとスケール操作を持ってくる
        painter.scale(self.scale.x(), self.scale.y())
        painter.translate(self.trans + self.mouseTrans)

        if self.rotatingWorld == True:
            painter.rotate(-90)

        # これ以降に描きたいものを重ねていく
        self.drawField(painter)

        self.drawTargets(painter)

        self.drawAvoidPoints(painter)

        self.drawFriends(painter)
        self.drawEnemis(painter)
        self.drawBallVelocity(painter)
        self.drawBall(painter)
Пример #2
0
    def paintEvent(self, event):
        painter = QPainter(self)

        # 描画の中心をWidgetの中心に持ってくる
        cx = float(self.width()) * 0.5
        cy = float(self.height()) * 0.5
        painter.translate(cx, cy)

        # これ以降にトランスとスケール操作を持ってくる
        painter.scale(self.scale.x(), self.scale.y())
        painter.translate(self.trans + self.mouseTrans)

        if self._should_rotate_world == True:
            painter.rotate(-90)

        # これ以降に描きたいものを重ねていく
        self.drawField(painter)

        self.drawAvoidingPoints(painter)
        self.drawTargets(painter)

        self.drawFriends(painter)
        self.drawEnemis(painter)
        self.drawBallVelocity(painter)
        self.drawBall(painter)

        if self._is_ballpos_replacement or self._is_robotpos_replacement:
            self.drawPosReplacement(painter)
            self.drawCoordinateText(painter)
        elif self._is_ballvel_replacement:
            self.drawVelReplacement(painter)
        elif self._is_robotangle_replacement:
            self.drawAngleReplacement(painter)
        else:
            self.drawCoordinateText(painter)
    def image_paint_event(self, data):
        self.image_paint_event_original(data)
        if self._cv_image is None:
            return;
        img = self._cv_image

        painter = QPainter(self.imageFrame)
        painter.drawImage(data.rect(), img)
        painter.end()
Пример #4
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!")
    def _save_image(self):
        file_name, _ = QFileDialog.getSaveFileName(self._widget, self.tr('Save as image'), 'rospackgraph.png', self.tr('Image (*.bmp *.jpg *.png *.tiff)'))
        if file_name is None or file_name == '':
            return

        img = QImage((self._scene.sceneRect().size() * 2.0).toSize(), QImage.Format_ARGB32_Premultiplied)
        painter = QPainter(img)
        painter.setRenderHint(QPainter.Antialiasing)
        self._scene.render(painter)
        painter.end()
        img.save(file_name)
    def _save_svg(self):
        file_name, _ = QFileDialog.getSaveFileName(self._widget, self.tr('Save as SVG'), 'rospackgraph.svg', self.tr('Scalable Vector Graphic (*.svg)'))
        if file_name is None or file_name == '':
            return

        generator = QSvgGenerator()
        generator.setFileName(file_name)
        generator.setSize((self._scene.sceneRect().size() * 2.0).toSize())

        painter = QPainter(generator)
        painter.setRenderHint(QPainter.Antialiasing)
        self._scene.render(painter)
        painter.end()
Пример #7
0
    def _export(self):
        file_name, _ = QFileDialog.getSaveFileName(
            self, self.tr("Save as image"), "graph.png", self.tr("Image (*.bmp *.jpg *.png *.tiff)")
        )

        if file_name is None or file_name == "":
            return

        img = QImage((self._scene.sceneRect().size() * 2.0).toSize(), QImage.Format_ARGB32_Premultiplied)
        painter = QPainter(img)
        painter.setRenderHint(QPainter.Antialiasing)
        self._scene.render(painter)
        painter.end()
        img.save(file_name)
Пример #8
0
 def paintEvent(self, event):
     painter = QPainter(self)
     #painter.setPen(QtCore.Qt.black)
     #painter.translate(self.x(), self.y())
     painter.rotate(self.angle)
     painter.drawPixmap(0, 0, self.width(), self.height(), self._pixmap)
     painter.end()
Пример #9
0
    def make_icon(self, image_list, mode=QIcon.Normal, state=QIcon.On):
        """
        Helper function to create QIcons from lists of image files
        Warning: svg files interleaved with other files will not render correctly

        :param image_list: list of image paths to layer into an icon.
        :type image: list of str
        :param mode: The mode of the QIcon to be created.
        :type mode: int
        :param state: the state of the QIcon to be created.
        :type state: int
        """
        if type(image_list) is not list:
            image_list = [image_list]
        if len(image_list) <= 0:
            raise TypeError('The list of images is empty.')

        num_svg = 0
        for item in image_list:
            if item[-4:].lower() == '.svg':
                num_svg = num_svg + 1

        if num_svg != len(image_list):
            # Legacy support for non-svg images
            icon_pixmap = QPixmap()
            icon_pixmap.load(image_list[0])
            painter = QPainter(icon_pixmap)
            for item in image_list[1:]:
                painter.drawPixmap(0, 0, QPixmap(item))
            icon = QIcon()
            icon.addPixmap(icon_pixmap, mode, state)
            painter.end()
            return icon
        else:
            #  rendering SVG files into a QImage
            renderer = QSvgRenderer(image_list[0])
            icon_image = QImage(renderer.defaultSize(), QImage.Format_ARGB32)
            icon_image.fill(0)
            painter = QPainter(icon_image)
            renderer.render(painter)
            if len(image_list) > 1:
                for item in image_list[1:]:
                    renderer.load(item)
                    renderer.render(painter)
            painter.end()
            #  Convert QImage into a pixmap to create the icon
            icon_pixmap = QPixmap()
            icon_pixmap.convertFromImage(icon_image)
            icon = QIcon(icon_pixmap)
            return icon
Пример #10
0
    def paintEvent(self, event):
        painter = QPainter(self)

        # 描画の中心をWidgetの中心に持ってくる
        cx = float(self.width()) * 0.5
        cy = float(self.height()) * 0.5
        painter.translate(cx, cy)

        painter.scale(self._scale.x(), self._scale.y())
        painter.translate(self._trans + self._mouse_trans)

        if self._do_rotate_view is True:
            painter.rotate(-90)

        # これ以降に書きたいものを重ねる
        self._draw_field(painter)

        # Referee情報
        self._draw_referee(painter)

        self._draw_ball(painter)
        self._draw_ball_velocity(painter)

        # JoyStick関連
        if len(self._joy_target.path) > 0:
            self._draw_joy_target(painter)

        self._draw_robots(painter)

        # grSim Replacement関連
        if self._replacement_target['ball_pos'] or self._replacement_target[
                'robot_pos']:
            self._draw_pos_replacement(painter)
            self._draw_cursor_coordinate(painter)

        elif self._replacement_target['ball_vel']:
            self._draw_vel_replacement(painter)

        elif self._replacement_target['robot_angle']:
            self._draw_angle_replacement(painter)

        else:
            self._draw_cursor_coordinate(painter)
Пример #11
0
    def mouseMoveEvent(self, event):
        '''
        Determine if the current movement is a drag.  If it is, convert it into a QDrag.  If the
        drag ends inside the tab bar, emit an move_tab_signal.  If the drag ends outside the tab
        bar, emit an detach_tab_signal.
        '''
        # Determine if the current movement is detected as a drag
        if not self.drag_start_pos.isNull() and ((event.pos() - self.drag_start_pos).manhattanLength() > QApplication.startDragDistance()):
            self.drag_initiated = True

        # If the current movement is a drag initiated by the left button
        if ((event.buttons() & Qt.LeftButton)) and self.drag_initiated:

            # Stop the move event
            finishMoveEvent = QMouseEvent(QEvent.MouseMove, event.pos(), Qt.NoButton, Qt.NoButton, Qt.NoModifier)
            QTabBar.mouseMoveEvent(self, finishMoveEvent)

            # Convert the move event into a drag
            drag = QDrag(self)
            mime_data = QMimeData()
            mime_data.setData('action', b'application/tab-detach')
            drag.setMimeData(mime_data)

            # Create the appearance of dragging the tab content
            # tab_index = self.tabAt(self.drag_start_pos)
            pixmap = self.parentWidget().grab()
            targetPixmap = QPixmap(pixmap.size())
            targetPixmap.fill(Qt.transparent)
            painter = QPainter(targetPixmap)
            painter.setOpacity(0.85)
            painter.drawPixmap(0, 0, pixmap)
            painter.end()
            drag.setPixmap(targetPixmap)

            # Initiate the drag
            dropAction = drag.exec_(Qt.MoveAction | Qt.CopyAction)

            # If the drag completed outside of the tab bar, detach the tab and move
            # the content to the current cursor position
            if dropAction == Qt.IgnoreAction:
                event.accept()
                self.detach_tab_signal.emit(self.tabAt(self.drag_start_pos), self.mouse_cursor.pos(), False)
            elif dropAction == Qt.MoveAction:
                # else if the drag completed inside the tab bar, move the selected tab to the new position
                if not self.drag_droped_pos.isNull():
                    self.move_tab_signal.emit(self.tabAt(self.drag_start_pos), self.tabAt(self.drag_droped_pos))
                else:
                    # else if the drag completed inside the tab bar new TabBar, move the selected tab to the new TabBar
                    self.detach_tab_signal.emit(self.tabAt(self.drag_start_pos), self.mouse_cursor.pos(), False)
                event.accept()
        else:
            QTabBar.mouseMoveEvent(self, event)
Пример #12
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
Пример #13
0
	def paintEvent(self, event):
		# super(QLabel, self).repaint(rect)
		painter = QPainter(self)

		# print "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2", event.rect()

		# painter.fillRect(event.rect(), Qt.darkGray)

		doc = QTextDocument()

		highlight = syntax.PythonHighlighter(doc, is_dark = True, default = ['white'])

		font = self.font()
		# font.setFamily("Courier");	
		font.setStyleHint(QFont.Monospace);
		font.setFixedPitch(True);
		# font.setPointSize(self.font().pointSize());
		doc.setDefaultFont(font)
		self.width = event.rect().width()
		# doc.setTextWidth(self.width())

		text = self.text()

		doc.setPlainText(text)

		painter.translate(0., event.rect().center().y() - doc.size().height()/2.)
		doc.drawContents(painter, QRectF(event.rect()))
		painter.resetTransform()

		self.size = doc.size()

		

		# print "repainting"
		pass
Пример #14
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)
Пример #15
0
    def make_icon(self, image_list, mode=QIcon.Normal, state=QIcon.On):
        """
        Helper function to create QIcons from lists of image files
        Warning: svg files interleaved with other files will not render correctly

        :param image_list: list of image paths to layer into an icon.
        :type image: list of str
        :param mode: The mode of the QIcon to be created.
        :type mode: int
        :param state: the state of the QIcon to be created.
        :type state: int
        """
        if type(image_list) is not list:
            image_list = [image_list]
        if len(image_list) <= 0:
            raise TypeError('The list of images is empty.')

        num_svg = 0
        for item in image_list:
            if item[-4:].lower() == '.svg':
                num_svg = num_svg + 1

        if num_svg != len(image_list):
            # Legacy support for non-svg images
            icon_pixmap = QPixmap()
            icon_pixmap.load(image_list[0])
            painter = QPainter(icon_pixmap)
            for item in image_list[1:]:
                painter.drawPixmap(0, 0, QPixmap(item))
            icon = QIcon()
            icon.addPixmap(icon_pixmap, mode, state)
            painter.end()
            return icon
        else:
            #  rendering SVG files into a QImage
            renderer = QSvgRenderer(image_list[0])
            icon_image = QImage(renderer.defaultSize(), QImage.Format_ARGB32)
            icon_image.fill(0)
            painter = QPainter(icon_image)
            renderer.render(painter)
            if len(image_list) > 1:
                for item in image_list[1:]:
                    renderer.load(item)
                    renderer.render(painter)
            painter.end()
            #  Convert QImage into a pixmap to create the icon
            icon_pixmap = QPixmap()
            icon_pixmap.convertFromImage(icon_image)
            icon = QIcon(icon_pixmap)
            return icon
Пример #16
0
    def _save_image(self):
        file_name, _ = QFileDialog.getSaveFileName(self._widget, self.tr('Save as image'), 'rosgraph.png', self.tr('Image (*.bmp *.jpg *.png *.tiff)'))
        if file_name is None or file_name == '':
            return

        img = QImage((self._scene.sceneRect().size() * 2.0).toSize(), QImage.Format_ARGB32_Premultiplied)
        painter = QPainter(img)
        painter.setRenderHint(QPainter.Antialiasing)
        self._scene.render(painter)
        painter.end()
        img.save(file_name)
Пример #17
0
    def _save_svg(self):
        file_name, _ = QFileDialog.getSaveFileName(self._widget, self.tr('Save as SVG'), 'rosgraph.svg', self.tr('Scalable Vector Graphic (*.svg)'))
        if file_name is None or file_name == '':
            return

        generator = QSvgGenerator()
        generator.setFileName(file_name)
        generator.setSize((self._scene.sceneRect().size() * 2.0).toSize())

        painter = QPainter(generator)
        painter.setRenderHint(QPainter.Antialiasing)
        self._scene.render(painter)
        painter.end()
    def save_svg_to_file(self):
        file_name, _ = QFileDialog.getSaveFileName(self._widget, self.tr("Save as SVG"), "stackmachine.svg",
                                                   self.tr("Scalable Vector Graphic (*.svg)"))

        if file_name is not None and file_name != "":
            generator = QSvgGenerator()
            generator.setFileName(file_name)
            generator.setSize((self._scene.sceneRect().size() * 2.0).toSize())

            painter = QPainter(generator)
            painter.setRenderHint(QPainter.Antialiasing)
            self._scene.render(painter)
            painter.end()
Пример #19
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
Пример #20
0
    def paintEvent(self, event):
        QSlider.paintEvent(self, event)

        curr_value = str(self.value())
        round_value = round(float(curr_value), 4)

        painter = QPainter(self)
        painter.setPen(QPen(QtCore.Qt.white))

        font_metrics = QFontMetrics(self.font())
        font_width = font_metrics.boundingRect(str(round_value)).width()
        font_height = font_metrics.boundingRect(str(round_value)).height()

        rect = self.geometry()
        if self.orientation() == QtCore.Qt.Horizontal:
            horizontal_x_pos = rect.width() - font_width - 5
            horizontal_y_pos = rect.height() * 0.75

            painter.drawText(QtCore.QPoint(horizontal_x_pos, horizontal_y_pos),
                             str(round_value))
            self.x = self.value()
        else:
            pass
        painter.drawRect(rect)
Пример #21
0
	def paintEvent(self, event):
		painter = QPainter(self)

		doc = QTextDocument()
		highlight = syntax.PythonHighlighter(doc, is_dark = True, default = ['white'])

		font = self.font()
		font.setStyleHint(QFont.Monospace);
		font.setFixedPitch(True);
		doc.setDefaultFont(font)
		self.width = event.rect().width()
		text = self.text()

		doc.setPlainText(text)

		painter.translate(0., event.rect().center().y() - doc.size().height()/2.)
		doc.drawContents(painter, QRectF(event.rect()))
		painter.resetTransform()

		self.size = doc.size()
Пример #22
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)
Пример #23
0
 def paintEvent(self, event, ctx=None):
     if ctx is None:
         ctx = QPainter(self)
     self.face.paint(ctx)
     ctx.end()
Пример #24
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()
        def paintEvent(self, event):
            contents_y = self.edit.verticalScrollBar().value()
            page_bottom = contents_y + self.edit.viewport().height()
            font_metrics = self.fontMetrics()
            current_block = self.edit.document().findBlock(self.edit.textCursor().position())
            painter = QPainter(self)
            painter.setPen(Qt.darkGray)
            line_count = 0
            # Iterate over all text blocks in the document.
            block = self.edit.document().begin()
            while block.isValid():
                line_count += 1
                # the top left position of the block in the document
                position = self.edit.document().documentLayout().blockBoundingRect(block).topLeft()
                # check if the position of the block is out side of visible area
                if position.y() > page_bottom:
                    break
                # we want the line number for the selected line to be bold.
                bold = False
                if block == current_block:
                    bold = True
                    font = painter.font()
                    font.setBold(True)
                    painter.setFont(font)
                    painter.setPen(Qt.black)
                # Draw the line number right justified at the y position of the
                # line. 3 is the magic padding number. drawText(x, y, text)
                painter.drawText(self.width() - font_metrics.width(str(line_count)) - 3, round(position.y()) - contents_y + font_metrics.ascent() + self.edit.document().documentMargin(), str(line_count))
                if bold:
                    font = painter.font()
                    font.setBold(False)
                    painter.setFont(font)
                    painter.setPen(Qt.darkGray)

                block = block.next()

            self.highest_line = line_count
            painter.end()
            QWidget.paintEvent(self, event)
Пример #26
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
 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
Пример #28
0
 def paintEvent(self, event):
     painter = QPainter(self)
     painter.drawImage(event.rect(), self.map_image, event.rect())
     painter.drawImage(event.rect(), self.overlay_image, event.rect())
     painter.end()
Пример #29
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))
Пример #30
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)
Пример #31
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()
Пример #32
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")
Пример #33
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
Пример #34
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()
Пример #35
0
    def paintEvent(self, event):
        geom = super(AxisWidget, self).geometry()
        h = geom.height()
        w = geom.width()

        box = QRect(2, 2, w - 4, h - 4)
        horiz = QLine(2, h / 2, w - 2, h / 2)
        vert = QLine(w / 2, 2, w / 2, h - 2)
        targ = QPoint(self._x * (w - 4) / 2 + w / 2,
                      self._y * (h - 4) / 2 + h / 2)

        plt = super(AxisWidget, self).palette()
        linebrsh = plt.dark()
        targetbrsh = plt.highlight()

        linepen = QPen(linebrsh, 1, Qt.SolidLine, Qt.SquareCap)
        targetpen = QPen(targetbrsh, 2, Qt.SolidLine, Qt.SquareCap)

        qp = QPainter()
        qp.begin(self)
        qp.setPen(linepen)
        qp.drawRect(box)
        qp.drawLine(horiz)
        qp.drawLine(vert)
        qp.setPen(targetpen)
        qp.drawEllipse(targ, 10, 10)
        qp.end()
Пример #36
0
 def paintEvent(self, event):
     painter = QPainter(self)
     painter.drawImage(event.rect(), self.map_image, event.rect())
     painter.drawImage(event.rect(), self.overlay_image, event.rect())
     painter.end()
Пример #37
0
    def paintEvent(self,event):
        if not self._initialized:
            self.placeStickAtCenter()
            self._initialized = True

        borderWidth = 1
        joyRange = 80
        center = QtCore.QPoint(self.height()/2,self.width()/2)
        
        qp = QPainter()
        qp.begin(self)
        qp.setRenderHint(QPainter.Antialiasing, True)
        qp.setPen(QPen(QtCore.Qt.lightGray, borderWidth, QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,QtCore.Qt.RoundJoin))

        if self._mode == "circle":

            qp.drawEllipse(center,joyRange,joyRange)

        if self._mode == "square":
            x = center.x() - joyRange
            y = center.y() - joyRange
            width = joyRange * 2
            height = joyRange * 2
            qp.drawRect(x,y,width,height)
       
        qp.end()

        super(JoystickView,self).paintEvent(event)
 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()
Пример #39
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()
Пример #40
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)