示例#1
0
    def __init__(self):
        super().__init__()

        self.setWindowTitle('loading_gif')
        self.resize(250, 120)

        self.scene = QGraphicsScene()
        self.setScene(self.scene)

        main_layout = QGraphicsLinearLayout(Qt.Horizontal)

        form = QGraphicsWidget()
        form.setLayout(main_layout)

        self.scene.addItem(form)

        for i in range(3):
            movie = QMovie("loading.gif")
            label_loading = QLabel()
            label_loading.setMovie(movie)
            movie.start()

            label_loading.setFrameStyle(QLabel.Box)
            label_loading.setAttribute(Qt.WA_OpaquePaintEvent)

            proxy_item = self.scene.addWidget(label_loading)
            main_layout.addItem(proxy_item)
示例#2
0
class SudokuWindow(QGraphicsView):
    """The main window that shows the Sudoku Board and the Menu Board.
    """
    def __init__(self):
        super().__init__()

        # Set up the Scene to manage the GraphicItems
        self.scene = QGraphicsScene(0, 0, 500, 600, self)
        self.setScene(self.scene)
        self.setSceneRect(self.scene.sceneRect())

        # Add the Boards to the form with a vertical layout
        self.form = QGraphicsWidget()
        self.layout = QGraphicsLinearLayout(Qt.Vertical)
        self.gameboard = board.GameBoard(400, 400)
        self.menuboard = board.MenuBoard(400, 80)
        self.layout.addItem(self.gameboard)
        self.layout.addItem(self.menuboard)
        self.layout.setSpacing(50)
        self.layout.setContentsMargins(50, 50, 50, 0)
        self.form.setLayout(self.layout)
        self.scene.addItem(self.form)

        # Setting the view
        self.setBackgroundBrush(QBrush(Qt.black))
        self.setRenderHint(QPainter.Antialiasing)
        self.fitInView(self.scene.sceneRect(), Qt.KeepAspectRatio)
        self.show()

        # Cross-Board signal connections
        self.gameboard.gridDrawn.connect(
            lambda: self.menuboard.show_children(True))
        self.gameboard.newGameSelected.connect(
            self.menuboard.set_difficulty_text)
        self.gameboard.sudokuDone.connect(self.menuboard.finish_the_game)
        self.menuboard.diff_display.notFocus.connect(
            self.gameboard.game_refocus)
        self.menuboard.diff_display.difficultySelected.connect(
            self.gameboard.new_game)

    def resizeEvent(self, event):
        """Reimplemented from QGraphicsView. Resize and maintain the board aspect ratio.
        """
        self.fitInView(self.scene.sceneRect(), Qt.KeepAspectRatio)
        super().resizeEvent(event)
    def __init__(self):
        super().__init__()

        self.scene = QGraphicsScene()
        self.scene.setSceneRect(0, 0, 200, 200)

        self.view = QGraphicsView()
        self.view.setRenderHint(QPainter.HighQualityAntialiasing)
        self.view.setAlignment(Qt.AlignLeft | Qt.AlignTop)
        self.view.setScene(self.scene)

        scene_layout = QGraphicsLinearLayout(Qt.Horizontal)

        form = QGraphicsWidget()
        form.setLayout(scene_layout)

        self.scene.addItem(form)

        self.main_layout = QHBoxLayout()
        self.main_layout.addWidget(self.view)
        self.setLayout(self.main_layout)

        self.rb0 = QPushButton("Hello")
        proxy_rb0 = self.scene.addWidget(self.rb0)
        scene_layout.addItem(proxy_rb0)

        self.rb1 = QPushButton("Hello")
        proxy_rb1 = self.scene.addWidget(self.rb1)
        proxy_rb1.setRotation(90)
        scene_layout.addItem(proxy_rb1)

        self.rb2 = QPushButton("Hello")
        proxy_rb2 = self.scene.addWidget(self.rb2)
        proxy_rb2.setRotation(180)
        scene_layout.addItem(proxy_rb2)

        self.rb3 = QPushButton("Hello")
        proxy_rb3 = self.scene.addWidget(self.rb3)
        proxy_rb3.setRotation(-166)
        scene_layout.addItem(proxy_rb3)
