Beispiel #1
0
    def showExamples(self, category):
        self.newPage()
        self.fadeShapes()
        self.currentCategory = category
        self.currentExample = ""

        horizontalMargin = 0.025 * self.width()
        verticalMargin = 0.025 * self.height()

        title = self.addTitle(category, verticalMargin)
        self.addTitleBackground(title)

        topMargin = 6 * verticalMargin
        bottomMargin = self.height() - 3.2 * verticalMargin
        space = bottomMargin - topMargin
        step = min(title.rect().height() / self.fontRatio,
                   space / self.maximumLabels)
        textHeight = self.fontRatio * step

        startPosition = QtCore.QPointF(2 * horizontalMargin,
                                       self.height() + topMargin)
        finishPosition = QtCore.QPointF(2 * horizontalMargin, topMargin)
        maxSize = QtCore.QSizeF(32 * horizontalMargin, textHeight)
        maxWidth = 0.0

        for example in self.categories[self.currentCategory]['examples']:
            caption = TitleShape(example, self.font(), QtGui.QPen(),
                                 QtCore.QPointF(startPosition),
                                 QtCore.QSizeF(maxSize))
            caption.setTarget(QtCore.QPointF(finishPosition))

            self.display.appendShape(caption)

            startPosition += QtCore.QPointF(0.0, step)

            finishPosition += QtCore.QPointF(0.0, step)
            maxWidth = max(maxWidth, caption.rect().width())

        menuButton = TitleShape(self.tr("Main Menu"), self.font(),
                                QtGui.QPen(QtCore.Qt.white),
                                QtCore.QPointF(startPosition),
                                QtCore.QSizeF(maxSize))
        menuButton.setTarget(QtCore.QPointF(finishPosition))
        self.display.appendShape(menuButton)

        startPosition = QtCore.QPointF(self.width(), topMargin)
        extra = (step - textHeight) / 4

        for example in self.categories[self.currentCategory]['examples']:
            uniquename = self.currentCategory + "-" + example

            path = QtGui.QPainterPath()

            path.addRect(-2 * extra, -extra, maxWidth + 4 * extra,
                         textHeight + 2 * extra)

            background = PanelShape(
                path, QtGui.QBrush(self.examples[uniquename]['color']),
                QtGui.QBrush(QtGui.QColor("#e0e0ff")),
                QtGui.QPen(QtCore.Qt.NoPen), QtCore.QPointF(startPosition),
                QtCore.QSizeF(maxWidth + 4 * extra, textHeight + 2 * extra))

            background.metadata["example"] = uniquename
            background.setInteractive(True)
            background.setTarget(
                QtCore.QPointF(2 * horizontalMargin,
                               background.position().y()))
            self.display.insertShape(0, background)
            startPosition += QtCore.QPointF(0.0, step)

        backPath = QtGui.QPainterPath()
        backPath.moveTo(-2 * extra, -extra)
        backPath.lineTo(-8 * extra, textHeight / 2)
        backPath.lineTo(-extra, textHeight + extra)
        backPath.lineTo(maxWidth + 2 * extra, textHeight + extra)
        backPath.lineTo(maxWidth + 2 * extra, -extra)
        backPath.closeSubpath()

        buttonBackground = PanelShape(
            backPath, QtGui.QBrush(QtGui.QColor("#a6ce39")),
            QtGui.QBrush(QtGui.QColor("#c7f745")), QtGui.QPen(QtCore.Qt.NoPen),
            QtCore.QPointF(startPosition),
            QtCore.QSizeF(maxWidth + 10 * extra, textHeight + 2 * extra))

        buttonBackground.metadata["action"] = "parent"
        buttonBackground.setInteractive(True)
        buttonBackground.setTarget(
            QtCore.QPointF(2 * horizontalMargin,
                           buttonBackground.position().y()))
        self.display.insertShape(0, buttonBackground)

        leftMargin = 3 * horizontalMargin + maxWidth
        rightMargin = self.width() - 3 * horizontalMargin

        description = DocumentShape(
            self.categories[self.currentCategory]['description'],
            self.documentFont, QtCore.QPointF(leftMargin, topMargin),
            QtCore.QSizeF(rightMargin - leftMargin, space), 0)

        description.metadata["fade"] = 10
        self.display.appendShape(description)

        self.addVersionAndCopyright(
            QtCore.QRectF(2 * horizontalMargin,
                          self.height() - verticalMargin - textHeight,
                          self.width() - 4 * horizontalMargin, textHeight))
