def draw_bounding_box(self):
        df = self.page_df

        scale = self.zoom
        no_df = df[df.word=="redroverr2"]
        tle_df = df[df.word.str.contains("suf", na = False)]
        catt_df = df[df.word.str.contains("insuf", na=False)]
        rinder_df = df[df.word.str.contains("ind1111er", na=False)]

        for index, row in no_df.iterrows():
            print(row)
            x1 = row.x1*scale
            y1 = row.y1*scale
            x3= row.x3*scale
            y3 = row.y3*scale
            diff_x = x3-x1
            diff_y = y3-y1
            rectItem = QGraphicsRectItem(x1,y1,diff_x,diff_y)
            rectItem.setBrush(QBrush(Qt.green))
            #rectItem = QGraphicsRectItem(0, 0, 100, 100)
            self.scene.addItem(rectItem)

        for index, row in tle_df.iterrows():
            print(row)
            x1 = row.x1 * scale
            y1 = row.y1 * scale
            x3 = row.x3 * scale
            y3 = row.y3 * scale
            diff_x = x3 - x1
            diff_y = y3 - y1
            rectItem = QGraphicsRectItem(x1, y1, diff_x, diff_y)
            rectItem.setBrush(QBrush(Qt.green))
            # rectItem = QGraphicsRectItem(0, 0, 100, 100)
            self.scene.addItem(rectItem)

        for index, row in rinder_df.iterrows():
            print(row)
            x1 = row.x1 * scale
            y1 = row.y1 * scale
            x3 = row.x3 * scale
            y3 = row.y3 * scale
            diff_x = x3 - x1
            diff_y = y3 - y1
            rectItem = QGraphicsRectItem(x1, y1, diff_x, diff_y)
            rectItem.setBrush(QBrush(Qt.red))
            # rectItem = QGraphicsRectItem(0, 0, 100, 100)
            self.scene.addItem(rectItem)

        for index, row in catt_df.iterrows():
            print(row)
            x1 = row.x1 * scale
            y1 = row.y1 * scale
            x3 = row.x3 * scale
            y3 = row.y3 * scale
            diff_x = x3 - x1
            diff_y = y3 - y1
            rectItem = QGraphicsRectItem(x1, y1, diff_x, diff_y)
            rectItem.setBrush(QBrush(Qt.red))
            # rectItem = QGraphicsRectItem(0, 0, 100, 100)
            self.scene.addItem(rectItem)
Example #2
0
    def __init__(self, parent=None):
        super(GameWindow, self).__init__(parent=parent)
        self.screen = None
        self.scene = QGraphicsScene()
        self.scene.setSceneRect(
            QRect(left=0,
                  top=0,
                  width=PLAYGROUND_SIZEX * SCALE_FACTORX,
                  height=PLAYGROUND_SIZEY * SCALE_FACTORY))
        self.setFrameStyle(4)
        self.setScene(self.scene)
        self.snake = []
        # define SnakeHead
        self.snake.append(QGraphicsRectItem())
        self.snake[0].setRect(QRect(0, 0, SCALE_FACTORX, SCALE_FACTORY))

        self.snake[0].setBrush(brushHead)
        self.scene.addItem(self.snake[0])
        # define rest of the snake
        for i in range(1, MAX_LENGTH_SNAKE):
            self.snake.append(QGraphicsRectItem())
            self.snake[i].setRect(QRect(0, 0, SCALE_FACTORX, SCALE_FACTORY))
            self.snake[i].setBrush(brushBody)
            self.snake[i].setVisible(False)
            self.scene.addItem(self.snake[i])
        # Create the graphic item for apple
        self.goal = QGraphicsRectItem()
        self.goal.setRect(QRect(0, 0, SCALE_FACTORX, SCALE_FACTORY))
        self.goal.setBrush(brushGoal)
        self.scene.addItem(self.goal)

        self.show()
