예제 #1
0
파일: task8.py 프로젝트: ZayJob/OS-and-N
    def draw_event(self):
        rnd = random.Random()
        if not self.isDrawn:

            item = QtWidgets.QGraphicsEllipseItem(*self.get_params())
            self.graphicsScene.addItem(item)

            item = QtWidgets.QGraphicsEllipseItem(*self.get_params())
            self.graphicsScene.addItem(item)

            item = QtWidgets.QGraphicsEllipseItem(*self.get_params())
            item.setStartAngle(90)
            item.setSpanAngle(random.randrange(10, 100))
            self.graphicsScene.addItem(item)

            item = QtWidgets.QGraphicsEllipseItem(*self.get_params())
            item.setStartAngle(90 * 20)
            item.setSpanAngle(random.randrange(10, 100) * 20)
            self.graphicsScene.addItem(item)

            item = QtWidgets.QGraphicsRectItem(*self.get_params())
            self.graphicsScene.addItem(item)

            item = QtWidgets.QGraphicsRectItem(*self.get_params())
            self.graphicsScene.addItem(item)

            item = QtWidgets.QGraphicsLineItem()
            item.setLine(
                random.randrange(
                    0,
                    self.graphicsView.frameGeometry().width() - MAX_WIDTH),
                random.randrange(
                    0,
                    self.graphicsView.frameGeometry().height() - MAX_HEIGHT),
                random.randrange(
                    0,
                    self.graphicsView.frameGeometry().width() - MAX_WIDTH),
                random.randrange(
                    0,
                    self.graphicsView.frameGeometry().height() - MAX_HEIGHT))
            self.graphicsScene.addItem(item)

            item = QtWidgets.QGraphicsLineItem()
            item.setLine(
                random.randrange(
                    0,
                    self.graphicsView.frameGeometry().width() - MAX_WIDTH),
                random.randrange(
                    0,
                    self.graphicsView.frameGeometry().height() - MAX_HEIGHT),
                random.randrange(
                    0,
                    self.graphicsView.frameGeometry().width() - MAX_WIDTH),
                random.randrange(
                    0,
                    self.graphicsView.frameGeometry().height() - MAX_HEIGHT))
            self.graphicsScene.addItem(item)
            self.isDrawn = True
예제 #2
0
    def __init__(self, parent):
        super(VideoRender, self).__init__()
        self.main_window = parent
        self.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter)
        self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.size_adjusted = False
        self.ratio = 1
        self.setAcceptDrops(True)

        # Config QGraphics objects
        self.scene = QtWidgets.QGraphicsScene(self)
        self.setScene(self.scene)

        # Frame
        self.frame = None
        self.scene_frame = QtWidgets.QGraphicsPixmapItem()

        # Current Detection Selection
        self.init_point = QtCore.QPoint()
        self.end_point = QtCore.QPoint()
        self.drawing = False
        self.current_selection = QtWidgets.QGraphicsRectItem()
        self.brush_current = QtGui.QBrush(QtGui.QColor(10, 10, 100, 120))

        # Detections
        self.detection = []
        self.detection_objects = []  # List of GraphicsRectItem objects
        self.brush_detection = QtGui.QBrush(QtGui.QColor(100, 10, 10, 120))

        self.init()
예제 #3
0
    def __init__(self,
                 frame: np.array = None,
                 show=None,
                 show_box=True,
                 *args,
                 **kwargs):
        super(ConfMapsPlot, self).__init__(*args, **kwargs)
        self.frame = frame
        self.show_box = show_box

        self.rect = QtCore.QRectF(0, 0, self.frame.shape[1],
                                  self.frame.shape[0])

        if self.show_box:
            QtWidgets.QGraphicsRectItem(self.rect, parent=self).setPen(
                QtGui.QPen("yellow"))

        for channel in range(self.frame.shape[2]):
            if show is None or channel in show:
                color_map = h5_colors[channel % len(h5_colors)]

                # Add QGraphicsPixmapItem as child object
                ConfMapPlot(confmap=self.frame[..., channel],
                            color=color_map,
                            parent=self)
