mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Enhancement #1920574: allow changing fonts in the templat tester
This commit is contained in:
parent
320c525cfe
commit
7fe23d9e58
@ -9,7 +9,8 @@ import json, os, traceback
|
|||||||
|
|
||||||
from qt.core import (Qt, QDialog, QDialogButtonBox, QSyntaxHighlighter, QFont,
|
from qt.core import (Qt, QDialog, QDialogButtonBox, QSyntaxHighlighter, QFont,
|
||||||
QRegExp, QApplication, QTextCharFormat, QColor, QCursor,
|
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 import sanitize_file_name
|
||||||
from calibre.constants import config_dir
|
from calibre.constants import config_dir
|
||||||
@ -81,8 +82,9 @@ class TemplateHighlighter(QSyntaxHighlighter):
|
|||||||
self.highlighted_paren = False
|
self.highlighted_paren = False
|
||||||
|
|
||||||
def initializeFormats(self):
|
def initializeFormats(self):
|
||||||
|
font = gprefs.get('gpm_template_editor_font', 'monospace')
|
||||||
Config = self.Config
|
Config = self.Config
|
||||||
Config["fontfamily"] = "monospace"
|
Config["fontfamily"] = font
|
||||||
pal = QApplication.instance().palette()
|
pal = QApplication.instance().palette()
|
||||||
for name, color, bold, italic in (
|
for name, color, bold, italic in (
|
||||||
("normal", None, False, False),
|
("normal", None, False, False),
|
||||||
@ -408,8 +410,7 @@ class TemplateDialog(QDialog, Ui_TemplateDialog):
|
|||||||
'<a href="%s">%s</a>' % (
|
'<a href="%s">%s</a>' % (
|
||||||
localize_user_manual_link('https://manual.calibre-ebook.com/generated/en/template_ref.html'), tt))
|
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.set_up_font_boxes()
|
||||||
self.font_size_box.valueChanged.connect(self.font_size_changed)
|
|
||||||
self.textbox.setFocus()
|
self.textbox.setFocus()
|
||||||
# Now geometry
|
# Now geometry
|
||||||
try:
|
try:
|
||||||
@ -419,6 +420,24 @@ class TemplateDialog(QDialog, Ui_TemplateDialog):
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
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):
|
def font_size_changed(self, toWhat):
|
||||||
gprefs['gpm_template_editor_font_size'] = toWhat
|
gprefs['gpm_template_editor_font_size'] = toWhat
|
||||||
self.highlighter.initializeFormats()
|
self.highlighter.initializeFormats()
|
||||||
|
@ -380,43 +380,54 @@
|
|||||||
<layout class="BoxLayout" name="user_layout_9" dir="TopToBottom">
|
<layout class="BoxLayout" name="user_layout_9" dir="TopToBottom">
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="20" column="0">
|
<item row="20" column="0" colspan="2">
|
||||||
<widget class="QLabel" name="label">
|
<layout class="QHBoxLayout">
|
||||||
<property name="text">
|
<item>
|
||||||
<string>Font size:</string>
|
<widget class="QLabel" name="font_name_label">
|
||||||
</property>
|
<property name="text">
|
||||||
</widget>
|
<string>Current font:</string>
|
||||||
</item>
|
</property>
|
||||||
<item row="20" column="1" colspan="3">
|
<property name="buddy">
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<cstring>font_box</cstring>
|
||||||
<item row="1" column="0">
|
</property>
|
||||||
<widget class="QSpinBox" name="font_size_box"/>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item>
|
||||||
<spacer>
|
<widget class="QFontComboBox" name="font_box">
|
||||||
<property name="orientation">
|
<property name="toolTip">
|
||||||
<enum>Qt::Horizontal</enum>
|
<string>Select the font for the Template box</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" stdset="0">
|
</widget>
|
||||||
<size>
|
|
||||||
<width>0</width>
|
|
||||||
<height>0</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="2">
|
<item>
|
||||||
<widget class="QDialogButtonBox" name="buttonBox">
|
<widget class="QLabel" name="font_size_label">
|
||||||
<property name="orientation">
|
<property name="text">
|
||||||
<enum>Qt::Horizontal</enum>
|
<string>Size:</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="standardButtons">
|
<property name="buddy">
|
||||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
<cstring>font_size_box</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QSpinBox" name="font_size_box">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Select the font size for the Template box</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="20" column="3">
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item row="21" column="0" colspan="4">
|
<item row="21" column="0" colspan="4">
|
||||||
<widget class="QFrame">
|
<widget class="QFrame">
|
||||||
<property name="frameShape">
|
<property name="frameShape">
|
||||||
@ -424,94 +435,95 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="22" column="0" colspan="2">
|
<item row="22" column="0" colspan="4">
|
||||||
<widget class="QLabel" name="label">
|
<layout class="QGridLayout">
|
||||||
<property name="text">
|
<item row="0" column="0" colspan="2">
|
||||||
<string>Template Function Reference</string>
|
<widget class="QLabel" name="label">
|
||||||
</property>
|
<property name="text">
|
||||||
<property name="buddy">
|
<string>Template Function Reference</string>
|
||||||
<cstring>function</cstring>
|
</property>
|
||||||
</property>
|
</widget>
|
||||||
</widget>
|
</item>
|
||||||
</item>
|
<item row="1" column="0">
|
||||||
<item row="23" column="0">
|
<widget class="QLabel" name="label">
|
||||||
<widget class="QLabel" name="label">
|
<property name="text">
|
||||||
<property name="text">
|
<string>Function &name:</string>
|
||||||
<string>Function &name:</string>
|
</property>
|
||||||
</property>
|
<property name="buddy">
|
||||||
<property name="buddy">
|
<cstring>function</cstring>
|
||||||
<cstring>function</cstring>
|
</property>
|
||||||
</property>
|
</widget>
|
||||||
</widget>
|
</item>
|
||||||
</item>
|
<item row="1" column="1">
|
||||||
<item row="23" column="1" colspan="3">
|
<widget class="QComboBox" name="function"/>
|
||||||
<widget class="QComboBox" name="function"/>
|
</item>
|
||||||
</item>
|
<item row="2" column="0">
|
||||||
<item row="24" column="0">
|
<widget class="QLabel" name="label_22">
|
||||||
<widget class="QLabel" name="label_22">
|
<property name="text">
|
||||||
<property name="text">
|
<string>&Function type:</string>
|
||||||
<string>&Function type:</string>
|
</property>
|
||||||
</property>
|
<property name="alignment">
|
||||||
<property name="alignment">
|
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
</property>
|
||||||
</property>
|
<property name="buddy">
|
||||||
<property name="buddy">
|
<cstring>func_type</cstring>
|
||||||
<cstring>func_type</cstring>
|
</property>
|
||||||
</property>
|
</widget>
|
||||||
</widget>
|
</item>
|
||||||
</item>
|
<item row="2" column="1">
|
||||||
<item row="24" column="1" colspan="3">
|
<widget class="QLineEdit" name="func_type">
|
||||||
<widget class="QLineEdit" name="func_type">
|
<property name="readOnly">
|
||||||
<property name="readOnly">
|
<bool>true</bool>
|
||||||
<bool>true</bool>
|
</property>
|
||||||
</property>
|
</widget>
|
||||||
</widget>
|
</item>
|
||||||
</item>
|
<item row="3" column="0">
|
||||||
<item row="25" column="0">
|
<widget class="QLabel" name="label_2">
|
||||||
<widget class="QLabel" name="label_2">
|
<property name="text">
|
||||||
<property name="text">
|
<string>&Documentation:</string>
|
||||||
<string>&Documentation:</string>
|
</property>
|
||||||
</property>
|
<property name="alignment">
|
||||||
<property name="alignment">
|
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
</property>
|
||||||
</property>
|
<property name="buddy">
|
||||||
<property name="buddy">
|
<cstring>documentation</cstring>
|
||||||
<cstring>documentation</cstring>
|
</property>
|
||||||
</property>
|
</widget>
|
||||||
</widget>
|
</item>
|
||||||
</item>
|
<item row="3" column="1">
|
||||||
<item row="26" column="0">
|
<widget class="QPlainTextEdit" name="documentation">
|
||||||
<widget class="QLabel" name="label_3">
|
<property name="maximumSize">
|
||||||
<property name="text">
|
<size>
|
||||||
<string>&Code:</string>
|
<width>16777215</width>
|
||||||
</property>
|
<height>75</height>
|
||||||
<property name="alignment">
|
</size>
|
||||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
</property>
|
||||||
</property>
|
</widget>
|
||||||
<property name="buddy">
|
</item>
|
||||||
<cstring>source_code</cstring>
|
<item row="4" column="0">
|
||||||
</property>
|
<widget class="QLabel" name="label_3">
|
||||||
</widget>
|
<property name="text">
|
||||||
</item>
|
<string>&Code:</string>
|
||||||
<item row="25" column="1" colspan="3">
|
</property>
|
||||||
<widget class="QPlainTextEdit" name="documentation">
|
<property name="alignment">
|
||||||
<property name="maximumSize">
|
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||||
<size>
|
</property>
|
||||||
<width>16777215</width>
|
<property name="buddy">
|
||||||
<height>75</height>
|
<cstring>source_code</cstring>
|
||||||
</size>
|
</property>
|
||||||
</property>
|
</widget>
|
||||||
</widget>
|
</item>
|
||||||
</item>
|
<item row="4" column="1">
|
||||||
<item row="26" column="1" colspan="3">
|
<widget class="QPlainTextEdit" name="source_code">
|
||||||
<widget class="QPlainTextEdit" name="source_code">
|
<property name="maximumSize">
|
||||||
<property name="maximumSize">
|
<size>
|
||||||
<size>
|
<width>16777215</width>
|
||||||
<width>16777215</width>
|
<height>75</height>
|
||||||
<height>75</height>
|
</size>
|
||||||
</size>
|
</property>
|
||||||
</property>
|
</widget>
|
||||||
</widget>
|
</item>
|
||||||
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="27" column="1">
|
<item row="27" column="1">
|
||||||
<widget class="QLabel" name="template_tutorial">
|
<widget class="QLabel" name="template_tutorial">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user