def test_font_coercion(family, size, weight, style, variant, stretch): """Test the font parsing produce the expected font objects. """ font = ' '.join([style, variant, weight, stretch, size, family]) font = ' '.join(font.split()) # Handle multiple whitespaces print('CSS3 font: ', font) font = coerce_font(font) assert isinstance(font, Font) assert repr(font) assert font.family == family if size in _SIZES: assert font.pointsize == _SIZES[size] else: pt_size = (_UNITS[size[-2:]](int(size[:-2])) if len(size) > 2 else int(size)) assert font.pointsize == pt_size assert font.weight == _WEIGHTS[weight or 'normal'] assert font.style == _STYLES[style or 'normal'] assert font.caps == _VARIANTS[variant or 'normal'] assert font.stretch == _STRETCH[stretch or 'normal'] assert font._tkdata is None try: from enaml.qt.q_resource_helpers import get_cached_qfont except Exception: return get_cached_qfont(font) assert font._tkdata is not None
def set_font(self, font): """ Set the font of the widget. """ if font is not None: self.widget.setFont(get_cached_qfont(font)) else: self.widget.setFont(QFont())
def _update_font(self, change=None): if self._text_edit: if self.text_font is not None: qfont = get_cached_qfont(self.text_font) else: qfont = QFont() document = self._text_edit.document() document.setDefaultFont(qfont) fm = QFontMetrics(qfont) self._text_edit.setTabStopWidth(self.tab_width * fm.width(' '))
def set_font(self, font): self.widget.setFont(get_cached_qfont(font))
def set_font_label(self, font): if font is not None: self.font_label = get_cached_qfont(font) else: self.font_label = QtGui.QFont("Ubuntu", 8) self.font_label.setStyleStrategy(QtGui.QFont.ForceOutline)
def set_font_title(self, font): if font is not None: self.font_title = get_cached_qfont(font) else: self.font_title = QtGui.QFont("Ubuntu", 10) self.widget.title_item.setFont(self.font_title)