Example #3
0
    def setup_scene(self, img: Image):
        #if img.mode != "RGB":
        #img = img.convert("RGB")
        self.image = img
        scene = CanvasGraphicsScene()
        self.setScene(scene)

        #scene固有の初期化
        qtimg = ImageQt(self.image)
        pixmap = QPixmap.fromImage(qtimg).copy()
        pixmap_item = QGraphicsPixmapItem(pixmap)
        self.scene().addItem(pixmap_item)
        pixmap_item.setPos(0, 0)
        self.rect_item = QGraphicsRectItem(0, 0, 200, 200)
        self.rect_item.setPen(QPen(QtCore.Qt.blue, 3))
        self.rect_item.hide()
        self.scene().addItem(self.rect_item)
        self.frame_rect_item = QGraphicsRectItem(0, 0, self.image.width - 3,
                                                 self.image.height - 3)
        self.frame_rect_item.setPen(QPen(QtCore.Qt.red, 5))
        self.scene().addItem(self.frame_rect_item)

        self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        img = self.image
        self.setSceneRect(0, 0, img.width, img.height)
        self.setFixedSize(img.width, img.height)

        self._dragging = False
        pass
Example #4
0
 def setUp(self):
     horizontal_threshold = 1.0
     vertical_threshold = 3.0
     self.scene = ShrinkingScene(horizontal_threshold, vertical_threshold,
                                 None)
     item_size = 1.0
     self.fixed_item = QGraphicsRectItem(0.0, 0.0, item_size, item_size)
     self.item = QGraphicsRectItem(0.0, 0.0, item_size, item_size)
     self.item.setPos(10.0, 10.0)
     self.scene.addItem(self.fixed_item)
     self.scene.addItem(self.item)
     self.assertEqual(self.scene.sceneRect(),
                      QRectF(-0.5, -0.5, 12.0, 12.0))
 def testIt(self):
     scene = QGraphicsScene()
     i1 = QGraphicsRectItem()
     scene.addItem(i1)
     i2 = QGraphicsRectItem(i1)
     i3 = QGraphicsRectItem()
     i4 = QGraphicsRectItem()
     group = scene.createItemGroup((i2, i3, i4))
     scene.removeItem(i1)
     del i1  # this shouldn't delete i2
     self.assertEqual(i2.scene(), scene)
     scene.destroyItemGroup(group)
     self.assertRaises(RuntimeError, group.type)
Example #6
0
 def __init__(self, main_window, stage=1):
     super().__init__()
     self.main_window = main_window
     self.stage = stage
     self.upper_mask = QGraphicsRectItem(0, 0, content_width, 0)
     self.lower_mask = QGraphicsRectItem(0, content_height, content_width, 0)
     self.stage_text_item = QGraphicsTextItem()
     self.mask_height = 0
     self.animation_timer_1 = QTimer()
     self.animation_timer_2 = QTimer()
     self.animation_timer_3 = QTimer()
     self.selected = None
     self.init()
Example #7
0
    def setUp(self):
        #Acquire resources
        super(ItemRetrieve, self).setUp()
        self.scene = QGraphicsScene()

        self.topleft = QGraphicsRectItem(0, 0, 100, 100)
        self.topright = QGraphicsRectItem(100, 0, 100, 100)
        self.bottomleft = QGraphicsRectItem(0, 100, 100, 100)
        self.bottomright = QGraphicsRectItem(100, 100, 100, 100)

        self.items = [self.topleft, self.topright, self.bottomleft,
                        self.bottomright]

        for item in self.items:
            self.scene.addItem(item)
Example #8
0
    def add_instance(
            self, instance: "GameInstance"
    ) -> Tuple[QGraphicsItem, Callable[[], None]]:
        """Add instance to manage, return a disconnect function and the canvas"""
        positionChanged = lambda rect: self.on_instance_moved(instance, rect)
        instance.positionChanged.connect(positionChanged)

        focusChanged = lambda focus: self.on_instance_focus_change(
            instance, focus)
        instance.focusChanged.connect(focusChanged)

        instance_pos = instance.get_position()
        gfx = QGraphicsRectItem(rect=instance_pos)
        gfx.setPen(self.transparent_pen)
        gfx.setPos(instance_pos.x(), instance_pos.y())
        self.scene.addItem(gfx)
        self._instances[instance.wid] = gfx

        def disconnect():
            gfx.hide()
            self.scene.removeItem(gfx)
            instance.positionChanged.disconnect(positionChanged)
            instance.focusChanged.disconnect(focusChanged)

        return gfx, disconnect
