def available_font_families() -> List: """ Function returns list of available font families. Can be used to instantiate font combo boxes. Returns ------- fonts: list List of available font families. """ if not QApplication.instance(): _ = QApplication(sys.argv) fonts = QFontDatabase().families() default = fonts.pop(fonts.index(default_font_family())) defaults = [default] guessed_name = default.split()[0] i = 0 while i < len(fonts): if fonts[i].startswith(guessed_name): defaults.append(fonts.pop(i)) else: i += 1 return FontList(defaults + [""] + sorted(fonts, key=lambda s: s.replace(".", "")))
def __init__(self, parent=None, **kwargs): super().__init__(parent, **kwargs) self.setDocumentLayout(QPlainTextDocumentLayout(self)) self.__currentCharFormat = QTextCharFormat() if 'defaultFont' not in kwargs: defaultFont = QFontDatabase.systemFont(QFontDatabase.FixedFont) self.setDefaultFont(defaultFont) self.__streams = []
def __init__(self, *args, **kwargs): # type: (Any, Any) -> None super().__init__(*args, **kwargs) self.setFrameStyle(QPlainTextEdit.NoFrame) self.setTextInteractionFlags(Qt.TextBrowserInteraction) self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) font = QFontDatabase.systemFont(QFontDatabase.FixedFont) self.setFont(font) self.setAttribute(Qt.WA_SetFont, False)
def available_font_families() -> List: """ Function returns list of available font families. Can be used to instantiate font combo boxes. Returns ------- fonts: list List of available font families. """ if not QApplication.instance(): _ = QApplication(sys.argv) return QFontDatabase().families()
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.setFrameStyle(QPlainTextEdit.NoFrame) self.setTextInteractionFlags(Qt.TextBrowserInteraction) self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) try: # Since Qt 5.2 font = QFontDatabase.systemFont(QFontDatabase.FixedFont) except AttributeError: font = self.font() font.setStyleHint(QFont.Monospace) font.setFamily("Monospace") self.setFont(font) self.setAttribute(Qt.WA_SetFont, False)
def load_icons_font(): fontId = QFontDatabase.addApplicationFont( join(dirname(__file__), 'icons', 'TimeSlice-icons.ttf')) font_family = QFontDatabase.applicationFontFamilies(fontId)[0] return QFont(font_family, 9, QFont.Normal)
def __init__(self): def update_font_family(**settings): for label in self.initial_settings[self.LABELS_BOX]: if label != self.FONT_FAMILY_LABEL: setter = self._setters[self.LABELS_BOX][label] setter(**settings) def update_title(**settings): Updater.update_plot_title_font(self.title_item, **settings) def update_label(**settings): self.label_font = Updater.change_font(self.label_font, settings) Updater.update_label_font(self.labels, self.label_font) def update_axes_titles(**settings): Updater.update_axes_titles_font(self.axis_items, **settings) def update_axes_ticks(**settings): Updater.update_axes_ticks_font(self.axis_items, **settings) def update_legend(**settings): self.legend_settings.update(**settings) Updater.update_legend_font(self.legend_items, **settings) def update_title_text(**settings): Updater.update_plot_title_text(self.title_item, settings[self.TITLE_LABEL]) def update_axis(axis, **settings): Updater.update_axis_title_text(self.getAxis(axis), settings[self.TITLE_LABEL]) self.FONT_FAMILY_SETTING: SettingsType = { # pylint: disable=invalid-name Updater.FONT_FAMILY_LABEL: (QFontDatabase().families(), QFont().family()), } self.FONT_SETTING: SettingsType = { # pylint: disable=invalid-name Updater.SIZE_LABEL: (range(4, 50), QFont().pointSize()), Updater.IS_ITALIC_LABEL: (None, False) } self.label_font = QFont() self.legend_settings = {} self._setters = { self.LABELS_BOX: { self.FONT_FAMILY_LABEL: update_font_family, self.TITLE_LABEL: update_title, self.LABEL_LABEL: update_label, self.AXIS_TITLE_LABEL: update_axes_titles, self.AXIS_TICKS_LABEL: update_axes_ticks, self.LEGEND_LABEL: update_legend, }, self.ANNOT_BOX: { self.TITLE_LABEL: update_title_text, self.X_AXIS_LABEL: lambda **kw: update_axis("bottom", **kw), self.Y_AXIS_LABEL: lambda **kw: update_axis("left", **kw), } } self.initial_settings: Dict[str, Dict[str, SettingsType]] = NotImplemented self.update_setters() self._check_setters()
def test_qfontdatabase_static(self): families = QFontDatabase.families() styles = QFontDatabase.styles(families[0]) systems = QFontDatabase.writingSystems() systems = QFontDatabase.writingSystems(families[0])