예제 #1
0
def set_default_font(font, size):
    fontDataBase = QFontDatabase()
    defaultSettings = QWebEngineSettings.globalSettings()
    standardFont = fontDataBase.font(font, "", 12)
    defaultSettings.setFontFamily(QWebEngineSettings.StandardFont,
                                  standardFont.family())
    defaultSettings.setFontSize(QWebEngineSettings.DefaultFontSize, size)
예제 #2
0
 def setup_lexer(self):
     fontdb = QFontDatabase()
     self.lexer = QsciLexerMarkdown()
     self.lexer.setDefaultFont(fontdb.font('Source Code Pro', 'Regular',
                                           11))
     # TODO autocompletion of links does not work
     self.api = QsciAPIWiki(self.lexer)
     self.api.prepare()
예제 #3
0
 def updateStyle(self, fontStyle):
     fontDatabase = QFontDatabase()
     oldStrategy = self.displayFont.styleStrategy()
     self.displayFont = fontDatabase.font(self.displayFont.family(),
             fontStyle, self.displayFont.pointSize())
     self.displayFont.setStyleStrategy(oldStrategy)
     self.squareSize = max(24, QFontMetrics(self.displayFont).xHeight() * 3)
     self.adjustSize()
     self.update()
예제 #4
0
 def updateStyle(self, fontStyle):
     fontDatabase = QFontDatabase()
     oldStrategy = self.displayFont.styleStrategy()
     self.displayFont = fontDatabase.font(self.displayFont.family(),
             fontStyle, self.displayFont.pointSize())
     self.displayFont.setStyleStrategy(oldStrategy)
     self.squareSize = max(24, QFontMetrics(self.displayFont).xHeight() * 3)
     self.adjustSize()
     self.update()
예제 #5
0
def _load_font(name, size=8):
    """Load a TTF font."""
    if name in _FONTS:
        return _FONTS[name]
    font_id = QFontDatabase.addApplicationFont(str(_static_abs_path(name)))
    font_db = QFontDatabase()
    font_family = QFontDatabase.applicationFontFamilies(font_id)[0]
    font = font_db.font(font_family, None, size)
    _FONTS[name] = font
    return font
예제 #6
0
    def __init__(self):
        super(MainWindow, self).__init__()

        font_id = QFontDatabase.addApplicationFont("fontawesome-webfont.ttf")

        if font_id is not -1:
            font_db = QFontDatabase()
            self.font_styles = font_db.styles('FontAwesome')
            self.font_families = QFontDatabase.applicationFontFamilies(font_id)
            print(self.font_styles, self.font_families)
            for font_family in self.font_families:
                self.font = font_db.font(font_family, self.font_styles[0], 18)
        self.home()
예제 #7
0
    def setTextFont(self, fileName, size=92):
        print(size)

        bin = self.readFontFileAsBinary(fileName)
        QFontDatabase.removeAllApplicationFonts()
        #id = QFontDatabase.addApplicationFont(fileName)
        id = QFontDatabase.addApplicationFontFromData(bin)
        try:
            family = QFontDatabase.applicationFontFamilies(id)[0]
        except:
            return "Not found"
        font = QFontDatabase.font(self.fontsDB, family, 'bold', size)
        font.setStrikeOut(False)
        self.ui.textEdit.setFont(font)
        self.ui.textEdit.setCurrentFont(font)
        self.ui.chkObserve.setEnabled(True)
        self.ui.chkHB.setEnabled(True)
        return family
예제 #8
0
    def setup_scintilla(self, widget):
        # Set up Markdown editor
        fontdb = QFontDatabase()
        widget.setWrapMode(QsciScintilla.WrapWord)
        widget.setMarginWidth(0, "0000")
        widget.setMarginLineNumbers(0, True)
        widget.setMarginsFont(fontdb.font('Source Code Pro', 'Regular', 11))
        widget.setMarginType(0, QsciScintilla.NumberMargin)
        widget.setIndentationsUseTabs(False)
        widget.setTabWidth(2)
        widget.setTabIndents(True)
        widget.setEolMode(QsciScintilla.EolUnix)

        widget.setAutoCompletionSource(QsciScintilla.AcsAPIs)
        widget.setAutoCompletionThreshold(1)
        widget.setAutoCompletionCaseSensitivity(False)
        widget.setAutoCompletionReplaceWord(False)
        widget.setAutoCompletionWordSeparators([' '])
        # widget.setAutoCompletionUseSingle(QsciScintilla.AcusNever)

        widget.setLexer(self.lexer)