Example #9
0
    def _generate_indicators(self, **kwargs):  # pylint: disable=unused-argument
        """
        Paint arrow indicators of selected instructions and labels.
        """
        scene = self.scene()
        for item in self._map_indicator_items:
            scene.removeItem(item)
        self._map_indicator_items.clear()

        for addr in list(self.disasm_view.infodock.selected_insns) + list(
                self.disasm_view.infodock.selected_labels):
            pos = self._get_pos_from_addr(addr)
            if pos is None:
                continue

            pos -= 1  # this is the top-left x coordinate of our arrow body (the rectangle)

            pen = QPen(Qt.yellow)
            brush = QBrush(Qt.yellow)
            item = QGraphicsRectItem(QRectF(pos, 0, 2, 10), parent=self)
            item.setPen(pen)
            item.setBrush(brush)
            item.setZValue(self.ZVALUE_INDICATOR)
            self._map_indicator_items.append(item)

            triangle = QPolygonF()
            triangle.append(QPointF(pos - 1, 10))
            triangle.append(QPointF(pos + 3, 10))
            triangle.append(QPointF(pos + 1, 12))
            triangle.append(QPointF(pos - 1, 10))
            item = QGraphicsPolygonItem(triangle, parent=self)
            item.setPen(pen)
            item.setBrush(brush)
            item.setZValue(self.ZVALUE_INDICATOR)
            self._map_indicator_items.append(item)
Example #10
0
def createItem(x, scene):
    rectItem = QGraphicsRectItem(QRectF(x + 40, 40, 120, 120))
    scene.addItem(rectItem)
    rectItem.setPen(QPen(Qt.black))
    rectItem.setBrush(Qt.gray)

    innerRectItem = QGraphicsRectItem(QRectF(x + 50, 50, 45, 100), rectItem)
    innerRectItem.setPen(QPen(Qt.black))
    innerRectItem.setBrush(Qt.white)
    # scene.addItem(innerRectItem)

    ellipseItem = QGraphicsEllipseItem(QRectF(x + 105, 50, 45, 100), rectItem)
    ellipseItem.setPen(QPen(Qt.black))
    ellipseItem.setBrush(Qt.white)
    # scene.addItem(ellipseItem)
    return rectItem
Example #11
0
    def draw_bounding_box(self):
        #self.item = QGraphicsPixmapItem(QPixmap(self.df["image"].iloc[self.index]))
        #self.scene.addItem(self.item)
        start = self.image.mapToScene(self.start)
        end = self.image.mapToScene(self.end)
        self.startSceneLoc = start
        self.endSceneLoc = end

        df = self.page_df

        scale = (1 / self.zoom)
        self.x1 = start.x() * scale
        #self.x3 = end.x()*scale
        #Fixed x length
        self.x3 = self.x1 + 250 * scale

        self.y1 = start.y() * scale
        self.y3 = end.y() * scale
        df = df[(df.x1 > self.x1) & (df.x3 < self.x3) & (df.y1 > self.y1) &
                (df.y3 < self.y3)]
        print(u"x1:", self.x1, u" x3:", self.x3, u" y1:", self.y1, u" y3:",
              self.y3, u" Scale:", scale)
        print(u"Current image:", self.report[self.page_index],
              u" Current df image:", df.image.unique())
        print(df.word)
        self.bound_data_text = " ".join(df.word.to_list())

        diff_x = (self.x1 - self.x3) * self.zoom
        diff_y = (self.y1 - self.y3) * self.zoom

        rectItem = QGraphicsRectItem(start.x(), start.y(), -diff_x, -diff_y)
        self.scene.addItem(rectItem)

        self.start = None
        self.end = None
