예제 #1
0
    def visualize(self):
        """
        called when user clicks draw lsystem. This visualizes the lsystem to allow setup
        before the actual lsystification takes place
        """
        self.getdata()
        self.run_lsystem()

        old_group = self.layersModel.itemFromIndex(
            self.parent.layersList.currentIndex()).get_graphics_items_group()
        if old_group:
            self.parent.scene.removeItem(old_group)

        group = QGraphicsItemGroup()
        path = QPainterPath()
        for idx, point in enumerate(
                self.lsysteminterpreter.globalstate["pts"]):
            x = point[0][0][0]
            y = point[0][1][0]
            direction = point[1]
            x = x * self.xscale + self.xoffs
            y = y * self.yscale + self.yoffs
            if idx == 0:
                path.moveTo(x, y)
            else:
                path.lineTo(x, y)
        item = QGraphicsPathItem(path)
        pen = QPen()
        pen.setWidth(self.strokeWidth)
        item.setPen(pen)
        group.addToGroup(item)
        self.addNewGraphicsItems(group)
예제 #2
0
    def imgInit(self):
        self.cv_img = cv2.imread(
            os.path.join(sampleDataPath, "color_filter_test.png"))

        self.frameBuffer = Queue()
        self.frameBufferItemGroup = QGraphicsItemGroup()
        self.frameBufferItemGroup.hide()
        self.inputPixmapRenderScene = QGraphicsScene()
        self.inputPixmapRenderScene.addItem(self.frameBufferItemGroup)

        self.inputScene = QGraphicsScene()
        self.inputGraphicsView.setScene(self.inputScene)
        self.inputGraphicsView.resizeEvent = self.graphicsViewResized
        # self.inputScene.addItem(self.frameBufferItemGroup)

        qimg = misc.cvMatToQImage(self.cv_img)
        self.inputPixmap = QPixmap.fromImage(qimg)
        self.inputPixmapItem = QGraphicsPixmapItem(self.inputPixmap)
        self.inputScene.addItem(self.inputPixmapItem)

        self.inputGraphicsView.mousePressEvent = self.inputGraphicsViewMousePressEvent
        self.inputGraphicsView.mouseMoveEvent = self.inputGraphicsViewMouseMoveEvent
        self.inputGraphicsView.mouseReleaseEvent = self.inputGraphicsViewMouseReleaseEvent
        self.inputGraphicsView.keyPressEvent = self.inputGraphicsViewKeyPressEvent
        self.inputGraphicsView.keyReleaseEvent = self.inputGraphicsViewKeyReleaseEvent
        self.inputGraphicsView.wheelEvent = self.inputGraphicsViewwheelEvent
        #self.inputGraphicsView.focusInEvent = self.inputGraphicsViewfocusInEvent
        self.inputGraphicsView.viewport().installEventFilter(self)

        self.inputGraphicsView.setMouseTracking(True)
        self.overlayScene = QGraphicsScene()
        self.inputGraphicsView.setOverlayScene(self.overlayScene)
예제 #3
0
 def makeCoords(self):
     """ draws Coordinates """
     xLabels = "ABCDEFGHIKLMNOPQRSTUVWXYZ"
     yLabels = list(range(1, 26))
     botGrid = []
     leftGrid = []
     # generate pixel coordinates grids
     for n in range(self.board.size):
         (xBot, yBot) = self.grid[self.board.size - 1][n]
         yBot += self.baseWidth * 0.4 / self.baseRectRatio
         xBot -= self.baseWidth * 0.1
         botGrid.append((xBot, yBot))
         (xLeft, yLeft) = self.grid[n][0]
         xLeft -= self.baseWidth * 1.2
         yLeft -= self.baseWidth * 0.3 / self.baseRectRatio
         leftGrid.append((xLeft, yLeft))
     # generate Text items and add them to group
     self.coordGroup = QGraphicsItemGroup()
     for n in range(self.board.size):
         leftText = QGraphicsSimpleTextItem(str(yLabels[n]))
         leftText.setPos(*leftGrid[n])
         self.coordGroup.addToGroup(leftText)
         bottomText = QGraphicsSimpleTextItem(xLabels[n])
         bottomText.setPos(*botGrid[n])
         self.coordGroup.addToGroup(bottomText)
     # draw coordinates and update visibility according to self.showCoords
     self.scene.addItem(self.coordGroup)
     self.updateCoords()
