Example #1
0
    def load_api(self):
        for api in self.father.all_api:
            pix = QPixmap()
            if api == '随机':
                pix.loadFromData(
                    QByteArray.fromBase64(
                        b'iVBORw0KGgoAAAANSUhEUgAAADEAAAAxCAYAAABznEEcAAAJk0lEQVRoge2ZC4yU1RXHf+ebbx7s8lwW1FUR8AUoWqIg1keDUWyqaKk1TYltpUTbao1N2rS2xlhNrCFWrcRaaa2Vttr6SCvah1DEBwq1UKSgBhTBCvJeYd87j+87zb33m5lvl2F3ZwU1qWczOzPf3O/e//+cc8/53xk+sY+JCbeqQXIScDNwDpAqQdMYSKlwrb8m/biv6z1twEPAj4HQByYAi4GGLsO6gz0Y4LvP1R8yzuqAm4AxwJWGxF29EjhUplUQqTz2CmCRB5z5kRCIr9fXNSuP+6whUehl0Idj/SdS8D4WBD6geR8rAhrlRb6627w+jKkORDU53t0COGtMwNQxAeTc+wOuEzPvA0VBewDeHzIFOHd0wLNf7WDuRVkOH6SQNZ2g59vK6XSoUqqvc0fjOvNCwhOumZzn2dntXHt2jlQCFxntNj4yr4sni/mYjR656Fq4/2JVk9bYcyGau7hOvjxnceqWnDCiVvnJ+VkWXtHG9HEFl14V9otc/kS+8VuTC3XGA805oSMv7GoTtjS5x6a9wqZ9QltrRMa0x0Q/CETO8GvgmCHKuHo4ZqgyeqhSX6M2dTRUGgaHjBoakg+UUM0tStoPCVVZuN7nnuUZXt+WcBh8O/sC/+ghyrRRAe2BR8IDTzz7mSAWc0dB2NIsrH5PWLLJY9FGYVtjlIjJPoDPu8XOHqvMHK9MG6OMGaYMSSsShccALRjAquQCJRsIIm4CsSnmoRIyc3yB88a28ttXU9z3Spo9zR6kwS+EkFOho+CAe2KIiO3wHmKJHT8MxtUpsyYG7GoXHn9NmL/KY93WHiKTdzLhslOU66YqZ49SEuJA50LoLBjwYoFbOqr2vSolchL9F1FUhdYc+KJcO7WTSydkuWdFhofXZPDNQMNa7GApyRP7Sox3xC5aJDWiBq6dArMnhdy3UrjteWGfSbV0jEAnnNgAP70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lE4VBlr7MH45jbu1jw6srmhWOr5VY9VEtS9jnf7yfPe1Wz9y5sNMs4pjSr8j29/sHi1f+IhNqiVAM3C/ado/Apa6Lzw/QjJ9jWxXjNeD/svsiX0gl4BeCXwO0XSX9JJDWGarTckygXdBHgVddPBBfWL/zwb8D/vnGgJlpdTcAAAAAElFTkSuQmCC'
                    ))
            else:
                pix.loadFromData(
                    QByteArray.fromBase64(eval('self.father.%s.b64_data' %
                                               api)))
            ico = QIcon(pix)
            ico.actualSize(QSize(22, 22))
            self.api_choose.addItem(ico, api)
        self.api_choose.setCurrentText(self.father.config['api'])

        if self.father.config['api'] != '随机':
            self.father.api = eval('self.father.%s' %
                                   self.father.config['api'])
            self.category_choose.addItems(self.father.api.cate)
            self.category_choose.setCurrentText(self.father.config['category'])
            if self.father.config['play_what'] != '网络':
                self.api_choose.setEnabled(False)
                self.category_choose.setEnabled(False)
        else:
            self.category_choose.addItem('随机')
            self.category_choose.setCurrentText('随机')
Example #2
0
    def paintEvent(self, event):
        painter = QPainter(self)
        if self.pixmap:
            painter.drawPixmap(0, 0, self.pixmap)
        margin = 25
        pad = 10
        if self.objectPlan:
            txt = self.objectPlan
            fm = QFontMetrics(painter.font())
            rect = fm.boundingRect(txt)
            rect = fm.boundingRect(rect, 0, txt)
            rect.adjust(-pad, -pad, pad, pad)

            imageDir = self.config.get("display",
                                       "image_dir",
                                       fallback="images")
            iconPath = os.path.join(imageDir, 'text-x-generic.svg')
            icon = QIcon(iconPath)
            iconSize = icon.actualSize(rect.size())
            rect.adjust(0, 0, iconSize.width(), 0)

            rect.moveBottomLeft(QPoint(margin, self.height() - margin))
            painter.fillRect(rect, QColor(220, 220, 150, 225))

            iconRect = QRect(rect)
            iconRect.setWidth(iconSize.width())
            icon.paint(painter, iconRect)

            textRect = rect.adjusted(iconRect.width(), 0, 0, 0)
            painter.drawText(textRect, Qt.AlignCenter, txt)