Beispiel #2
0
    def showExamples(self, category):
        self.newPage()
        self.fadeShapes()
        self.currentCategory = category
        self.currentExample = ""

        horizontalMargin = 0.025*self.width()
        verticalMargin = 0.025*self.height()

        title = self.addTitle(category, verticalMargin)
        self.addTitleBackground(title)

        topMargin = 6*verticalMargin
        bottomMargin = self.height() - 3.2*verticalMargin
        space = bottomMargin - topMargin
        step = min(title.rect().height() / self.fontRatio, space/self.maximumLabels )
        textHeight = self.fontRatio * step

        startPosition = QtCore.QPointF(2*horizontalMargin, self.height()+topMargin)
        finishPosition = QtCore.QPointF(2*horizontalMargin, topMargin)
        maxSize = QtCore.QSizeF(32*horizontalMargin, textHeight)
        maxWidth = 0.0

        for example in self.categories[self.currentCategory]['examples']:
            caption = TitleShape(example, self.font(), QtGui.QPen(), QtCore.QPointF(startPosition), QtCore.QSizeF(maxSize))
            caption.setTarget(QtCore.QPointF(finishPosition))

            self.display.appendShape(caption)

            startPosition += QtCore.QPointF(0.0, step)

            finishPosition += QtCore.QPointF(0.0, step)
            maxWidth = max(maxWidth, caption.rect().width() )

        menuButton = TitleShape(self.tr("Main Menu"), self.font(),
                                QtGui.QPen(QtCore.Qt.white),
                                QtCore.QPointF(startPosition),
                                QtCore.QSizeF(maxSize))
        menuButton.setTarget(QtCore.QPointF(finishPosition))
        self.display.appendShape(menuButton)

        startPosition = QtCore.QPointF(self.width(), topMargin )
        extra = (step - textHeight)/4

        for example in self.categories[self.currentCategory]['examples']:
            uniquename = self.currentCategory + "-" + example

            path = QtGui.QPainterPath()

            path.addRect(-2*extra, -extra, maxWidth + 4*extra, textHeight+2*extra)

            background = PanelShape(path,
                QtGui.QBrush(self.examples[uniquename]['color']),
                QtGui.QBrush(QtGui.QColor("#e0e0ff")),
                QtGui.QPen(QtCore.Qt.NoPen), QtCore.QPointF(startPosition),
                QtCore.QSizeF(maxWidth + 4*extra, textHeight + 2*extra))

            background.metadata["example"] =  uniquename
            background.setInteractive(True)
            background.setTarget(QtCore.QPointF(2*horizontalMargin,
                                          background.position().y()))
            self.display.insertShape(0, background)
            startPosition += QtCore.QPointF(0.0, step)

        backPath = QtGui.QPainterPath()
        backPath.moveTo(-2*extra, -extra)
        backPath.lineTo(-8*extra, textHeight/2)
        backPath.lineTo(-extra, textHeight + extra)
        backPath.lineTo(maxWidth + 2*extra, textHeight + extra)
        backPath.lineTo(maxWidth + 2*extra, -extra)
        backPath.closeSubpath()

        buttonBackground = PanelShape(backPath,
            QtGui.QBrush(QtGui.QColor("#a6ce39")), QtGui.QBrush(QtGui.QColor("#c7f745")),
            QtGui.QPen(QtCore.Qt.NoPen), QtCore.QPointF(startPosition),
            QtCore.QSizeF(maxWidth + 10*extra, textHeight + 2*extra))

        buttonBackground.metadata["action"] =  "parent"
        buttonBackground.setInteractive(True)
        buttonBackground.setTarget(QtCore.QPointF(2*horizontalMargin,
                                          buttonBackground.position().y()))
        self.display.insertShape(0, buttonBackground)

        leftMargin = 3*horizontalMargin + maxWidth
        rightMargin = self.width() - 3*horizontalMargin

        description = DocumentShape(self.categories[self.currentCategory]['description'],
            self.documentFont, QtCore.QPointF(leftMargin, topMargin),
                QtCore.QSizeF(rightMargin - leftMargin, space), 0)

        description.metadata["fade"] =  10
        self.display.appendShape(description)

        self.addVersionAndCopyright(QtCore.QRectF(2*horizontalMargin,
                    self.height() - verticalMargin - textHeight,
                    self.width() - 4*horizontalMargin, textHeight))