예제 #4
0
    def mouseMoveEvent(self, event, image_item):
        if self._aiming:
            if self._helpLines is not None and self._helpLines.scene(
            ) is not None:
                self._scene.removeItem(self._helpLines)

            self._helpLines = QGraphicsItemGroup()
            group = self._helpLines

            verticalHelpLine = QGraphicsLineItem(event.scenePos().x(), 0,
                                                 event.scenePos().x(),
                                                 self._scene.height())
            horizontalHelpLine = QGraphicsLineItem(0,
                                                   event.scenePos().y(),
                                                   self._scene.width(),
                                                   event.scenePos().y())

            horizontalHelpLine.setPen(self._helpLinesPen)
            verticalHelpLine.setPen(self._helpLinesPen)

            group.addToGroup(verticalHelpLine)
            group.addToGroup(horizontalHelpLine)

            self._scene.addItem(self._helpLines)
        else:
            if self._item is not None:
                assert self._init_pos is not None
                rect = QRectF(self._init_pos, event.scenePos()).normalized()
                self._item.setRect(rect)

        event.accept()
	def __init__(self, parentItem, segments, colour):
		QGraphicsItem.__init__(self, parent=parentItem)
		self.colour_name = colour
		self.shape = QPainterPath()
		self.labels = QGraphicsItemGroup(self)
		self.bbox = QRectF(0, 0, 0, 0)
		for (p1, p2), label in segments:
			lvect = QVector2D(p2 - p1)
			lpath = QPainterPath()
			m = TWY_line_margin
			l = lvect.length()
			plst = [QPointF(-m, 0), QPointF(-m/3, -m), QPointF(l + m/3, -m), QPointF(l + m, 0), QPointF(l + m/3, m), QPointF(-m/3, m)]
			lpath.addPolygon(QPolygonF(plst))
			lrot = QTransform()
			lrot.rotateRadians(atan2(lvect.y(), lvect.x()))
			lpath = lrot.map(lpath)
			lpath.translate(p1)
			self.shape.addPath(lpath)
			rect = QRectF(p1, p2).normalized()
			if label != None:
				self.labels.addToGroup(TaxiwayLabelItem(label, rect.center(), self))
			self.bbox |= rect
		self.shape.setFillRule(Qt.WindingFill)
		self.mouse_highlight = False
		self.labels.setVisible(False)
예제 #6
0
    def makeLines(self, image):
        # remove existing data on this layer
        self.removeOldGraphicsItems()

        group = QGraphicsItemGroup()

        sections = 4
        coordinates = []
        bounds = [
            self.parent.region1Linify.value(),
            self.parent.region2Linify.value(),
            self.parent.region3Linify.value(),
            self.parent.region3Linify.value()
        ]

        for y in range(0, image.height(), 4):
            drawing = False
            for linetype in range(sections):
                if linetype >= 1:
                    qt_y = y + linetype  # / sections
                    for x in range(image.width()):
                        grayvalue = qGray(image.pixel(x, y))
                        start_drawing = (grayvalue <
                                         bounds[linetype]) and not drawing
                        if start_drawing:
                            coordinates.append([[x, qt_y]])
                            drawing = True
                        stop_drawing = ((grayvalue >= bounds[linetype]) or
                                        (x == (image.width() - 1))) and drawing
                        if stop_drawing:
                            coordinates[-1].append([x, qt_y])
                            drawing = False

        group = QGraphicsItemGroup()
        for lineseg in coordinates:
            if len(lineseg) != 2 or len(lineseg[0]) != 2 or len(
                    lineseg[1]) != 2:
                print("Unexpected lineseg: ", lineseg)
            else:
                lineitem = QGraphicsLineItem(lineseg[0][0], lineseg[0][1],
                                             lineseg[1][0], lineseg[1][1])
                pen = QPen()
                pen.setWidth(1 / sections)
                lineitem.setPen(pen)
                group.addToGroup(lineitem)

        self.addNewGraphicsItems(group)