Example #3
0
 def __init__(self, parent=None):
     # noinspection PyArgumentList
     super(NoDocWidget, self).__init__(parent)
     self.label = QLabel()
     icon = QIcon(':/icons/[email protected]')
     pixmap = icon.pixmap(icon.actualSize(QSize(512, 512)))
     pixmap.setDevicePixelRatio(3)
     self.label.setPixmap(pixmap)
     layout = QVBoxLayout()
     layout.addWidget(self.label, alignment=Qt.AlignHCenter)
     self.setLayout(layout)
Example #4
0
 def height_for_width(self, icon: QIcon, height: int) -> QSize:
     size = QSize()
     size.setWidth(height)
     size.setHeight(height)
     actual = icon.actualSize(size)
     if actual.height() != height:
         ratio = actual.width() / actual.height()
         width = int(ratio * height)
         size.setWidth(width)
         size.setHeight(height)
     return size
    def paint(self, painter, option, index):

        if (index.isValid() == False):
            return
        painter.save()
        painter.setOpacity(0.6)
        if (option.state & QStyle.State_Selected):
            painter.fillRect(option.rect, option.palette.highlight())
        if (option.state & QStyle.State_MouseOver):
            painter.setOpacity(0.25)
            painter.fillRect(option.rect, option.palette.highlight())
        painter.setOpacity(1.0)
        painter.setFont(option.font)
        metrics = QFontMetrics(option.font)
        regular = QFont(option.font)
        italics = QFont(option.font)
        italics.setItalic(True)
        icon = QIcon(index.data(CPE.IMAGE))
        rect = option.rect
        margin = 4
        decoratonSize = QSize(option.decorationSize)
        imageSize = icon.actualSize(option.decorationSize)
        leftSideThumbnail = (decoratonSize.width() - imageSize.width()) / 2
        if (rect.width() < decoratonSize.width()):
            leftSideThumbnail = max(0, (rect.width() - imageSize.width()) / 2)
        topSizeThumbnail = (
            (rect.height() - imageSize.height()) / 2) + rect.top()
        painter.drawImage(
            QRect(leftSideThumbnail, topSizeThumbnail, imageSize.width(),
                  imageSize.height()),
            icon.pixmap(imageSize).toImage())

        labelWidth = rect.width() - decoratonSize.width() - (margin * 3)

        if (decoratonSize.width() + (margin * 2) < rect.width()):

            textRect = QRect(decoratonSize.width() + margin,
                             margin + rect.top(), labelWidth, metrics.height())
            textTitle = metrics.elidedText(
                str(index.row() + 1) + ". " + index.data(CPE.TITLE),
                Qt.ElideRight, labelWidth)
            painter.drawText(textRect, Qt.TextWordWrap, textTitle)

            if rect.height() / (metrics.lineSpacing() +
                                margin) > 5 or index.data(
                                    CPE.KEYWORDS) is not None:
                painter.setOpacity(0.6)
                textRect = QRect(textRect.left(),
                                 textRect.bottom() + margin, labelWidth,
                                 metrics.height())
                if textRect.bottom() < rect.bottom():
                    textKeyWords = index.data(CPE.KEYWORDS)
                    if textKeyWords == None:
                        textKeyWords = i18n("No keywords")
                        painter.setOpacity(0.3)
                        painter.setFont(italics)
                    textKeyWords = metrics.elidedText(textKeyWords,
                                                      Qt.ElideRight,
                                                      labelWidth)
                    painter.drawText(textRect, Qt.TextWordWrap, textKeyWords)

            painter.setFont(regular)

            if rect.height() / (metrics.lineSpacing() + margin) > 3:
                painter.setOpacity(0.6)
                textRect = QRect(textRect.left(),
                                 textRect.bottom() + margin, labelWidth,
                                 metrics.height())
                if textRect.bottom() + metrics.height() < rect.bottom():
                    textLastEdit = index.data(CPE.LASTEDIT)
                    if textLastEdit is None:
                        textLastEdit = i18n("No last edit timestamp")
                    if index.data(CPE.EDITOR) is not None:
                        textLastEdit += " - " + index.data(CPE.EDITOR)
                    if (index.data(CPE.LASTEDIT) is None) and (index.data(
                            CPE.EDITOR) is None):
                        painter.setOpacity(0.3)
                        painter.setFont(italics)
                    textLastEdit = metrics.elidedText(textLastEdit,
                                                      Qt.ElideRight,
                                                      labelWidth)
                    painter.drawText(textRect, Qt.TextWordWrap, textLastEdit)

            painter.setFont(regular)

            descRect = QRect(textRect.left(),
                             textRect.bottom() + margin, labelWidth,
                             (rect.bottom() - margin) -
                             (textRect.bottom() + margin))
            if textRect.bottom() + metrics.height() < rect.bottom():
                textRect.setBottom(textRect.bottom() + (margin / 2))
                textRect.setLeft(textRect.left() - (margin / 2))
                painter.setOpacity(0.4)
                painter.drawLine(textRect.bottomLeft(), textRect.bottomRight())
                painter.setOpacity(1.0)
                textDescription = index.data(CPE.DESCRIPTION)
                if textDescription is None:
                    textDescription = i18n("No description")
                    painter.setOpacity(0.3)
                    painter.setFont(italics)
                linesTotal = floor(descRect.height() / metrics.lineSpacing())
                if linesTotal == 1:
                    textDescription = metrics.elidedText(
                        textDescription, Qt.ElideRight, labelWidth)
                    painter.drawText(descRect, Qt.TextWordWrap,
                                     textDescription)
                else:
                    descRect.setHeight(linesTotal * metrics.lineSpacing())
                    totalDescHeight = metrics.boundingRect(
                        descRect, Qt.TextWordWrap, textDescription).height()
                    if totalDescHeight > descRect.height():
                        if totalDescHeight - metrics.lineSpacing(
                        ) > descRect.height():
                            painter.setOpacity(0.5)
                            painter.drawText(descRect, Qt.TextWordWrap,
                                             textDescription)
                            descRect.setHeight(
                                (linesTotal - 1) * metrics.lineSpacing())
                            painter.drawText(descRect, Qt.TextWordWrap,
                                             textDescription)
                            descRect.setHeight(
                                (linesTotal - 2) * metrics.lineSpacing())
                            painter.drawText(descRect, Qt.TextWordWrap,
                                             textDescription)
                        else:
                            painter.setOpacity(0.75)
                            painter.drawText(descRect, Qt.TextWordWrap,
                                             textDescription)
                            descRect.setHeight(
                                (linesTotal - 1) * metrics.lineSpacing())
                            painter.drawText(descRect, Qt.TextWordWrap,
                                             textDescription)
                    else:
                        painter.drawText(descRect, Qt.TextWordWrap,
                                         textDescription)

            painter.setFont(regular)

        painter.restore()