예제 #4
0
 def columns_setup(self):
     '''
     only works in three conditions:
         1. starting app
         2. spin amount
         3. state 2 → 0, press btnSort when it's text is new sort
     functions:
         1. reset display labels and their correspoing class variables
         2. reset scene and render it again with correspoing variables
     '''
     # reset label
     self.ui.labTime.setText('0')
     self.ui.labComparisons.setText('0')
     # reset columns
     self.scene.clear()
     self.col_heights.clear()
     self.col_items.clear()
     # compute width of all columns
     col_width = self.scene_width / self.col_amount
     # create heights for all columns in scene
     height_increment = self.scene_height / self.col_amount
     height = 0
     for i in range(self.col_amount):
         height += height_increment
         self.col_heights.append(height)
     # shuffle heights
     random.shuffle(self.col_heights)
     # apply columns to scene
     xpos = 0
     for i in range(self.col_amount):
         ypos = self.scene_height - self.col_heights[i]
         rect_item = QtWidgets.QGraphicsRectItem()
         # column location in scene
         rect_item.setRect(xpos, ypos, col_width, self.col_heights[i])
         # column background color
         rect_item.setBrush(QtGui.QBrush(QtGui.Qt.red))
         # column border width
         if self.col_amount <= 200:
             rect_item.setPen(QtGui.QPen(QtGui.Qt.black, 2))
         elif 200 < self.col_amount <= 300:
             rect_item.setPen(QtGui.QPen(QtGui.Qt.black, 1))
         else:
             rect_item.setPen(QtGui.Qt.NoPen)
         # add item to scene
         self.scene.addItem(rect_item)
         self.col_items.append(rect_item)
         # update xpos
         xpos += col_width
예제 #5
0
    def __init__(self, *args, **kwargs):
        self._widget_size = 200
        self._pen_width = 4
        self._box_size = None
        self._scale = None

        box_pen = QtGui.QPen(QtGui.QColor("blue"), self._pen_width)
        box_pen.setCosmetic(True)

        self.box = QtWidgets.QGraphicsRectItem()
        self.box.setPen(box_pen)

        super(ReceptiveFieldImageWidget, self).__init__(*args, **kwargs)

        self.setFixedSize(self._widget_size, self._widget_size)
        self.scene.addItem(self.box)
예제 #6
0
    def setupScene(self):
        self.m_scene.setSceneRect(-300, -200, 600, 460)

        linearGrad = QtGui.QLinearGradient(QtCore.QPointF(-100, -100),
                QtCore.QPointF(100, 100))
        linearGrad.setColorAt(0, QtGui.QColor(255, 255, 255))
        linearGrad.setColorAt(1, QtGui.QColor(192, 192, 255))
        self.setBackgroundBrush(linearGrad)

        radialGrad = QtGui.QRadialGradient(30, 30, 30)
        radialGrad.setColorAt(0, QtCore.Qt.yellow)
        radialGrad.setColorAt(0.2, QtCore.Qt.yellow)
        radialGrad.setColorAt(1, QtCore.Qt.transparent)

        pixmap = QtGui.QPixmap(60, 60)
        pixmap.fill(QtCore.Qt.transparent)

        painter = QtGui.QPainter(pixmap)
        painter.setPen(QtCore.Qt.NoPen)
        painter.setBrush(radialGrad)
        painter.drawEllipse(0, 0, 60, 60)
        painter.end()

        self.m_lightSource = self.m_scene.addPixmap(pixmap)
        self.m_lightSource.setZValue(2)

        for i in range(-2, 3):
            for j in range(-2, 3):
                if (i + j) & 1:
                    item = QtWidgets.QGraphicsEllipseItem(0, 0, 50, 50)
                else:
                    item = QtWidgets.QGraphicsRectItem(0, 0, 50, 50)

                item.setPen(QtGui.QPen(QtCore.Qt.black, 1))
                item.setBrush(QtGui.QBrush(QtCore.Qt.white))

                effect = QtWidgets.QGraphicsDropShadowEffect(self)
                effect.setBlurRadius(8)
                item.setGraphicsEffect(effect)
                item.setZValue(1)
                item.setPos(i * 80, j * 80)
                self.m_scene.addItem(item)
                self.m_items.append(item)
예제 #7
0
 def draw_creatures(self, creature_or_predator, creature):
     """Fill the cell at grid location (x, y)
     """
     x = creature.x_position
     y = creature.y_position
     world_left = 0
     world_top = 0
     world_right = self.simulation_window_groupbox.size().width()
     world_bottom = self.simulation_window_groupbox.size().height()
     creature_x_in_world = int(((world_right - world_left) * x) +
                               world_left)
     creature_y_in_world = int(((world_bottom - world_top) * y) + world_top)
     item = QtWidgets.QGraphicsRectItem(creature_x_in_world,
                                        creature_y_in_world, 10, 10)
     if creature_or_predator:
         item.setBrush(QtGui.QBrush(QtCore.Qt.blue))
     else:
         item.setBrush(QtGui.QBrush(QtCore.Qt.red))
     self.scene.addItem(item)