예제 #7
0
    def __init__(self, node, parent, background, border, text, x=0, y=0, offset=20):
        """
        Constructor for the node class.
        It generates all necessary variables and calls the draw function

        :param node: data node which it gets the data from
        :param parent: parent widget
        :param background: background color of the node
        :param border: border color for the node
        :param text: text color for the node
        :param x: x-position of the node
        :param y: y-position of the node
        :param offset: offset for the type to center it
        """
        super().__init__()

        self.typeOffset = offset

        self.node = node

        self.parent = parent

        self.threatEdge = None
        self.counterEdge = None
        self.defaultEdge = None

        self.childEdges = []
        self.parentEdges = []

        self.headerGroup = QGraphicsItemGroup()
        self.attributes = QGraphicsItemGroup()
        self.footerGroup = QGraphicsItemGroup()

        self.setFlag(QGraphicsItem.ItemIsMovable, True)
        self.setFlag(QGraphicsItem.ItemIsSelectable, True)

        self.attributesHeight = 0
        self.headerHeight = 0

        self.printHeader(background, border, text)
        self.printAttributes(background, border, text)
        self.printFooter(background, border, text)

        self.setAcceptDrops(True)

        self.setPos(x, y)
예제 #8
0
 def initUI(self, fnames):
     # Make QGraphicsScene
     self.scene = QGraphicsScene()
     # TODO = handle different image sizes.
     self.images = {}
     self.imageGItem = QGraphicsItemGroup()
     self.scene.addItem(self.imageGItem)
     self.updateImage(fnames)
     self.setBackgroundBrush(QBrush(Qt.darkCyan))
 def __init__(self, levels: List[int], parent=None):
     super().__init__(parent)
     self.levels = levels
     self.level_group = {}
     for level in levels:
         group = QGraphicsItemGroup(self)
         group.setVisible(False)
         self.level_group[level] = group
     self.visible_level = None
     self.setAcceptedMouseButtons(Qt.NoButton)
     self.setAcceptHoverEvents(False)
예제 #10
0
def build_tiles_level(level, tile_size, slide_helper: SlideHelper):
    level_size = slide_helper.get_level_size(level)
    tiles_rects = slice_rect(level_size, tile_size)
    tiles_graphics_group = QGraphicsItemGroup()
    downsample = slide_helper.get_downsample_for_level(level)
    for tile_rect in tiles_rects:
        item = TileGraphicsItem(tile_rect, slide_helper.slide_path, level,
                                downsample)
        item.moveBy(tile_rect[0], tile_rect[1])
        tiles_graphics_group.addToGroup(item)

    return tiles_graphics_group
예제 #11
0
 def initUI(self, fnames):
     # set background
     self.setStyleSheet("background: transparent")
     self.setBackgroundBrush(BackGrid())
     self.setRenderHint(QPainter.Antialiasing, True)
     self.setRenderHint(QPainter.SmoothPixmapTransform, True)
     # Make QGraphicsScene
     self.scene = QGraphicsScene()
     # TODO = handle different image sizes.
     self.images = {}
     self.imageGItem = QGraphicsItemGroup()
     self.scene.addItem(self.imageGItem)
     self.updateImage(fnames)
예제 #12
0
    def __init__(self):
        QGraphicsView.__init__(self)

        # Image is displayed as a QPixmap in a QGraphicsScene attached to this QGraphicsView.
        self.scene = QGraphicsScene()
        self.setScene(self.scene)
        self.rectgroup = QGraphicsItemGroup()
        self.linegroup = QGraphicsItemGroup()
        self._pixmapHandle = None
        self.canZoom = True
        self.canPan = True
        self.zoomStack = []
        self.aspectRatioMode = Qt.KeepAspectRatio
        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
        self.begin = QPoint()
        self.end = QPoint()
        self.helper_bool = False
        self.helper_bool2 = False

        self.rect = QGraphicsRectItem()
        self.line = QGraphicsLineItem()