Example #6
0
class NGL_Bitmap(NGL_Base):
    """NGL_Bitmap(QWidget)
    Provides a embedded NGL library rect widget.
    """
    def __init__(self, parent=None):
        """ Constructor for ngl widget """
        super(NGL_Bitmap, self).__init__(parent)

        self._ico = QIcon()
        self._static = True
        self.setGeometry(100, 100, 100, 100)
        self.update()

    def paintEvent(self, event):
        """ Paint ngl widget event """

        painter = QPainter()
        painter.begin(self)

        # get rect and flags for paint
        rect = QRect(0, 0, self.size().width(), self.size().height())
        flags = Qt.AlignJustify

        # paint ico image
        self._ico.paint(painter, rect, flags)

        painter.end()

    def sizeHint(self):
        """ Return Qt sizeHint """
        return self.size()

    # Provide getter and setter methods for the property.
    @pyqtProperty(QIcon)
    def icon(self):
        return self._ico

    @icon.setter
    def icon(self, ico):
        self._ico = ico
        actualsize = self._ico.actualSize(QSize(16**2, 16**2))
        self.setMaximumSize(actualsize)
        self.setMinimumSize(actualsize)
        self.update()

    def doNGLCode(self, **kwargs):
        """ generane ngl code """

        template = 'NGL_DrawImage({x}, {y}, {image_pointer});'

        # convert coordinates
        g = self._ngl_geometry()

        # ico name
        if 'iconame' in kwargs and kwargs['iconame'] is not None:
            icon_name = '(NGL_Image*)&' + kwargs['iconame']
        else:
            icon_name = '(void*)0'

        # format and return final code
        return template.format(x=g.x(), y=g.y(), image_pointer=icon_name)