예제 #8
0
 def update_frame(self):
     """"Update the frame and all the detection squares"""
     self.scene.clear()
     # Display image/frame
     if self.frame:
         self.scene_frame = QtWidgets.QGraphicsPixmapItem(self.frame)
         self.scene.addItem(self.scene_frame)
         self.fitInView(self.scene_frame)
     # Draw new detection square
     if self.drawing:
         self.current_selection = QtWidgets.QGraphicsRectItem(
             QtCore.QRect(self.init_point, self.end_point))
         self.current_selection.setBrush(self.brush_current)
         self.scene.addItem(self.current_selection)
     # Detect all objects according to the Track List
     self.detection_objects = []
     for element in self.detection:
         d = CustomWidget.GraphicsRectItem(element.rect(self.ratio))
         d.setBrush(self.brush_detection)
         d.set_edit_mode(self.main_window.controller.edit_mode)
         self.scene.addItem(d)
         self.detection_objects.append(d)
예제 #9
0
            if self.handle_selected is None or handle == self.handle_selected:
                painter.drawEllipse(rect)


if __name__ == "__main__":
    app = qtw.QApplication(sys.argv)
    main = qtw.QGraphicsView()
    main.setFixedSize(700, 700)
    main.setAlignment(qtc.Qt.AlignTop | qtc.Qt.AlignLeft)  # start at 0, 0
    main.setSizePolicy(qtw.QSizePolicy.Fixed, qtw.QSizePolicy.Fixed)
    main.setHorizontalScrollBarPolicy(qtc.Qt.ScrollBarAlwaysOff)
    main.setVerticalScrollBarPolicy(qtc.Qt.ScrollBarAlwaysOff)
    # main.setSceneRect(0, 0, 1000, 1000)
    # main.setFixedSize(1000, 1000)

    rect = [0, 0, 1, 1]
    scene = VideoBufferScene()
    item = qtw.QGraphicsRectItem(0, 0, 500, 500)
    scene.addItem(item)

    rect2 = [0.1, 0.2, 1, 1]
    item2 = GraphicsRectItem(0, 0, *rect2, 300, 300)
    scene.addItem(item2)

    # scene.rect_changed.connect(lambda packet: print(packet.data))

    main.setScene(scene)
    main.show()

    sys.exit(app.exec_())
예제 #10
0
        myPath.arcTo(QtCore.QRectF(50, -25, 50, 50), 90, -90)
        myPath.closeSubpath()
        painter.drawPath(myPath)
        

def timerHandler(): 
    increment = 15
    blade1.setAngle(blade1.angle+increment)
    blade2.setAngle(blade2.angle+increment)
    blade3.setAngle(blade3.angle+increment)    
    view.viewport().repaint()

if __name__ == '__main__':
	app = QtWidgets.QApplication(sys.argv)
	scene = QtWidgets.QGraphicsScene(QtCore.QRectF(-100, -100, 200, 200))
	scene.addItem(QtWidgets.QGraphicsRectItem(scene.sceneRect()))	

	centerItem = QtWidgets.QGraphicsEllipseItem(QtCore.QRectF(-10, -10, 20, 20))	
	centerItem.setPen(QtGui.QPen(QtCore.Qt.darkBlue))
	centerItem.setBrush(QtCore.Qt.green)
	centerItem.setZValue(2)
	scene.addItem(centerItem)

	circle1 = QtWidgets.QGraphicsEllipseItem(QtCore.QRectF(-75, -75, 150, 150))
	circle1.setPen(QtGui.QPen(QtCore.Qt.black))
	circle1.setBrush(QtCore.Qt.NoBrush)
	# scene.addItem(circle1)

	blade1 = FanBlade()	
	scene.addItem(blade1)
    kineticPix = QtGui.QPixmap(':/images/kinetic.png')
    bgPix = QtGui.QPixmap(':/images/Time-For-Lunch-2.jpg')

    scene = QtWidgets.QGraphicsScene(-350, -350, 700, 700)

    items = []
    for i in range(64):
        item = Pixmap(kineticPix)
        item.pixmap_item.setOffset(-kineticPix.width() / 2,
                                   -kineticPix.height() / 2)
        item.pixmap_item.setZValue(i)
        items.append(item)
        scene.addItem(item.pixmap_item)

    # Buttons.
    buttonParent = QtWidgets.QGraphicsRectItem()
    ellipseButton = Button(QtGui.QPixmap(':/images/ellipse.png'), buttonParent)
    figure8Button = Button(QtGui.QPixmap(':/images/figure8.png'), buttonParent)
    randomButton = Button(QtGui.QPixmap(':/images/random.png'), buttonParent)
    tiledButton = Button(QtGui.QPixmap(':/images/tile.png'), buttonParent)
    centeredButton = Button(QtGui.QPixmap(':/images/centered.png'),
                            buttonParent)

    ellipseButton.setPos(-100, -100)
    figure8Button.setPos(100, -100)
    randomButton.setPos(0, 0)
    tiledButton.setPos(-100, 100)
    centeredButton.setPos(100, 100)

    scene.addItem(buttonParent)
    buttonParent.setTransform(QtGui.QTransform().scale(0.75, 0.75))