예제 #9
0
    def __init__(self,
                 splash,
                 nexicoBase,
                 config,
                 selectionName="standard",
                 parent=None):
        """
		Constructor	
		"""
        QMainWindow.__init__(self)
        self.setupUi(self)
        qfdb = QFontDatabase()
        fi = qfdb.addApplicationFont(":fonts/resources/FreeSans.otf")

        try:
            self.font = qfdb.font(
                qfdb.applicationFontFamilies(fi)[0], "Light", False)
        except:
            self.font = None

        self.config = config
        self.nbBestKids = int(self.config["configuration"]["nbBestKids"])
        self.currentSection = None
        self.selectedWord = ""
        self.selectedTokeni = None
        self.sectList = []
        self.base = nexicoBase
        self.wordTableWidget.setHorizontalHeaderLabels(
            [self.tr("word"), self.tr("frequency")])
        self.autoSelect = 0

        false_positives = set(["aliases", "undefined"])
        self.encodings = set(
            name
            for imp, name, ispkg in pkgutil.iter_modules(encodings.__path__)
            if not ispkg)
        self.encodings.difference_update(false_positives)
        self.encodings = sorted(self.encodings)

        self.statusbar.showMessage(self.tr("Welcome!"), 20000)
        self.fileNameEdit.setText(selectionName)
        self.pb = QtWidgets.QProgressBar(self.statusBar())
        self.statusBar().addPermanentWidget(self.pb)
        self.pb.hide()
        self.splash = splash
        self.selecting = False
        self.graphicsView.setRenderHints(
            QtGui.QPainter.Antialiasing
            or QtGui.QPainter.SmoothPixmapTransform)
        self.ngra = self.ngraDial.sliderPosition()
        self.renoword = re.compile("\W+$", re.U + re.I + re.M)

        self.webView = QWebView()
        self.collocations = Collocations(self)

        #self.gridLayout_3.addWidget(self.graphcanvas, 0, 0, 1, 1)
        self.gridLayout_3.addWidget(self.webView, 0, 0, 1, 1)

        # start with collocation open?
        #openwithcolloc=int(self.config["configuration"]["openwithcolloc"]) # False
        openwithcolloc = False
        self.actionCollocations.setChecked(openwithcolloc)
        self.on_actionCollocations_toggled(openwithcolloc)
        #self.graphButton.setChecked(True)

        #self.specos=None # dict of collocations for current word

        # TODO: solve the memory problem of qsplitter:
        #self.hsplitter=QSplitter(1, self.centralwidget)  # 2=vertical orientation
        #self.centralGridLayout.addWidget(self.hsplitter,  0, 1)
        #self.vspgridLayout = QtGui.QGridLayout(self.hsplitter)
        #self.vspgridLayout.setSpacing(0)
        #self.hsplitter.setHandleWidth(8)
        #self.vspgridLayout.setContentsMargins(2, 0, 2, 0)
        #self.vspgridLayout.addWidget(self.westwidget, 0, 0)
        #self.vspgridLayout.addWidget(self.eastwidget)

        self.load()
        self.filter.textChanged.connect(self.filterChanged)
        self.colfilter.textChanged.connect(self.colfilterChanged)

        self.recenter = RecenterClass()