예제 #13
0
 def __init__(self, minBrightness, maxBrightness, minRadius, maxRadius,
              minStepSize, maxStepSize, clipToBitmap, strokeWidth,
              imageWidth, imageHeight):
     self.group = QGraphicsItemGroup()
     self.minBrightness = minBrightness
     self.maxBrightness = maxBrightness
     self.minRadius = minRadius
     self.maxRadius = maxRadius
     self.minStepSize = minStepSize
     self.maxStepSize = maxStepSize
     self.clipToBitmap = clipToBitmap
     self.strokeWidth = strokeWidth
     self.width = imageWidth
     self.height = imageHeight
예제 #14
0
파일: game.py 프로젝트: spacejump163/ai2
    def __init__(self, color, group):
        super(Tank, self).__init__()
        self.graphics = QGraphicsItemGroup()
        self.body_graphics = TankGraphics(color)
        self.graphics.addToGroup(self.body_graphics)
        self.cannon_graphics = CannonGraphics(color)
        self.graphics.addToGroup(self.cannon_graphics)

        self.cannon_rotation = 0
        self.cannon_rotate_speed = 0
        self.group = group
        self.hp = 50

        self.fire_cd = 0
예제 #15
0
 def addToGroup(self, item, name):
     '''
     Määrittää saman ryhmänimen omaaville yhteisen ryhmän ja palauttaa sen
     '''
     if name.strip() == 'None':
         return None
     elif name not in self.groups:
         group = QGraphicsItemGroup()
         self.piirtoalusta.scene.addItem(group)
         group.setFlag(QGraphicsItem.ItemIsSelectable)
         group.setFlag(QGraphicsItem.ItemIsMovable)
         group.addToGroup(item)
         self.groups.update({name: group})
     else:
         group = self.groups[name]
         group.addToGroup(item)
예제 #16
0
    def __loadGraphicItem(self,
                          shapes,
                          images,
                          condition_variables=None,
                          default_color=Qt.blue):

        if not images:
            return ObjectGraphicsItem(shapes, color=default_color)

        gitem = QGraphicsItemGroup()

        for image in images:
            gitem.addToGroup(
                self.__loadGraphicItemImagePart(image, condition_variables))

        return gitem
예제 #17
0
def paint_screenshot_image(
        painter: QPainter,
        scene: QGraphicsScene,
        image_size: QSize,
        scene_rect: QRectF = QRectF(),
        transparent_background=False,
) -> QImage:
    # with elapsed_timer() as elapsed:
    painter.fillRect(QRect(QPoint(0, 0), image_size),
                     painter.background().color())
    scene_items = scene.items(scene_rect, Qt.IntersectsItemBoundingRect)
    only_leaf_items = [
        item for item in scene_items if len(item.childItems()) == 0
    ]
    item_parents = {}
    item_groups = {}
    for item in only_leaf_items:
        if item.group():
            item_groups[item] = item.group()
            item.group().setVisible(False)
        elif item.parentItem():
            item_parents[item] = item.parentItem()
            item.parentItem().setVisible(False)
    group_for_screenshot = QGraphicsItemGroup()
    for item in only_leaf_items:
        group_for_screenshot.addToGroup(item)
    scene.addItem(group_for_screenshot)
    group_for_screenshot.setVisible(True)
    # scene_items2 = scene.items(scene_rect, Qt.IntersectsItemBoundingRect)
    # print(scene_items2)
    # print("before render==========================================")
    rendered_size = scene_rect.size().scaled(QSizeF(image_size),
                                             Qt.KeepAspectRatio)
    dsize = QSizeF(image_size) - rendered_size
    top_left = QPointF(dsize.width() / 2, dsize.height() / 2)
    scene.render(painter, QRectF(top_left, rendered_size), scene_rect,
                 Qt.KeepAspectRatio)
    scene.destroyItemGroup(group_for_screenshot)

    for item in item_parents:
        parent = item_parents[item]
        item.setParentItem(parent)
        parent.setVisible(True)
    for item in item_groups:
        group = item_groups[item]
        group.addToGroup(item)
        group.setVisible(True)
예제 #18
0
    def __init__(self, parent=None):
        super().__init__(parent)
        self._invert = False
        self.homography_transform = None
        self.setBackgroundBrush(Qt.black)

        monitor_width = 3200
        monitor_height = 1800

        self.background_image = QGraphicsRectItem(0, 0, 1, 1)
        brush = QBrush()
        brush.setStyle(Qt.SolidPattern)
        brush.setColor(Qt.black)
        self.background_image.setBrush(brush)
        self.addItem(self.background_image)
        self.visible_group = QGraphicsItemGroup()
        self.visible_stimuli = []