예제 #12
0
	def buildBackgroundRect(self):
		"""return a single qrect below all other scene items with a checker pattern
		"""
		rect = QtWidgets.QGraphicsRectItem(self.sceneRect())

		rect.setBrush()
예제 #13
0
def main():		
	app = QtWidgets.QApplication(sys.argv)
	margin = 10
	scene = QtWidgets.QGraphicsScene(QtCore.QRectF(-200-margin/2, -200-margin/2, 400+margin, 400+margin))
	
	rect = QtWidgets.QGraphicsRectItem(scene.sceneRect().adjusted(1, 1, -1, -1))
	rect.setPen(QtGui.QPen(QtCore.Qt.red, 1))
	# scene.addItem(rect)
	
	radius = 200
	diameter = radius * 2	
	ellipseItem = QtWidgets.QGraphicsEllipseItem(QtCore.QRectF(-200, -200, diameter, diameter))
	ellipseItem.setPen(QtGui.QPen(QtCore.Qt.darkBlue))
	# ellipseItem.setBrush(QtCore.Qt.blue)
	scene.addItem(ellipseItem)	
	
	origin = QtCore.QPointF(0, 0)
	p1 = None
	p2 = None
	angle = 270
	line1 = None
	line2 = None
	conePath = QtGui.QPainterPath()

	def drawLine():
		nonlocal  p1
		nonlocal angle
		nonlocal line1
		nonlocal line2
		nonlocal origin		

		if p1 == None:
			angle2 = angle + 20

			p1 = QtCore.QPointF(radius * math.cos(angle * math.pi / 180.0),
				radius * math.sin(angle * math.pi / 180.0))
			p2 =  QtCore.QPointF(radius * math.cos(angle2 * math.pi / 180.0),
				radius * math.sin(angle2 * math.pi / 180.0))

			line1 = QtWidgets.QGraphicsLineItem(p1.x(), p1.y(), 0, 0)
			line2 = QtWidgets.QGraphicsLineItem(0, 0, p2.x(), p2.y())
			
			# conePath.moveTo(line1)
			# conePath.lineTo(line2)
			# conePath.closeSubpath()
			# scene.addPath(conePath)
			
			scene.addItem(line1)
			scene.addItem(line2)
		else:
			scene.removeItem(line1)
			scene.removeItem(line2)
			# scene.removeItem(conePath)

			angle += 1
			angle2 = angle + 20

			p1 = QtCore.QPointF(radius * math.cos(angle * math.pi / 180.0),
				radius * math.sin(angle * math.pi / 180.0))
			p2 =  QtCore.QPointF(radius * math.cos(angle2 * math.pi / 180.0),
				radius * math.sin(angle2 * math.pi / 180.0))

			line1 = QtWidgets.QGraphicsLineItem(p1.x(), p1.y(), 0, 0)
			line2 = QtWidgets.QGraphicsLineItem(0, 0, p2.x(), p2.y())

			# conePath.moveTo(line1)
			# conePath.lineTo(line2)
			# conePath.closeSubpath()
			# scene.addPath(conePath)

			scene.addItem(line1)
			scene.addItem(line2)		

	view = QtWidgets.QGraphicsView()
	view.setRenderHint(QtGui.QPainter.Antialiasing)
	view.setScene(scene)
	view.show()

	# drawLine()

	timer = QtCore.QTimer()
	timer.setInterval(100)
	timer.timeout.connect(drawLine)
	timer.start()

	sys.exit(app.exec_())
예제 #14
0
    scene = QtWidgets.QGraphicsScene(
        QtCore.QRectF(0, 0, sceneWidth, sceneHeight))
    rect = scene.sceneRect()

    gridLines = list()
    drawGrid(sceneWidth, sceneHeight, scene)

    line1 = QtWidgets.QGraphicsLineItem(sceneWidth / 2, 0, sceneWidth / 2,
                                        sceneHeight)
    line1.setPen(QtGui.QPen(QtCore.Qt.black, 2))
    scene.addItem(line1)

    line2 = QtWidgets.QGraphicsLineItem(0, sceneHeight / 2, sceneWidth,
                                        sceneHeight / 2)
    line2.setPen(QtGui.QPen(QtCore.Qt.red, 2))
    scene.addItem(line2)

    line3 = QtWidgets.QGraphicsLineItem(-50, -50, sceneWidth, sceneHeight)
    line3.setPen(QtGui.QPen(QtCore.Qt.blue, 2))
    line3.setFlag(QtWidgets.QGraphicsItem.ItemClipsChildrenToShape, True)
    scene.addItem(line3)

    scene.addItem(QtWidgets.QGraphicsRectItem(rect))
    # Create a graphics view
    view = QtWidgets.QGraphicsView()
    view.setScene(scene)
    view.show()

    sys.exit(app.exec_())