예제 #10
0
class GFonts(QtWidgets.QMainWindow):
    def __init__(self):
        super(GFonts, self).__init__()
        uic.loadUi('gfonts.ui', self)
        self.fTool = gFontsTool()
        self.threadPool = QtCore.QThreadPool()

        self.DDFamily.currentIndexChanged.connect(self.familySelected)
        self.DDWeight.currentIndexChanged.connect(self.weightSelected)

        self.show()

        worker = bgProc(self.fTool.getMetadata)
        worker.signals.finished.connect(self.mdLoaded)
        self.threadPool.start(worker)

        self.statusBar().showMessage('Loading metadata...')

    def mdLoaded(self):
        # metadata loaded handler
        self.DDFamily.addItems(self.fTool.getFamilies())
        self.statusBar().showMessage('Loading metadata... Done')

    def familySelected(self, index):
        selName = self.DDFamily.currentText()
        self.DDWeight.clear()
        self.DDWeight.addItems(self.fTool.getWeights(selName))

    def weightSelected(self, index):
        selName = self.DDFamily.currentText()
        selWeight = self.DDWeight.currentText()
        worker = bgProc(self.fTool.getCSS, selName, selWeight)
        worker.signals.result.connect(self.cssLoaded)
        self.threadPool.start(worker)

        self.statusBar().showMessage('Retrieving CSS')

    def cssLoaded(self, css):
        print('CSS', css)
        pcss = self.fTool.getParsedCSS(css)
        au = self.fTool.getFontAllURIs(pcss)
        fancyName = self.fTool.getFontFullNames(pcss.rules)
        sName = self.fTool.selectSimplestName(fancyName)

        worker = bgProc(self.fTool.getFontBitStreams, au)
        worker.signals.result.connect(self.bsLoaded)
        self.threadPool.start(worker)

        self.statusBar().showMessage('Retrieving font')

    def bsLoaded(self, bs):
        self.statusBar().showMessage('Font loaded')
        key = list(bs.keys())[0]
        self.ttf = QtCore.QByteArray()
        bio = QtCore.QBuffer(self.ttf)
        bio.open(QtCore.QIODevice.WriteOnly)
        self.fTool.mergeBitStreams(bs[key], bio)
        self.statusBar().showMessage('Font merged')
        self.fdb = QFontDatabase()
        insertion = self.fdb.addApplicationFontFromData(self.ttf)
        print('Insertion:', insertion)
        if insertion == -1:
            print('Failed to insert font into database')
        fName = key[0]
        fWeight = key[1]
        print('Converted bitstream to ttf for:', fName, fWeight)
        print('Bitstream keys:', bs.keys())
        if type(fWeight) == str and fWeight[-1] == 'i':
            fWeight = fWeight[:-1]
            italic = True
        else:
            italic = False

        styles = self.fdb.styles(fName)
        print('styles', styles)
        print(fWeight, italic)
        for s in styles:
            print('s:', s)
            print('s weight:', self.fdb.weight(fName, s))
            print('s italic:', self.fdb.italic(fName, s))
            if self.fdb.weight(fName, s) == self.fTool.CSS2QtFontWeight(
                    fWeight) and self.fdb.italic(fName, s) == italic:
                thisStyle = s
                break
            else:
                thisStyle = None
        print(thisStyle)
        font = self.fdb.font(fName, thisStyle, 40)
        self.SampleText.setFont(font)
예제 #11
0
파일: fonts_test.py 프로젝트: B-Rich/PPQT2
myfdb = QFontDatabase()
genqf = myfdb.systemFont(QFontDatabase.GeneralFont)
fonts.initialize(settings)
assert same_font(genqf,fonts.get_general())
monqf = fonts.get_fixed()
dbg = monqf.family()
assert monqf.family() == 'Liberation Mono'
assert monqf.pointSize() == C.DEFAULT_FONT_SIZE
SIGBOOL = None
def slot(boola):
    global SIGBOOL
    SIGBOOL = boola