Example #12
0
    def drawTile(self, i, j):
        rect = QGraphicsRectItem(j * self.nPieceWidth, i * self.nPieceWidth,
                                 self.nPieceWidth, self.nPieceWidth)
        if i % 2 == j % 2:
            if self.selectCell[i][
                    j]:  # Selected cells only get the selection background color
                rect.setBrush(QBrush(self.cLightSquareColorSelected))
            elif self.focusCell[i][j]:
                if self.threatCell[i][j]:
                    rect.setBrush(QBrush(self.cLightSquareColorFocusDanger))
                else:
                    rect.setBrush(QBrush(self.cLightSquareColorFocus))
            else:  # If the cell has no focus, it also has no danger indication
                rect.setBrush(QBrush(self.cLightSquareColor))
        else:
            if self.selectCell[i][
                    j]:  # Selectd cells only get the selection background color
                rect.setBrush(QBrush(self.cDarkSquareColorSelected))
            elif self.focusCell[i][j]:
                if self.threatCell[i][j]:
                    rect.setBrush(QBrush(self.cDarkSquareColorFocusDanger))
                else:
                    rect.setBrush(QBrush(self.cDarkSquareColorFocus))
            else:  # If the cell has no focus, it also has no danger indication
                rect.setBrush(QBrush(self.cDarkSquareColor))

        rect.setCacheMode(QGraphicsItem.NoCache)
        self.addItem(rect)
Example #13
0
    def overlay_rect(self, color: int, x: int, y: int, w: int, h: int,
                     timeout: int, line_width: int):
        pen = QPen(decode_color(color))
        pen.setWidthF(max(1.0, line_width / 10))

        gfx = QGraphicsRectItem(x, y, w, h)
        gfx.setPen(pen)

        self._finalize_gfx(gfx, timeout)
Example #14
0
 def drawBox(self):
     x1 = self.start.x()
     y1 = self.start.y()
     x3 = self.end.x()
     y3 = self.end.y()
     diff_x = x3 - x1
     diff_y = y3 - y1
     rectItem = QGraphicsRectItem(x1, y1, diff_x, diff_y)
     #rectItem.setBrush(QBrush(Qt.green))
     self.scene.addItem(rectItem)
Example #15
0
 def __init__(self, *a, **kw):
     data = kw.pop("data")
     self.name = kw.pop("name")
     self.window = kw.pop("window")
     super().__init__(0, 0, 0, 0)
     self.setAcceptedMouseButtons(Qt.LeftButton)
     self.label = QGraphicsTextItem("", self)
     self.bottom_edge = QGraphicsRectItem(0, 0, 0, 0, self)
     self.bottom_edge.setBrush(QBrush("red", Qt.SolidPattern))
     self.update_visuals(data)
 def __init__(self):
     """Notification list graphics item.
     Used to show notifications for a ProjectItem
     """
     super().__init__()
     self.bg = QGraphicsRectItem(self.boundingRect(), self)
     bg_brush = QApplication.palette().brush(QPalette.ToolTipBase)
     self.bg.setBrush(bg_brush)
     self.bg.setFlag(QGraphicsItem.ItemStacksBehindParent)
     self.setFlag(QGraphicsItem.ItemIsSelectable, enabled=False)
     self.setZValue(2)
Example #17
0
 def _compute_max_zoom(self):
     # The max zoom is the one that fits one item into the view
     # We don't allow to zoom any further than this
     item = QGraphicsRectItem(0, 0, ProjectItemIcon.ITEM_EXTENT, 0)
     self.scene().addItem(item)
     self.scene().removeItem(item)
     item_scene_rect = item.boundingRegion(
         item.sceneTransform()).boundingRect()
     item_view_rect = self.mapFromScene(item_scene_rect).boundingRect()
     viewport_extent = min(self.viewport().width(),
                           self.viewport().height())
     return viewport_extent / item_view_rect.width()
Example #18
0
    def __init__(self, G):
        super().__init__()
        self.G = G
        #        self.setMinimunSize(400, 400)
        self.scale(1, -1)
        # AXIS
        self.axis_center = QGraphicsRectItem(-100, -100, 200, 200)
        self.axis_center.setPen(QPen(QColor("black")))
        self.axis_center.setBrush(QBrush(QColor("black")))
        self.axis_center.setZValue(5000)
        self.axis_x = QGraphicsRectItem(0, 0, 1000, 30)
        self.axis_x.setPen(QPen(QColor("red")))
        self.axis_x.setBrush(QBrush(QColor("red")))
        self.axis_x.setZValue(5000)
        self.axis_y = QGraphicsRectItem(0, 0, 30, 1000)
        self.axis_y.setPen(QPen(QColor("blue")))
        self.axis_y.setBrush(QBrush(QColor("blue")))
        self.axis_y.setZValue(5000)

        self.set_draw_axis(True)
        self.draw_axis()