示例#4
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        width = Settings.NUM_BLOCKS_X * (Settings.WIDTH + 1)
        height = Settings.NUM_BLOCKS_Y * (Settings.HEIGHT + 1)
        self.setSceneRect(0, 0, height, width)
        self.setItemIndexMethod(QtWidgets.QGraphicsScene.NoIndex)

        layout = QGraphicsGridLayout()
        layout.setVerticalSpacing(0)
        layout.setHorizontalSpacing(0)

        form = QGraphicsWidget()
        form.setLayout(layout)

        for i in range(Settings.NUM_BLOCKS_X):
            layout.setRowSpacing(i, 0)
            layout.setRowMaximumHeight(i, Settings.HEIGHT)
            for j in range(Settings.NUM_BLOCKS_Y):
                layout.setColumnSpacing(j, 0)
                layout.setColumnMaximumWidth(j, Settings.WIDTH)
                if j - i == 1:
                    rect = RectangleWidget(QRectF(0, 0, Settings.WIDTH,
                                                  Settings.HEIGHT),
                                           path=True)
                elif j - i == 3:
                    rect = RectangleWidget(QRectF(0, 0, Settings.WIDTH,
                                                  Settings.HEIGHT),
                                           item=True)
                else:
                    rect = RectangleWidget(
                        QRectF(0, 0, Settings.WIDTH, Settings.HEIGHT))

                layout.addItem(rect, i, j)

        self.addItem(form)
示例#5
0
    maxSize = QSizeF(300, 100)

    a = createItem(minSize, prefSize, maxSize, "A")
    b = createItem(minSize, prefSize, maxSize, "B")
    c = createItem(minSize, prefSize, maxSize, "C")
    d = createItem(minSize, prefSize, maxSize, "D")
    e = createItem(minSize, prefSize, maxSize, "E")
    f = createItem(QSizeF(30, 50), QSizeF(150, 50), maxSize, "F")
    g = createItem(QSizeF(30, 50), QSizeF(30, 100), maxSize, "G")

    l = QGraphicsAnchorLayout()
    l.setSpacing(0)

    w = QGraphicsWidget(None, Qt.Window)
    w.setPos(20, 20)
    w.setLayout(l)

    # Vertical.
    l.addAnchor(a, Qt.AnchorTop, l, Qt.AnchorTop)
    l.addAnchor(b, Qt.AnchorTop, l, Qt.AnchorTop)

    l.addAnchor(c, Qt.AnchorTop, a, Qt.AnchorBottom)
    l.addAnchor(c, Qt.AnchorTop, b, Qt.AnchorBottom)
    l.addAnchor(c, Qt.AnchorBottom, d, Qt.AnchorTop)
    l.addAnchor(c, Qt.AnchorBottom, e, Qt.AnchorTop)

    l.addAnchor(d, Qt.AnchorBottom, l, Qt.AnchorBottom)
    l.addAnchor(e, Qt.AnchorBottom, l, Qt.AnchorBottom)

    l.addAnchor(c, Qt.AnchorTop, f, Qt.AnchorTop)
    l.addAnchor(c, Qt.AnchorVerticalCenter, f, Qt.AnchorBottom)