Beispiel #3
0
    def showCategories(self):
        self.newPage()
        self.fadeShapes()
        self.currentCategory = ""
        self.currentExample = ""

        # Sort the category names excluding any "Qt" prefix.
        def csort(c1, c2):
            if c1.startsWith("Qt "):
                c1 = c1[3:]

            if c2.startsWith("Qt "):
                c2 = c2[3:]

            return cmp(c1, c2)

        categories = [c for c in self.categories.keys() if c != "[main]"]
        categories.sort(csort)

        horizontalMargin = 0.025 * self.width()
        verticalMargin = 0.025 * self.height()
        title = TitleShape(
            self.tr("PyQt Examples and Demos"), self.titleFont,
            QtGui.QPen(QtGui.QColor("#a6ce39")), QtCore.QPointF(),
            QtCore.QSizeF(0.5 * self.width(), 4 * verticalMargin))

        title.setPosition(
            QtCore.QPointF(self.width() / 2 - title.rect().width() / 2,
                           -title.rect().height()))
        title.setTarget(QtCore.QPointF(title.position().x(), verticalMargin))

        self.display.appendShape(title)

        topMargin = 6 * verticalMargin
        bottomMargin = self.height() - 3.2 * verticalMargin
        space = bottomMargin - topMargin
        step = min(title.rect().height() / self.fontRatio,
                   space / self.maximumLabels)
        textHeight = self.fontRatio * step

        startPosition = QtCore.QPointF(0.0, topMargin)
        maxSize = QtCore.QSizeF(10.8 * horizontalMargin, textHeight)
        maxWidth = 0.0

        newShapes = []

        for category in categories:
            caption = TitleShape(category, self.font(), QtGui.QPen(),
                                 QtCore.QPointF(startPosition),
                                 QtCore.QSizeF(maxSize))
            caption.setPosition(
                QtCore.QPointF(-caption.rect().width(),
                               caption.position().y()))
            caption.setTarget(
                QtCore.QPointF(2 * horizontalMargin,
                               caption.position().y()))

            newShapes.append(caption)
            startPosition += QtCore.QPointF(0.0, step)
            maxWidth = max(maxWidth, caption.rect().width())

        exitButton = TitleShape(self.tr("Exit"), self.font(),
                                QtGui.QPen(QtCore.Qt.white),
                                QtCore.QPointF(startPosition),
                                QtCore.QSizeF(maxSize))
        exitButton.setTarget(
            QtCore.QPointF(2 * horizontalMargin,
                           exitButton.position().y()))
        newShapes.append(exitButton)

        startPosition = QtCore.QPointF(self.width(), topMargin)

        extra = (step - textHeight) / 4

        backgroundPath = QtGui.QPainterPath()
        backgroundPath.addRect(-2 * extra, -extra, maxWidth + 4 * extra,
                               textHeight + 2 * extra)

        for category in categories:
            background = PanelShape(
                backgroundPath,
                QtGui.QBrush(self.categories[category]['color']),
                QtGui.QBrush(QtGui.QColor("#e0e0ff")),
                QtGui.QPen(QtCore.Qt.NoPen), QtCore.QPointF(startPosition),
                QtCore.QSizeF(maxWidth + 4 * extra, textHeight + 2 * extra))

            background.metadata["category"] = category
            background.setInteractive(True)
            background.setTarget(
                QtCore.QPointF(2 * horizontalMargin,
                               background.position().y()))
            self.display.insertShape(0, background)
            startPosition += QtCore.QPointF(0.0, step)

        exitPath = QtGui.QPainterPath()
        exitPath.moveTo(-2 * extra, -extra)
        exitPath.lineTo(-8 * extra, textHeight / 2)
        exitPath.lineTo(-extra, textHeight + extra)
        exitPath.lineTo(maxWidth + 2 * extra, textHeight + extra)
        exitPath.lineTo(maxWidth + 2 * extra, -extra)
        exitPath.closeSubpath()

        exitBackground = PanelShape(
            exitPath, QtGui.QBrush(QtGui.QColor("#a6ce39")),
            QtGui.QBrush(QtGui.QColor("#c7f745")), QtGui.QPen(QtCore.Qt.NoPen),
            QtCore.QPointF(startPosition),
            QtCore.QSizeF(maxWidth + 10 * extra, textHeight + 2 * extra))

        exitBackground.metadata["action"] = "exit"
        exitBackground.setInteractive(True)
        exitBackground.setTarget(
            QtCore.QPointF(2 * horizontalMargin,
                           exitBackground.position().y()))
        self.display.insertShape(0, exitBackground)

        for caption in newShapes:
            position = caption.target()
            size = caption.rect().size()
            caption.setPosition(QtCore.QPointF(-maxWidth, position.y()))
            self.display.appendShape(caption)

        leftMargin = 3 * horizontalMargin + maxWidth
        rightMargin = self.width() - 3 * horizontalMargin

        description = DocumentShape(
            self.categories['[main]']['description'], self.documentFont,
            QtCore.QPointF(leftMargin, topMargin),
            QtCore.QSizeF(rightMargin - leftMargin, space))

        description.metadata["fade"] = 10
        self.display.appendShape(description)

        imageHeight = title.rect().height() + verticalMargin

        qtLength = min(imageHeight, title.rect().left() - 3 * horizontalMargin)
        qtMaxSize = QtCore.QSizeF(qtLength, qtLength)

        qtShape = ImageShape(
            self.qtLogo,
            QtCore.QPointF(2 * horizontalMargin - extra, -imageHeight),
            qtMaxSize, 0, QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)

        qtShape.metadata["fade"] = 15
        qtShape.setTarget(QtCore.QPointF(qtShape.rect().x(), verticalMargin))
        self.display.insertShape(0, qtShape)

        trolltechMaxSize = QtCore.QSizeF(
            self.width() - 3 * horizontalMargin - title.rect().right(),
            imageHeight)

        trolltechShape = ImageShape(
            self.rbLogo,
            QtCore.QPointF(
                self.width() - 2 * horizontalMargin -
                trolltechMaxSize.width() + extra, -imageHeight),
            trolltechMaxSize, 0, QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)

        trolltechShape.metadata["fade"] = 15
        trolltechShape.setTarget(
            QtCore.QPointF(trolltechShape.rect().x(), verticalMargin))

        self.display.insertShape(0, trolltechShape)

        self.addVersionAndCopyright(
            QtCore.QRectF(2 * horizontalMargin,
                          self.height() - verticalMargin - textHeight,
                          self.width() - 4 * horizontalMargin, textHeight))