Example #19
0
    def __init__(self, text=None, parent=None):
        super().__init__(parent)

        self._text = text or ""
        self._elided_text = text or ""
        self._elide_mode = Qt.ElideRight
        self._align_mode = Qt.AlignLeft
        self._max_width = None
        self._font = QFont()
        self._bounding_rect = QRectF()
        """Bounding and drawing rectangle. Determined automatically."""

        self.background = QGraphicsRectItem(self)
        self.background.setPen(Qt.NoPen)
        self.background.setFlag(QGraphicsItem.ItemStacksBehindParent)

        self.adjust()
Example #20
0
 def __init__(self, parent):
     """
     Args:
         parent (ProjectItemIcon): the parent item
     """
     super().__init__(parent)
     self._parent = parent
     rect_w = parent.rect().width()  # Parent rect width
     self.text_margin = 0.05 * rect_w
     self.bg = QGraphicsRectItem(self.boundingRect(), self)
     bg_brush = QApplication.palette().brush(QPalette.ToolTipBase)
     self.bg.setBrush(bg_brush)
     self.bg.setFlag(QGraphicsItem.ItemStacksBehindParent)
     self.setFlag(QGraphicsItem.ItemIsSelectable, enabled=False)
     font = self.font()
     font.setPointSize(parent.text_font_size)
     font.setBold(True)
     self.setFont(font)
     doc = self.document()
     doc.setDocumentMargin(0)
Example #21
0
    def __init__(self, entity_item):
        """Initializes item.

        Args:
            entity_item (spinetoolbox.widgets.graph_view_graphics_items.EntityItem): The parent item.
        """
        super().__init__(entity_item)
        self.entity_item = entity_item
        self._font = QApplication.font()
        self._font.setPointSize(11)
        self.setFont(self._font)
        self.bg = QGraphicsRectItem(self)
        self.bg_color = QGuiApplication.palette().color(
            QPalette.Normal, QPalette.ToolTipBase)
        self.bg_color.setAlphaF(0.8)
        self.bg.setBrush(QBrush(self.bg_color))
        self.bg.setPen(Qt.NoPen)
        self.bg.setFlag(QGraphicsItem.ItemStacksBehindParent)
        self.setFlag(QGraphicsItem.ItemIsSelectable, enabled=False)
        self.setAcceptHoverEvents(False)
Example #22
0
    def _generate_hover_region(self):
        """
        Paint the memory region indicator.
        """
        if self._map_hover_region_item:
            self.scene().removeItem(self._map_hover_region_item)
            self._map_hover_region_item = None

        mr = self._map_hover_region
        if mr is None:
            return

        pw = 1.0
        hpw = pw / 2
        pen = QPen(Qt.red)
        pen.setWidth(pw)
        r = self._get_region_rect(mr)
        r = r.marginsRemoved(QMarginsF(hpw, hpw, hpw, hpw))
        item = QGraphicsRectItem(r, parent=self)
        item.setPen(pen)
        item.setZValue(self.ZVALUE_HOVER)
        self._map_hover_region_item = item
Example #23
0
 def __init__(self):
     QWidget.__init__(self)
     self.layout = QVBoxLayout(self)
     rect = QRectF(0, 0, 800, 800)
     self.scene = QGraphicsScene(rect)
     item = Node()
     self.scene.addItem(item)
     item1 = Node()
     item1.setPos(QPoint(50, 50))
     self.scene.addItem(item1)
     item2 = QGraphicsRectItem(10, 10, 50, 50)
     self.scene.addItem(item2)
     line = Edge(item, item1)
     self.scene.addItem(line)
     self.view = NetworkView(self.scene, self)
     self.view.setCacheMode(QGraphicsView.CacheBackground)
     self.view.setViewportUpdateMode(
         QGraphicsView.BoundingRectViewportUpdate)
     print(item1.scenePos())
     print(item1.pos())
     self.layout.addWidget(self.view)
     self.setLayout(self.layout)