fonts.notify_me(slot)
fonts.set_general(genqf) # should be no signal
assert SIGBOOL is None
palqf = myfdb.font('Palatino','Normal',18)
fonts.set_general(palqf) # should cause signal(false)
assert SIGBOOL == False # altho None is never true, it isn't False
couqf = myfdb.font('Courier','Normal',17)
fonts.set_fixed(couqf) # should cause signal(true)
assert SIGBOOL
# check shutdown
fonts.shutdown(settings)
assert settings.value('fonts/general_family') == palqf.family()
assert settings.value('fonts/mono_family') == couqf.family()
assert settings.value('fonts/general_size') == palqf.pointSize()
assert settings.value('fonts/mono_size') == couqf.pointSize()
# check scale
ps = genqf.pointSize()
genqf = fonts.scale(C.CTL_SHFT_EQUAL, genqf)
assert (ps+1) == genqf.pointSize()
예제 #12
0
파일: HUD.py 프로젝트: wangyeee/MiniGCS
    def __init__(self, parent = None):
        super().__init__(parent)
        self.yawInt = 0.0
        self.mode = 'UNKNOWN MODE'
        self.state = 'UNKNOWN STATE'
        self.fuelStatus = '00.0V (00m:00s)'
        self.xCenterOffset = 0.0
        self.yCenterOffset = 0.0
        self.vwidth = HUD.DEFAULT_VWIDTH
        self.vheight = 150.0
        self.vGaugeSpacing = 65.0
        self.vPitchPerDeg = 6.0 # 4 mm y translation per degree
        self.rawBuffer1 = None
        self.rawBuffer2 = None
        self.rawImage = None
        self.rawLastIndex = 0
        self.rawExpectedBytes = 0
        self.bytesPerLine = 1
        self.imageStarted = False
        self.receivedDepth = 8
        self.receivedChannels = 1
        self.receivedWidth = 640
        self.receivedHeight = 480
        self.warningBlinkRate = 5

        self.noCamera = True
        self.hardwareAcceleration = True
        self.strongStrokeWidth = 1.5
        self.normalStrokeWidth = 1.0
        self.fineStrokeWidth = 0.5
        self.waypointName = ''
        self.roll = 0.0
        self.pitch = 0.0
        self.yaw = 0.0
        self.rollLP = 0.0
        self.pitchLP = 0.0
        self.yawLP = 0.0
        self.yawDiff = 0.0
        self.xPos = 0.0
        self.yPos = 0.0
        self.zPos = 0.0
        self.xSpeed = 0.0
        self.ySpeed = 0.0
        self.zSpeed = 0.0
        self.lastSpeedUpdate = 0
        self.totalSpeed = 0.0
        self.totalAcc = 0.0
        self.lat = 0.0
        self.lon = 0.0
        self.alt = 0.0
        self.desiredRoll = 0.0
        self.desiredPitch = 0.0
        self.desiredHeading = 0.0
        self.targetBearing = 0.0
        self.wpDist = 0.0
        self.load = 0.0
        self.videoRecording = ''
        self.nextOfflineImage = ''
        self.HUDInstrumentsEnabled = True
        self.videoEnabled = False
        self.imageLoggingEnabled = False
        self.imageLogCounter = 0
        self.imageLogDirectory = None
        self.xImageFactor = 1.0
        self.yImageFactor = 1.0
        self.imageRequested = False

        self.videoSrc = None
        self.videoStarted = False
        self.updateInterval = 100

        self.defaultColor = None
        self.setPointColor = None
        self.warningColor = None
        self.criticalColor = None
        self.infoColor = None
        self.fuelColor = None
        self.DEFAULT_BACKGROUND_IMAGE = None

        self.enableHUDAction: QAction = None
        self.enableVideoAction: QAction = None
        self.selectOfflineDirectoryAction: QAction = None

        self.attitudes = {}
        self.uas = None
        self.refreshTimer = QTimer(self)
        # Set auto fill to False
        self.setAutoFillBackground(False)

        # Set minimum size
        self.setMinimumSize(80, 60)
        # Set preferred size
        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.scalingFactor = self.width()/self.vwidth

        # Set up the initial color theme. This can be updated by a styleChanged
        # signal from MainWindow.
        self.styleChanged()
        self.glImage = self.DEFAULT_BACKGROUND_IMAGE

        # Refresh timer
        self.refreshTimer.setInterval(self.updateInterval)
        self.refreshTimer.timeout.connect(self.repaint)

        # Resize to correct size and fill with image
        QWidget.resize(self, self.width(), self.height())

        fontDatabase = QFontDatabase()
        fontFileName = './res/vera.ttf' # Font file is part of the QRC file and compiled into the app
        fontFamilyName = 'Bitstream Vera Sans'

        fontDatabase.addApplicationFont(fontFileName)
        font = fontDatabase.font(fontFamilyName, 'Roman', max(5, int(10.0 * self.scalingFactor * 1.2 + 0.5)))
        if font == None:
            print('ERROR! FONT NOT LOADED!')
        if font.family() != fontFamilyName:
            print('ERROR! WRONG FONT LOADED: {}'.format(fontFamilyName))
        self.createActions()
예제 #13
0
monqf = fonts.get_fixed()
dbg = monqf.family()
assert monqf.family() == 'Liberation Mono'
assert monqf.pointSize() == C.DEFAULT_FONT_SIZE
SIGBOOL = None


def slot(boola):
    global SIGBOOL
    SIGBOOL = boola


fonts.notify_me(slot)
fonts.set_general(genqf)  # should be no signal
assert SIGBOOL is None
palqf = myfdb.font('Palatino', 'Normal', 18)
fonts.set_general(palqf)  # should cause signal(false)
assert SIGBOOL == False  # altho None is never true, it isn't False
couqf = myfdb.font('Courier', 'Normal', 17)
fonts.set_fixed(couqf)  # should cause signal(true)
assert SIGBOOL
# check shutdown
fonts.shutdown(T.settings)
assert T.settings.value('fonts/general_family') == palqf.family()
assert T.settings.value('fonts/mono_family') == couqf.family()
assert T.settings.value('fonts/general_size') == palqf.pointSize()
assert T.settings.value('fonts/mono_size') == couqf.pointSize()
T.settings.clear()
# check scale
ps = genqf.pointSize()
genqf = fonts.scale(C.CTL_SHFT_EQUAL, genqf)