From 7fe23d9e58d3e2ab67f19f043b45ece4484cc180 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Sun, 21 Mar 2021 15:29:32 +0000 Subject: [PATCH] Enhancement #1920574: allow changing fonts in the templat tester --- src/calibre/gui2/dialogs/template_dialog.py | 27 ++- src/calibre/gui2/dialogs/template_dialog.ui | 244 ++++++++++---------- 2 files changed, 151 insertions(+), 120 deletions(-) diff --git a/src/calibre/gui2/dialogs/template_dialog.py b/src/calibre/gui2/dialogs/template_dialog.py index 0bd30367b2..5b5cfddd57 100644 --- a/src/calibre/gui2/dialogs/template_dialog.py +++ b/src/calibre/gui2/dialogs/template_dialog.py @@ -9,7 +9,8 @@ import json, os, traceback from qt.core import (Qt, QDialog, QDialogButtonBox, QSyntaxHighlighter, QFont, QRegExp, QApplication, QTextCharFormat, QColor, QCursor, - QIcon, QSize, QPalette, QLineEdit, QByteArray) + QIcon, QSize, QPalette, QLineEdit, QByteArray, + QFontInfo, QFontDatabase) from calibre import sanitize_file_name from calibre.constants import config_dir @@ -81,8 +82,9 @@ class TemplateHighlighter(QSyntaxHighlighter): self.highlighted_paren = False def initializeFormats(self): + font = gprefs.get('gpm_template_editor_font', 'monospace') Config = self.Config - Config["fontfamily"] = "monospace" + Config["fontfamily"] = font pal = QApplication.instance().palette() for name, color, bold, italic in ( ("normal", None, False, False), @@ -408,8 +410,7 @@ class TemplateDialog(QDialog, Ui_TemplateDialog): '%s' % ( localize_user_manual_link('https://manual.calibre-ebook.com/generated/en/template_ref.html'), tt)) - self.font_size_box.setValue(gprefs['gpm_template_editor_font_size']) - self.font_size_box.valueChanged.connect(self.font_size_changed) + self.set_up_font_boxes() self.textbox.setFocus() # Now geometry try: @@ -419,6 +420,24 @@ class TemplateDialog(QDialog, Ui_TemplateDialog): except Exception: pass + def set_up_font_boxes(self): + family = gprefs.get('gpm_template_editor_font', 'monospace') + size = gprefs['gpm_template_editor_font_size'] + font = QFont(family, pointSize=size) + self.font_box.setWritingSystem(QFontDatabase.Latin) + self.font_box.setCurrentFont(font) + self.font_box.setEditable(False) + self.font_box.currentFontChanged.connect(self.font_changed) + self.font_size_box.setValue(gprefs['gpm_template_editor_font_size']) + self.font_size_box.valueChanged.connect(self.font_size_changed) + + def font_changed(self, font): + fi = QFontInfo(font) + gprefs['gpm_template_editor_font_size'] = fi.pointSize() + gprefs['gpm_template_editor_font'] = unicode_type(fi.family()) + self.highlighter.initializeFormats() + self.highlighter.rehighlight() + def font_size_changed(self, toWhat): gprefs['gpm_template_editor_font_size'] = toWhat self.highlighter.initializeFormats() diff --git a/src/calibre/gui2/dialogs/template_dialog.ui b/src/calibre/gui2/dialogs/template_dialog.ui index 06a116dd5d..709bf30039 100644 --- a/src/calibre/gui2/dialogs/template_dialog.ui +++ b/src/calibre/gui2/dialogs/template_dialog.ui @@ -380,43 +380,54 @@ - - - - Font size: - - - - - - - + + + + + + Current font: + + + font_box + + - - - - Qt::Horizontal + + + + Select the font for the Template box - - - 0 - 0 - - - + - - - - Qt::Horizontal + + + + Size: - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + font_size_box + + + + + + + Select the font size for the Template box + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + @@ -424,94 +435,95 @@ - - - - Template Function Reference - - - function - - - - - - - Function &name: - - - function - - - - - - - - - - &Function type: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - func_type - - - - - - - true - - - - - - - &Documentation: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - documentation - - - - - - - &Code: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - source_code - - - - - - - - 16777215 - 75 - - - - - - - - - 16777215 - 75 - - - + + + + + + Template Function Reference + + + + + + + Function &name: + + + function + + + + + + + + + + &Function type: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + func_type + + + + + + + true + + + + + + + &Documentation: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + documentation + + + + + + + + 16777215 + 75 + + + + + + + + &Code: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + source_code + + + + + + + + 16777215 + 75 + + + + +