Example #7
0
class CCollapsibleFrameHeader(QWidget):
    def __init__(self, title, parentCollapsible, icon, bCollapsed):
        super().__init__()
        self.iconSize = QSize(16, 16)
        self.parentCollapsible = QCollapsibleFrame(parentCollapsible)
        self.titleLabel = QLabel(title)
        self.collapsed = False

        if icon:
            self.iconLabel = QLabel()
            self.iconLabel.setPixmap(
                QIcon(icon).pixmap(16, 16, QIcon.Normal, QIcon.On))
        else:
            self.iconLabel = None

        collapsedPixmap = QPixmap(
            "./resources/icons/window_collapse_arrow_right_tinted.ico")
        if collapsedPixmap.isNull():
            self.collapsedIcon = QApplication.style().standardIcon(
                QStyle.SP_TitleBarShadeButton)
        else:
            self.collapsedIcon = QIcon(collapsedPixmap, createColorMap())

        expandedPixmap = QPixmap(
            "./resources/icons/window_collapse_arrow_down_tinted.ico")
        if expandedPixmap.isNull():
            self.expandedIcon = QApplication.style().standardIcon(
                QStyle.SP_TitleBarUnshadeButton)
        else:
            self.expandedIcon = QIcon(expandedPixmap, createColorMap())

        self.setupCollapseButton()
        self.setupMainLayout()

        self.collapseButton.installEventFilter(self)
        self.collapseButton.clicked.connect(self.onCollapseButtonClick)

    def getIconSize(self):
        return self.iconSize

    def setIconSize(self, iconSize):
        self.iconSize = iconSize

    def setClosable(self, closable):
        self.closeButton.setVisible(closable)

    def closable(self):
        return self.closeButton.isVisible()

    def setCollapsed(self, collapsed):
        if collapsed != self.collapsed:
            self.collapsed = collapsed

            if self.collapsed:
                self.collapseIconLabel.setPixmap(
                    self.collapsedIcon.pixmap(
                        self.collapsedIcon.actualSize(self.iconSize)))
            else:
                self.collapseIconLabel.setPixmap(
                    self.expandedIcon.pixmap(
                        self.expandedIcon.actualSize(self.iconSize)))

            if self.parentCollapsible.contentsFrame:
                self.parentCollapsible.contentsFrame.setHidden(collapsed)

    def paintEvent(self, e):
        opt = QStyleOption()
        opt.initFrom(self)
        painter = QPainter(self)
        self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)

    def eventFilter(self, o, e):
        collapseButton = self.collapseButton
        if e.type(
        ) != QEvent.MouseButtonRelease or o != collapseButton or self.isEnabled(
        ):
            return super().eventFilter(o, e)
        self.onCollapseButtonClick()
        return True

    def setupCollapseButton(self):
        self.collapseButton = QPushButton(self.parentCollapsible)
        self.collapseButton.setObjectName("CollapseButton")

        layout = QHBoxLayout()
        layout.setContentsMargins(6, 2, 6, 2)
        self.collapseButton.setLayout(layout)

        self.collapseIconLabel = QLabel(self.collapseButton)
        self.collapseIconLabel.setSizePolicy(QSizePolicy.Maximum,
                                             QSizePolicy.Maximum)

        self.titleLabel.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)

        self.closeButton = QToolButton(self.collapseButton)
        self.closeButton.setIcon(QApplication.style().standardIcon(
            QStyle.SP_DockWidgetCloseButton))
        self.closeButton.setFixedHeight(16)
        self.closeButton.setFixedWidth(16)

        self.closeButton.setVisible(False)
        self.collapseIconLabel.setPixmap(
            self.expandedIcon.pixmap(
                self.expandedIcon.actualSize(self.iconSize)))

        layout.addWidget(self.collapseIconLabel)

        if self.iconLabel:
            layout.addWidget(self.iconLabel)

        layout.addWidget(self.titleLabel)
        layout.addStretch()
        layout.addWidget(self.closeButton)

    def setTitle(self, title):
        self.titleLabel.setText(title)

    def setupMainLayout(self):
        titleLayout = QHBoxLayout()
        titleLayout.setContentsMargins(0, 0, 0, 0)
        titleLayout.setSpacing(0)
        titleLayout.addWidget(self.collapseButton)
        self.setLayout(titleLayout)

    def onCollapseButtonClick(self):
        self.setCollapsed(not self.collapsed)
        if self.onCollapsedStateChanged:
            self.onCollapsedStateChanged(self.collapsed)
