File: font.py

package info (click to toggle)
python-pyqtgraph 0.13.7-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,068 kB
  • sloc: python: 54,043; makefile: 129; ansic: 40; sh: 2
file content (40 lines) | stat: -rw-r--r-- 1,211 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from ...Qt import QtGui, QtWidgets
from ..Parameter import Parameter
from .basetypes import WidgetParameterItem


class FontParameterItem(WidgetParameterItem):
    def makeWidget(self):
        w = QtWidgets.QFontComboBox()
        w.setMaximumHeight(20)
        w.sigChanged = w.currentFontChanged
        w.value = w.currentFont
        w.setValue = w.setCurrentFont
        self.hideWidget = False
        return w

    def updateDisplayLabel(self, value=None):
        if value is None:
            value = self.widget.currentText()
        super().updateDisplayLabel(value)


class FontParameter(Parameter):
    """
    Creates and controls a QFont value. Be careful when selecting options from the font dropdown. since not all
    fonts are available on all systems
    """
    itemClass = FontParameterItem

    def _interpretValue(self, v):
        if isinstance(v, str):
            newVal = QtGui.QFont()
            if not newVal.fromString(v):
                raise ValueError(f'Error parsing font "{v}"')
            v = newVal
        return v

    def saveState(self, filter=None):
        state = super().saveState(filter)
        state['value'] = state['value'].toString()
        return state