예제 #19
0
 def __init__(self, minBrightness, maxBrightness, strength, detail,
              minStepSize, maxStepSize, clipToBitmap, strokeWidth,
              imageWidth, imageHeight):
     self.group = QGraphicsItemGroup()
     self.path = QPainterPath()
     self.minBrightness = minBrightness
     self.maxBrightness = maxBrightness
     self.strength = strength
     self.detail = detail
     self.minStepSize = minStepSize
     self.maxStepSize = maxStepSize
     self.clipToBitmap = clipToBitmap
     self.strokeWidth = strokeWidth
     self.width = imageWidth
     self.height = imageHeight
     self.prevPos = None
     self.disturbance_direction = 1
     self.previous_stepsize = 1
예제 #20
0
    def __init__(self):
        super(AMANDisplay, self).__init__()
        self.setGeometry(0, 0, 500, 600)
        self.setStyleSheet('background-color:#233370')
        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.scene = QGraphicsScene(0, 0, 500, 600)

        # Timeline boundaries
        pen = QPen(QColor('white'))
        brush = QBrush(QColor('#233370'))
        self.scene.addLine(220, 0, 220, 600, pen)
        self.scene.addLine(280, 0, 280, 600, pen)
        self.scene.addLine(0, 30, 500, 30, pen)

        timelinebox = self.scene.addRect(220, 30, 60, 540, pen, brush)
        timelinebox.setFlag(timelinebox.ItemClipsChildrenToShape, True)

        # Timeline scale
        self.timeline = QGraphicsItemGroup()
        self.timeline.setParentItem(timelinebox)
        self.timeticks = []
        for i in range(40):
            y = 15 * i
            w = 6
            if i % 5 == 0:
                w = 10
                self.timeticks.append(
                    self.scene.addText('%02d' % (40 - i), QFont('Courier',
                                                                10)))
                self.timeticks[-1].setPos(240, y - 10)
                self.timeticks[-1].setDefaultTextColor(QColor('white'))
                self.timeline.addToGroup(self.timeticks[-1])
            self.timeline.addToGroup(
                self.scene.addLine(220, y, 220 + w, y, pen))
            self.timeline.addToGroup(
                self.scene.addLine(280 - w, y, 280, y, pen))

        self.lrwy = self.scene.addText('18R', QFont('Arial', 20, 50))
        self.lrwy.setPos(1, 1)
        self.lrwy.setDefaultTextColor(QColor('white'))
        # Finalize
        self.setScene(self.scene)
        self.show()
예제 #21
0
    def printFooter(self, background, border, text):
        """
        Prints the footer for the threat node
        The footer contains two columns where the conjunction will start from

        :param background: background color of the node
        :param border: border color for the node
        :param text: text color for the node
        """
        self.threatBoxText = QGraphicsTextItem()
        self.threatBoxText.setFont(Configuration.font)
        self.threatBoxText.setDefaultTextColor(QColor(text))
        self.threatBoxText.setPlainText('T')

        self.counterBoxText = QGraphicsTextItem()
        self.counterBoxText.setFont(Configuration.font)
        self.counterBoxText.setDefaultTextColor(QColor(text))
        self.counterBoxText.setPlainText('C')

        self.threatBox = QGraphicsRectItem()
        self.counterBox = QGraphicsRectItem()

        self.threatBox.setBrush(QBrush(QColor(background)))
        self.counterBox.setBrush(QBrush(QColor(background)))

        self.threatBox.setPen(QPen(QColor(border), 2))
        self.counterBox.setPen(QPen(QColor(border), 2))

        self.footerGroup = QGraphicsItemGroup()

        self.footerGroup.addToGroup(self.threatBox)
        self.footerGroup.addToGroup(self.counterBox)
        self.footerGroup.addToGroup(self.threatBoxText)
        self.footerGroup.addToGroup(self.counterBoxText)

        self.threatBox.setRect(0, 0, 100, 20)
        self.counterBox.setRect(100, 0, 100, 20)

        self.threatBoxText.setPos(40, 0)
        self.counterBoxText.setPos(140, 0)

        self.footerGroup.setPos(self.x(), self.y() + self.headerHeight + self.attributesHeight)

        self.addToGroup(self.footerGroup)