Example #24
0
	def __init__(self, parent: QWidget = None) -> None:
		"""
		Create a GraphicsView for Facile.
		:param parent: The widget to embed the graphics view into
		:type parent: QWidget
		:return: None
		:rtype: NoneType
		"""
		super(FacileGraphicsView, self).__init__(parent)

		# set flags
		self.setDragMode(QGraphicsView.ScrollHandDrag)
		self.setViewportUpdateMode(QGraphicsView.FullViewportUpdate)
		
		# show initial message
		scene = QGraphicsScene()
		box = QGraphicsRectItem(0, 0, 100, 100)
		box.setPen(QColor(Qt.transparent))
		box.setBrush(QColor(Qt.transparent))
		QGraphicsTextItem("Nothing to show here yet!", box)
		scene.addItem(box)
		
		self.setScene(scene)
Example #25
0
    QGraphicsRectItem,
    QWidget,
    QGraphicsSimpleTextItem,
    QGraphicsEllipseItem,
    QGraphicsPolygonItem,
)
from PySide2.QtGui import (QPen, QBrush, QPolygonF)
from PySide2.QtCore import (Qt, QRectF, QPoint, QPointF)

import sys

if __name__ == '__main__':
    app = QApplication(sys.argv)
    scene = QGraphicsScene(QRectF(-50, -50, 400, 200))

    rect = QGraphicsRectItem(scene.sceneRect().adjusted(1, 1, -1, -1))
    rect.setPen(QPen(Qt.red, 1))
    scene.addItem(rect)

    rectItem = QGraphicsRectItem(QRectF(-25, 25, 200, 40))
    rectItem.setPen(QPen(Qt.red, 3, Qt.DashDotLine))
    rectItem.setBrush(Qt.gray)
    scene.addItem(rectItem)
    print(f'Rect Pos: {rectItem.pos()}')

    textItem = QGraphicsSimpleTextItem("Foundation of Qt")
    scene.addItem(textItem)
    print(f'Text Pos: {textItem.pos()}')
    textItem.setPos(50, 0)
    print(f'Text Pos: {textItem.pos()}')
Example #26
0
 def _init_bg(self):
     self._bg = QGraphicsRectItem(self.boundingRect(), self)
     self._bg.setPen(Qt.NoPen)
Example #27
0
    def _create_line_indicator(self, addr, item_map, color=Qt.yellow, show_frontier=False, z=None, z_frontier=None):
        """
        Generate a cursor at a given address.
        """
        pos_x = self._get_pos_from_addr(addr)
        if pos_x is None:
            return

        pen = QPen(color)
        brush = QBrush(color)
        height = self.height

        tri_width = 7
        tri_height = 4

        pos_x = int(pos_x - tri_width / 2)  # Center drawing
        center = pos_x + int(tri_width / 2)
        pos_y = 0
        frontier_width = int(0.15 * max(self.width, self.height))

        if show_frontier:
            # Draw frontier gradients
            r = QRectF(center - frontier_width, pos_y, frontier_width, height)
            bg = QLinearGradient(r.topLeft(), r.topRight())
            color = Qt.red
            top_color = QColor(color)
            top_color.setAlpha(0)
            bg.setColorAt(0, top_color)
            bottom_color = QColor(color)
            bottom_color.setAlpha(180)
            bg.setColorAt(1, bottom_color)

            i = QGraphicsRectItem(r, parent=self)
            i.setPen(Qt.NoPen)
            i.setBrush(bg)
            if z_frontier is not None:
                i.setZValue(z_frontier)
            item_map.append(i)

            r = QRectF(center, pos_y, frontier_width, height)
            bg = QLinearGradient(r.topLeft(), r.topRight())
            color = Qt.blue
            top_color = QColor(color)
            bg.setColorAt(0, top_color)
            bottom_color = QColor(color)
            bottom_color.setAlpha(0)
            bg.setColorAt(1, bottom_color)

            i = QGraphicsRectItem(r, parent=self)
            i.setPen(Qt.NoPen)
            i.setBrush(bg)
            if z_frontier is not None:
                i.setZValue(z_frontier)
            item_map.append(i)

        # Draw line
        i = QGraphicsLineItem(center, 0, center, height, parent=self)
        i.setPen(pen)
        if z is not None:
            i.setZValue(z)
        item_map.append(i)

        # Draw top and bottom triangles
        t = QPolygonF()
        t.append(QPointF(pos_x, pos_y))
        t.append(QPointF(pos_x + tri_width - 1, pos_y))
        t.append(QPointF(center, pos_y + tri_height - 1))
        t.append(QPointF(pos_x, pos_y))

        pos_y += height - 1
        b = QPolygonF()
        b.append(QPointF(pos_x, pos_y))
        b.append(QPointF(center, pos_y - tri_height + 1))
        b.append(QPointF(pos_x + tri_width - 1, pos_y))
        b.append(QPointF(pos_x, pos_y))

        for i in [QGraphicsPolygonItem(t, parent=self),
                  QGraphicsPolygonItem(b, parent=self)]:
            i.setPen(pen)
            i.setBrush(brush)
            if z is not None:
                i.setZValue(z)
            item_map.append(i)
