예제 #1
0
def load_fonts():
    from qtpy import QtGui
    database = QtGui.QFontDatabase()
    for font in FONTFILES:
        database.addApplicationFont(font)
    font = database.font("Ubuntu", "normal", 12)
    return font
예제 #2
0
def font_is_installed(font):
    """Check if font is installed"""
    from qtpy import QtGui as QG

    return [
        fam for fam in QG.QFontDatabase().families()
        if to_text_string(fam) == font
    ]
예제 #3
0
파일: gl.py 프로젝트: cas91010491/ngsgui
    def addFont(self, font_size):
        with self._vao:
            font = TextRenderer.Font()
            font.size = font_size

            db = QtGui.QFontDatabase()
            qfont = db.systemFont(db.FixedFont)
            if font_size > 0:
                qfont.setPointSize(font_size)
            else:
                self.fonts[0] = font

            self.fonts[qfont.pointSize()] = font

            metrics = QtGui.QFontMetrics(qfont)

            font.width = metrics.width("W")
            font.height = metrics.height()

            font.tex_width = (1 + 128 - 32) * font.width
            font.tex_width = (font.tex_width +
                              3) // 4 * 4  # should be multiple of 4
            font.tex_height = metrics.height()
            for i in range(32, 128):
                c = bytes([i]).decode()

            image = QtGui.QImage(font.tex_width, font.tex_height,
                                 QtGui.QImage.Format_Grayscale8)
            image.fill(QtCore.Qt.black)

            painter = QtGui.QPainter()
            painter.begin(image)
            painter.setFont(qfont)
            painter.setPen(QtCore.Qt.white)
            for i in range(32, 128):
                w = font.width
                text = bytes([i]).decode()
                painter.drawText(
                    (i - 32) * w, 0, (i + 1 - 32) * w, font.height,
                    QtCore.Qt.AlignTop | QtCore.Qt.AlignLeft, text)
            painter.end()
            ptr = image.constBits()
            if qtpy.API == "pyqt5":
                ptr.setsize(image.byteCount())
            Z = numpy.array(ptr).reshape(font.tex_height, font.tex_width)

            font.tex = Texture(GL_TEXTURE_2D, GL_RED)
            font.tex.store(Z, GL_UNSIGNED_BYTE, Z.shape[1], Z.shape[0])
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
예제 #4
0
    def headerData(self, index, orientation, role=None):
        if orientation == Qt.Horizontal:
            return self._get_horizontal_header_data(index, role)
        else:
            return self._get_vertical_header_data(index, role)

    def flags(self, index):
        row, col = index.row(), index.column()
        return self._flags_data[row, col]


if __name__ == '__main__':
    import sys

    app = QtWidgets.QApplication([])

    db = QtGui.QFontDatabase()

    combo = QtWidgets.QComboBox()

    families = db.families()

    for i in range(len(families)):
        family = families[i]
        combo.addItem(family)
        combo.setItemData(i, family, Qt.FontRole)

    combo.show()

    sys.exit(app.exec_())