示例#6
0
文件: states.py 项目: skinkie/Scripts
    layout2 = QVBoxLayout()
    box.setLayout(layout2)
    layout2.addWidget(QRadioButton("Herring"))
    layout2.addWidget(QRadioButton("Blue Parrot"))
    layout2.addWidget(QRadioButton("Petunias"))
    layout2.addStretch()

    boxProxy = QGraphicsProxyWidget()
    boxProxy.setWidget(box)

    # Parent widget.
    widget = QGraphicsWidget()
    layout = QGraphicsLinearLayout(Qt.Vertical, widget)
    layout.addItem(editProxy)
    layout.addItem(buttonProxy)
    widget.setLayout(layout)

    p1 = Pixmap(QPixmap(':/digikam.png'))
    p2 = Pixmap(QPixmap(':/akregator.png'))
    p3 = Pixmap(QPixmap(':/accessories-dictionary.png'))
    p4 = Pixmap(QPixmap(':/k3b.png'))
    p5 = Pixmap(QPixmap(':/help-browser.png'))
    p6 = Pixmap(QPixmap(':/kchart.png'))

    scene = QGraphicsScene(0, 0, 400, 300)
    scene.setBackgroundBrush(scene.palette().window())
    scene.addItem(widget)
    scene.addItem(boxProxy)
    scene.addItem(p1)
    scene.addItem(p2)
    scene.addItem(p3)
示例#7
0
    maxSize = QSizeF(300, 100)

    a = createItem(minSize, prefSize, maxSize, "A")
    b = createItem(minSize, prefSize, maxSize, "B")
    c = createItem(minSize, prefSize, maxSize, "C")
    d = createItem(minSize, prefSize, maxSize, "D")
    e = createItem(minSize, prefSize, maxSize, "E")
    f = createItem(QSizeF(30, 50), QSizeF(150, 50), maxSize, "F")
    g = createItem(QSizeF(30, 50), QSizeF(30, 100), maxSize, "G")

    l = QGraphicsAnchorLayout()
    l.setSpacing(0)

    w = QGraphicsWidget(None, Qt.Window)
    w.setPos(20, 20)
    w.setLayout(l)

    # Vertical.
    l.addAnchor(a, Qt.AnchorTop, l, Qt.AnchorTop)
    l.addAnchor(b, Qt.AnchorTop, l, Qt.AnchorTop)

    l.addAnchor(c, Qt.AnchorTop, a, Qt.AnchorBottom)
    l.addAnchor(c, Qt.AnchorTop, b, Qt.AnchorBottom)
    l.addAnchor(c, Qt.AnchorBottom, d, Qt.AnchorTop)
    l.addAnchor(c, Qt.AnchorBottom, e, Qt.AnchorTop)

    l.addAnchor(d, Qt.AnchorBottom, l, Qt.AnchorBottom)
    l.addAnchor(e, Qt.AnchorBottom, l, Qt.AnchorBottom)

    l.addAnchor(c, Qt.AnchorTop, f, Qt.AnchorTop)
    l.addAnchor(c, Qt.AnchorVerticalCenter, f, Qt.AnchorBottom)
示例#8
0
    def __init__(self, dither, detectors, *args):
        super().__init__(*args)

        self._enabled_detectors = detectors

        self._boxes = {
        }  # this will be of the form {detector_number: DetectorBox}

        self.gv_layout = QGraphicsGridLayout()

        self.gv_layout.setSpacing(0)

        min_length = DetectorBox.length * 4 + 6

        self._min_length = min_length

        self._dither = dither

        self.gv_layout.setMinimumSize(min_length, min_length)
        self.gv_layout.setMaximumSize(min_length, min_length)
        self.gv_layout.setContentsMargins(0, 0, 0, 0)

        self.setMinimumWidth(min_length)
        self.setMinimumHeight(min_length)

        self.setMaximumWidth(min_length + 20)
        self.setMaximumHeight(min_length + 20)

        self._init_boxes()

        gv_widget = QGraphicsWidget()

        gv_widget.setLayout(self.gv_layout)

        gv_widget.setContentsMargins(0, 0, 0, 0)

        scene = QGraphicsScene()

        scene.addItem(gv_widget)

        scene.setSceneRect(0, 0, min_length, min_length)

        view = QGraphicsView()

        view.setMouseTracking(True)

        view.setViewportMargins(0, 0, 0, 0)

        view.setGeometry(0, 0, min_length, min_length)

        view.setStyleSheet("border: 0px; margin: 0px; padding: 0px;")

        view.setScene(scene)

        view.setTransform(flip_vertical, True)

        layout = QVBoxLayout()

        layout.addWidget(view)

        self.setLayout(layout)