Beispiel #4
0
    def showCategories(self):
        self.newPage()
        self.fadeShapes()
        self.currentCategory = ""
        self.currentExample = ""

        # Sort the category names excluding any "Qt" prefix.
        def remove_Qt(cat):
            if cat.startsWith("Qt "):
                cat = cat[3:]

            return cat

        categories = [c for c in self.categories.keys() if c != "[main]"]
        categories.sort(key=remove_Qt)

        horizontalMargin = 0.025*self.width()
        verticalMargin = 0.025*self.height()
        title = TitleShape(self.tr("PyQt Examples and Demos"),
                        self.titleFont, QtGui.QPen(QtGui.QColor("#a6ce39")), QtCore.QPointF(),
                        QtCore.QSizeF(0.5*self.width(), 4*verticalMargin))

        title.setPosition(QtCore.QPointF(self.width() / 2 - title.rect().width() / 2,
                                         -title.rect().height()))
        title.setTarget(QtCore.QPointF(title.position().x(), verticalMargin))

        self.display.appendShape(title)

        topMargin = 6*verticalMargin
        bottomMargin = self.height() - 3.2*verticalMargin
        space = bottomMargin - topMargin
        step = min(title.rect().height() / self.fontRatio, space/self.maximumLabels )
        textHeight = self.fontRatio * step

        startPosition = QtCore.QPointF(0.0, topMargin)
        maxSize = QtCore.QSizeF(10.8*horizontalMargin, textHeight)
        maxWidth = 0.0

        newShapes = []

        for category in categories:
            caption = TitleShape(category, self.font(), QtGui.QPen(), QtCore.QPointF(startPosition), QtCore.QSizeF(maxSize))
            caption.setPosition(QtCore.QPointF(-caption.rect().width(),
                                caption.position().y()))
            caption.setTarget(QtCore.QPointF(2*horizontalMargin, caption.position().y()))

            newShapes.append(caption)
            startPosition += QtCore.QPointF(0.0, step)
            maxWidth = max(maxWidth, caption.rect().width() )

        exitButton = TitleShape(self.tr("Exit"), self.font(), QtGui.QPen(QtCore.Qt.white),
                                   QtCore.QPointF(startPosition), QtCore.QSizeF(maxSize))
        exitButton.setTarget(QtCore.QPointF(2*horizontalMargin, exitButton.position().y()))
        newShapes.append(exitButton)

        startPosition = QtCore.QPointF(self.width(), topMargin )

        extra = (step - textHeight)/4

        backgroundPath = QtGui.QPainterPath()
        backgroundPath.addRect(-2*extra, -extra, maxWidth + 4*extra, textHeight + 2*extra)

        for category in categories:
            background = PanelShape(backgroundPath,
                QtGui.QBrush(self.categories[category]['color']), QtGui.QBrush(QtGui.QColor("#e0e0ff")),
                QtGui.QPen(QtCore.Qt.NoPen), QtCore.QPointF(startPosition),
                QtCore.QSizeF(maxWidth + 4*extra, textHeight + 2*extra))

            background.metadata["category"] = category
            background.setInteractive(True)
            background.setTarget(QtCore.QPointF(2*horizontalMargin,
                                          background.position().y()))
            self.display.insertShape(0, background)
            startPosition += QtCore.QPointF(0.0, step)

        exitPath = QtGui.QPainterPath()
        exitPath.moveTo(-2*extra, -extra)
        exitPath.lineTo(-8*extra, textHeight/2)
        exitPath.lineTo(-extra, textHeight + extra)
        exitPath.lineTo(maxWidth + 2*extra, textHeight + extra)
        exitPath.lineTo(maxWidth + 2*extra, -extra)
        exitPath.closeSubpath()

        exitBackground = PanelShape(exitPath,
            QtGui.QBrush(QtGui.QColor("#a6ce39")), QtGui.QBrush(QtGui.QColor("#c7f745")),
            QtGui.QPen(QtCore.Qt.NoPen), QtCore.QPointF(startPosition),
            QtCore.QSizeF(maxWidth + 10*extra, textHeight + 2*extra))

        exitBackground.metadata["action"] = "exit"
        exitBackground.setInteractive(True)
        exitBackground.setTarget(QtCore.QPointF(2*horizontalMargin,
                                          exitBackground.position().y()))
        self.display.insertShape(0, exitBackground)

        for caption in newShapes:
            position = caption.target()
            size = caption.rect().size()
            caption.setPosition(QtCore.QPointF(-maxWidth, position.y()))
            self.display.appendShape(caption)

        leftMargin = 3*horizontalMargin + maxWidth
        rightMargin = self.width() - 3*horizontalMargin

        description = DocumentShape(self.categories['[main]']['description'],
            self.documentFont, QtCore.QPointF(leftMargin, topMargin),
                QtCore.QSizeF(rightMargin - leftMargin, space))

        description.metadata["fade"] = 10
        self.display.appendShape(description)

        imageHeight = title.rect().height() + verticalMargin

        qtLength = min(imageHeight, title.rect().left()-3*horizontalMargin)
        qtMaxSize = QtCore.QSizeF(qtLength, qtLength)

        qtShape = ImageShape(self.qtLogo,
                QtCore.QPointF(2*horizontalMargin-extra, -imageHeight), qtMaxSize, 0,
                QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)

        qtShape.metadata["fade"] = 15
        qtShape.setTarget(QtCore.QPointF(qtShape.rect().x(), verticalMargin))
        self.display.insertShape(0, qtShape)

        trolltechMaxSize = QtCore.QSizeF(
                self.width()-3*horizontalMargin-title.rect().right(), imageHeight)

        trolltechShape = ImageShape(self.rbLogo,
                QtCore.QPointF(self.width()-2*horizontalMargin-trolltechMaxSize.width()+extra,
                        -imageHeight),
                trolltechMaxSize, 0, QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)

        trolltechShape.metadata["fade"] = 15
        trolltechShape.setTarget(QtCore.QPointF(trolltechShape.rect().x(),
                            verticalMargin))

        self.display.insertShape(0, trolltechShape)

        self.addVersionAndCopyright(QtCore.QRectF(2*horizontalMargin,
                    self.height() - verticalMargin - textHeight,
                    self.width() - 4*horizontalMargin, textHeight))