예제 #22
0
    def toggleGrid(self):
        if self.gridSet:
            self.scene.removeItem(self.gridGroup)
            self.gridSet = False
        else: 
            self.gridGroup = QGraphicsItemGroup()  
            self.gridGroup.setZValue(common["gridZ"])
            self.scene.addItem(self.gridGroup)
            self.gridSet = True

            gs = common["gridSize"]
            pen = QPen(QColor(0,0,255))
         
            for i in range(1, int(common["ViewH"]/gs)):
                self.addLines(QGraphicsLineItem(0.0, gs*i,
                    float(common["ViewW"]), gs*i), pen)
  
            for j in range(1, int(common["ViewW"]/gs)):
                self.addLines(QGraphicsLineItem(gs*j, 0.0,
                    gs*j, float(common["ViewH"])), pen)
예제 #23
0
    def hatchify(self, image):
        """
        actual calculations
        :param image: bitmap to squigglify
        :return:
        """
        #print("image width = {0}, image height = {1}".format(image.width(), image.height()))
        ctimage = ImageOps.autocontrast(
            qimage_to_pil_image(image).convert("L"), 10)
        draw_contours = self.parent.includeContoursHatchify.checkState(
        ) == Qt.Checked
        draw_hatch = self.parent.includeHatchingHatchify.checkState(
        ) == Qt.Checked
        contour_simplify = self.parent.contourSimplificationHatchify.value()
        hatch_size = self.parent.hatchSizeHatchify.value()
        resolution = image.width()
        w, h = image.width(), image.height()
        aspect_ratio = h / w

        lines = []
        inv_resize_factor = (1, 1)
        if draw_contours:
            lines += self.getcontours(ctimage, contour_simplify)
        if draw_hatch:
            lines += self.hatch(ctimage, hatch_size)

        lines = self.sortlines(lines)

        self.removeOldGraphicsItems()
        group = QGraphicsItemGroup()
        for line in lines:
            path = QPainterPath()
            for point_idx, point in enumerate(line):
                if point_idx == 0:
                    path.moveTo(point[0], point[1])
                else:
                    path.lineTo(point[0], point[1])
            item = QGraphicsPathItem(path)
            group.addToGroup(item)

        self.addNewGraphicsItems(group)
예제 #24
0
    def on_actGroup_triggered(self):  # 组合
        cnt = len(self.scene.selectedItems())
        if cnt > 1:
            # group=self.scene.createItemGroup(self.scene.selectedItems())
            group = QGraphicsItemGroup()  # 创建组合
            self.scene.addItem(group)  # 组合添加到场景中

            for i in range(0, cnt):
                item = self.scene.selectedItems()[0]
                item.setSelected(False)  # 清除选择虚线框
                item.clearFocus()
                group.addToGroup(item)  # 添加到组合
            group.setFlags(QGraphicsItem.ItemIsMovable
                           | QGraphicsItem.ItemIsSelectable
                           | QGraphicsItem.ItemIsFocusable)

            self.view.frontZ = self.view.frontZ + 1
            group.setZValue(self.view.frontZ)
            # group.clearFocus()
            self.scene.clearSelection()
            group.setSelected(True)
예제 #25
0
파일: my0806.py 프로젝트: falomsc/pyqtStudy
    def on_qAction8_triggered(self):  # 组合
        items = self.scene.selectedItems()
        cnt = len(items)
        if cnt <= 1:
            return
        group = QGraphicsItemGroup()
        self.scene.addItem(group)
        for i in range(cnt):
            item = items[i]
            item.setSelected(False)
            item.clearFocus()
            group.addToGroup(item)

        group.setFlag(QGraphicsItem.ItemIsFocusable)
        group.setFlag(QGraphicsItem.ItemIsMovable)
        group.setFlag(QGraphicsItem.ItemIsSelectable)

        self.__frontZ += 1
        group.setZValue(self.__frontZ)
        self.scene.clearSelection()
        group.setSelected(True)