示例#9
0
    layout2 = QVBoxLayout()
    box.setLayout(layout2)
    layout2.addWidget(QRadioButton("Herring"))
    layout2.addWidget(QRadioButton("Blue Parrot"))
    layout2.addWidget(QRadioButton("Petunias"))
    layout2.addStretch()

    boxProxy = QGraphicsProxyWidget()
    boxProxy.setWidget(box)

    # Parent widget.
    widget = QGraphicsWidget()
    layout = QGraphicsLinearLayout(Qt.Vertical, widget)
    layout.addItem(editProxy)
    layout.addItem(buttonProxy)
    widget.setLayout(layout)

    p1 = Pixmap(QPixmap(':/digikam.png'))
    p2 = Pixmap(QPixmap(':/akregator.png'))
    p3 = Pixmap(QPixmap(':/accessories-dictionary.png'))
    p4 = Pixmap(QPixmap(':/k3b.png'))
    p5 = Pixmap(QPixmap(':/help-browser.png'))
    p6 = Pixmap(QPixmap(':/kchart.png'))

    scene = QGraphicsScene(0, 0, 400, 300)
    scene.setBackgroundBrush(scene.palette().window())
    scene.addItem(widget)
    scene.addItem(boxProxy)
    scene.addItem(p1)
    scene.addItem(p2)
    scene.addItem(p3)
示例#10
0
    def __updateState(self):
        """
        Update the widget with the new source/sink node signal descriptions.
        """
        widget = QGraphicsWidget()
        widget.setLayout(QGraphicsGridLayout())

        # Space between left and right anchors
        widget.layout().setHorizontalSpacing(50)

        left_node = EditLinksNode(self,
                                  direction=Qt.LeftToRight,
                                  node=self.source)

        left_node.setSizePolicy(QSizePolicy.MinimumExpanding,
                                QSizePolicy.MinimumExpanding)

        right_node = EditLinksNode(self,
                                   direction=Qt.RightToLeft,
                                   node=self.sink)

        right_node.setSizePolicy(QSizePolicy.MinimumExpanding,
                                 QSizePolicy.MinimumExpanding)

        left_node.setMinimumWidth(150)
        right_node.setMinimumWidth(150)

        widget.layout().addItem(
            left_node,
            0,
            0,
        )
        widget.layout().addItem(
            right_node,
            0,
            1,
        )

        title_template = "<center><b>{0}<b></center>"

        left_title = GraphicsTextWidget(self)
        left_title.setHtml(title_template.format(escape(self.source.title)))
        left_title.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)

        right_title = GraphicsTextWidget(self)
        right_title.setHtml(title_template.format(escape(self.sink.title)))
        right_title.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)

        widget.layout().addItem(left_title,
                                1,
                                0,
                                alignment=Qt.AlignHCenter | Qt.AlignTop)
        widget.layout().addItem(right_title,
                                1,
                                1,
                                alignment=Qt.AlignHCenter | Qt.AlignTop)

        widget.setParentItem(self)

        max_w = max(
            left_node.sizeHint(Qt.PreferredSize).width(),
            right_node.sizeHint(Qt.PreferredSize).width())

        # fix same size
        left_node.setMinimumWidth(max_w)
        right_node.setMinimumWidth(max_w)
        left_title.setMinimumWidth(max_w)
        right_title.setMinimumWidth(max_w)

        self.layout().addItem(widget)
        self.layout().activate()

        self.sourceNodeWidget = left_node
        self.sinkNodeWidget = right_node
        self.sourceNodeTitle = left_title
        self.sinkNodeTitle = right_title