Example #28
0
    def _generate_map_items(self, **kwargs):  # pylint: disable=unused-argument
        """
        Generate the feature map items (memory region blocks, separating lines, etc).
        """
        cfb = self.instance.cfb.am_obj
        if cfb is None:
            return

        for item in self._map_items:
            self.scene().removeItem(item)
        self._map_items.clear()
        self._calculate_memory_region_offsets()

        func_color = Conf.feature_map_color_regular_function
        data_color = Conf.feature_map_color_data
        unknown_color = Conf.feature_map_color_unknown
        delimiter_color = Conf.feature_map_color_delimiter
        offset = 0
        current_region = None

        for addr, obj in cfb.ceiling_items():
            if obj.size is None:
                continue

            # Are we in a new region?
            new_region = False
            if current_region is None or not current_region.addr <= addr < current_region.addr + current_region.size:
                try:
                    current_region_addr = next(
                        self._addr_to_region.irange(maximum=addr,
                                                    reverse=True))
                except StopIteration:
                    # FIXME: it's not within any of the known regions
                    # we should fix this in the future. for now, let's make sure it does not crash
                    continue
                current_region = self._addr_to_region[current_region_addr]
                new_region = True

            if new_region:
                r = self._get_region_rect(current_region)
                pos = r.topLeft().x()
                pen = QPen(delimiter_color)
                hpw = pen.width() / 2
                item = QGraphicsLineItem(pos,
                                         hpw,
                                         pos,
                                         self._height - hpw,
                                         parent=self)
                item.setPen(pen)
                item.setZValue(self.ZVALUE_SEPARATOR)
                self._map_items.append(item)

            # Clip item to possibly truncated region size
            adjusted_region_size = self._get_adjusted_region_size(
                current_region)
            adjusted_size = min(
                obj.size, current_region.addr + adjusted_region_size - addr)
            if adjusted_size <= 0:
                # Item falls outside truncated region. Drop the item.
                continue

            r = self._get_offset_size_rect(offset, adjusted_size)
            offset += adjusted_size

            if isinstance(obj, MemoryData):
                brush = QBrush(data_color)
            elif isinstance(obj, Block):
                # TODO: Check if it belongs to a function or not
                brush = QBrush(func_color)
            else:
                brush = QBrush(unknown_color)

            item = QGraphicsRectItem(r, parent=self)
            item.setPen(Qt.NoPen)
            item.setBrush(brush)
            self._map_items.append(item)
Example #29
0
    ellipseItem.setBrush(Qt.white)
    # scene.addItem(ellipseItem)
    return rectItem


def timerHandler():
    global sec
    item2.setTransformOriginPoint(300, 100)
    item2.setRotation(sec)
    sec += 1


if __name__ == '__main__':
    app = QApplication(sys.argv)
    scene = QGraphicsScene(QRectF(0, 0, 1000, 200))
    scene.addItem(QGraphicsRectItem(scene.sceneRect()))

    item1 = createItem(0, scene)
    sec = 0
    item2 = createItem(200, scene)

    timer = QTimer()
    timer.setInterval(1000)
    timer.timeout.connect(timerHandler)
    # item2.mapToScene(300, 100)
    # # item2.translate(300, 100)
    item2.setTransformOriginPoint(300, 100)
    item2.setRotation(30)
    # # item2.translate(-300, -100)
    # item2.mapToScene(-300, -100)