Example #8
0
class NGL_Bitmap(NGL_Base):
    """NGL_Bitmap(QWidget)
    Provides a embedded NGL library rect widget.
    """

    def __init__(self, parent=None):
        """ Constructor for ngl widget """
        super(NGL_Bitmap, self).__init__(parent)

        self._ico = QIcon()
        self._static = True
        self.setGeometry(100, 100, 100, 100)
        self.update()

    def paintEvent(self, event):
        """ Paint ngl widget event """

        painter = QPainter()
        painter.begin(self)

        # get rect and flags for paint
        rect = QRect(0, 0, self.size().width(), self.size().height())
        flags = Qt.AlignJustify

        # paint ico image
        self._ico.paint(painter, rect, flags)

        painter.end()

    def sizeHint(self):
        """ Return Qt sizeHint """
        return self.size()

    # Provide getter and setter methods for the property.
    @pyqtProperty(QIcon)
    def icon(self):
        return self._ico

    @icon.setter
    def icon(self, ico):
        self._ico = ico
        actualsize = self._ico.actualSize(QSize(16**2, 16**2))
        self.setMaximumSize(actualsize)
        self.setMinimumSize(actualsize)
        self.update()

    def doNGLCode(self, **kwargs):
        """ generane ngl code """

        template = 'NGL_DrawImage({x}, {y}, {image_pointer});'

        # convert coordinates
        g = self._ngl_geometry()

        # ico name
        if 'iconame' in kwargs and kwargs['iconame'] is not None:
            icon_name = '(NGL_Bitmap*)&' + kwargs['iconame']
        else:
            icon_name = '(void*)0'

        # format and return final code
        return template.format(
                            x = g.x(),
                            y = g.y(),
                            image_pointer=icon_name)
Example #9
0
class IconPreviewArea(QWidget):

    NumModes = 4
    NumStates = 2
    size = 0
    icon = None

    def __init__(self, *args):
        super(QWidget, self).__init__(*args)

        self.mainLayout = QGridLayout(self)
        self.stateLabels = [None for i in range(self.NumStates)]
        self.modeLabels = [None for i in range(self.NumModes)]
        self.pixmapLabels = [[None for x in range(self.NumStates)]
                             for y in range(self.NumModes)]

        self.icon = QIcon()

        for row in range(self.NumStates):
            self.stateLabels[row] = self.createHeaderLabel(
                self.iconStateNames()[row])
            self.mainLayout.addWidget(self.stateLabels[row], row + 1, 0)

        for column in range(self.NumModes):
            self.modeLabels[column] = self.createHeaderLabel(
                self.iconModeNames()[column])
            self.mainLayout.addWidget(self.modeLabels[column], 0, column + 1)

        for column in range(self.NumModes):
            for row in range(self.NumStates):
                self.pixmapLabels[column][row] = self.createPixmapLabel()
                self.mainLayout.addWidget(self.pixmapLabels[column][row],
                                          row + 1, column + 1)

    def createHeaderLabel(self, text):
        label = QLabel("<b>{}</b>".format(text))
        label.setAlignment(Qt.AlignCenter)
        return label

    def createPixmapLabel(self):
        label = QLabel()
        label.setEnabled(False)
        label.setAlignment(Qt.AlignCenter)
        label.setFrameShape(QFrame.Box)
        label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        label.setBackgroundRole(QPalette.Base)
        label.setAutoFillBackground(True)
        label.setMinimumSize(132, 132)
        return label

    @staticmethod
    def iconModes():
        return (QIcon.Normal, QIcon.Active, QIcon.Disabled, QIcon.Selected)

    @staticmethod
    def iconStates():
        return (QIcon.Off, QIcon.On)

    @staticmethod
    def iconModeNames():
        return ("Normal", "Active", "Disabled", "Selected")

    @staticmethod
    def iconStateNames():
        return ("Off", "On")

    def setIcon(self, icon):
        self.icon = icon
        self.updatePixmapLabels()

    def setSize(self, size):
        if self.size != size:
            self.size = size
            self.updatePixmapLabels()

    def updatePixmapLabels(self):
        window = None
        nativeParent = self.nativeParentWidget()

        if nativeParent is not None:
            window = nativeParent.windowHandle()

        for column in range(self.NumModes):
            for row in range(self.NumStates):
                pixmap = self.icon.pixmap(window, self.size,
                                          self.iconModes()[column],
                                          self.iconStates()[row])
                pixmapLabel = self.pixmapLabels[column][row]
                pixmapLabel.setPixmap(pixmap)
                pixmapLabel.setEnabled(not pixmap.isNull())
                toolTip = None
                if not pixmap.isNull():
                    actualSize = self.icon.actualSize(self.size)
                    tooltip = "Size: {}x{}\nActual size: {}x{}\nDevice pixel ratio: {}".format(
                        self.size.width(), self.size.height(),
                        actualSize.width(), actualSize.height(),
                        pixmap.devicePixelRatioF())
                    #print(tooltip)
                pixmapLabel.setToolTip(toolTip)