From 047af20cbff2fcc734b65466392f378de0d8a1a6 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Thu, 26 Jun 2014 09:46:42 +0200 Subject: [PATCH 1/2] Add a tweak to change the font size in the template editor --- resources/default_tweaks.py | 6 ++++++ src/calibre/gui2/dialogs/template_dialog.py | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py index ae595a7cf8..6ad1ac3a27 100644 --- a/resources/default_tweaks.py +++ b/resources/default_tweaks.py @@ -501,6 +501,12 @@ change_book_details_font_size_by = 0 # No compile: compile_gpm_templates = False compile_gpm_templates = True +#: Change the font size in the General Program Mode template editor +# Change the font size used when editing GPM templates. This changes the size +# of the font in the editing pane. Set it to a positive or +# negative number to increase or decrease the font size. +change_template_editor_font_size_by = 0 + #: What format to default to when using the Tweak feature # The Tweak feature of calibre allows direct editing of a book format. # If multiple formats are available, calibre will offer you a choice diff --git a/src/calibre/gui2/dialogs/template_dialog.py b/src/calibre/gui2/dialogs/template_dialog.py index 5a43c3481a..dd20b9e306 100644 --- a/src/calibre/gui2/dialogs/template_dialog.py +++ b/src/calibre/gui2/dialogs/template_dialog.py @@ -12,6 +12,7 @@ from PyQt4.Qt import (Qt, QDialog, QDialogButtonBox, QSyntaxHighlighter, QFont, from calibre import sanitize_file_name_unicode from calibre.constants import config_dir from calibre.gui2.dialogs.template_dialog_ui import Ui_TemplateDialog +from calibre.utils.config_base import tweaks from calibre.utils.formatter_functions import formatter_functions from calibre.utils.icu import sort_key from calibre.ebooks.metadata.book.base import Metadata @@ -75,7 +76,6 @@ class TemplateHighlighter(QSyntaxHighlighter): def initializeFormats(self): Config = self.Config Config["fontfamily"] = "monospace" - #Config["fontsize"] = 10 for name, color, bold, italic in ( ("normal", "#000000", False, False), ("keyword", "#000080", True, False), @@ -91,7 +91,9 @@ class TemplateHighlighter(QSyntaxHighlighter): baseFormat = QTextCharFormat() baseFormat.setFontFamily(Config["fontfamily"]) - #baseFormat.setFontPointSize(Config["fontsize"]) + Config["fontsize"] = (baseFormat.font().pointSize() + + tweaks['change_template_editor_font_size_by']) + baseFormat.setFontPointSize(Config["fontsize"]) for name in ("normal", "keyword", "builtin", "comment", "string", "number", "lparen", "rparen"): From fa55b10c4265589a725ebe766e73627a10e813e6 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Thu, 26 Jun 2014 11:10:46 +0200 Subject: [PATCH 2/2] Removed template editor font size tweak. Added a font size spin box. --- resources/default_tweaks.py | 6 -- src/calibre/gui2/__init__.py | 1 + src/calibre/gui2/dialogs/template_dialog.py | 14 +++-- src/calibre/gui2/dialogs/template_dialog.ui | 64 ++++++++++++++++----- 4 files changed, 60 insertions(+), 25 deletions(-) diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py index 6ad1ac3a27..ae595a7cf8 100644 --- a/resources/default_tweaks.py +++ b/resources/default_tweaks.py @@ -501,12 +501,6 @@ change_book_details_font_size_by = 0 # No compile: compile_gpm_templates = False compile_gpm_templates = True -#: Change the font size in the General Program Mode template editor -# Change the font size used when editing GPM templates. This changes the size -# of the font in the editing pane. Set it to a positive or -# negative number to increase or decrease the font size. -change_template_editor_font_size_by = 0 - #: What format to default to when using the Tweak feature # The Tweak feature of calibre allows direct editing of a book format. # If multiple formats are available, calibre will offer you a choice diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index 374a872ef7..2068a3a6da 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -127,6 +127,7 @@ defs['show_highlight_toggle_button'] = False defs['add_comments_to_email'] = False defs['cb_preserve_aspect_ratio'] = False defs['show_rating_in_cover_browser'] = True +defs['gpm_template_editor_font_size'] = 10 del defs # }}} diff --git a/src/calibre/gui2/dialogs/template_dialog.py b/src/calibre/gui2/dialogs/template_dialog.py index dd20b9e306..3960c62289 100644 --- a/src/calibre/gui2/dialogs/template_dialog.py +++ b/src/calibre/gui2/dialogs/template_dialog.py @@ -11,8 +11,8 @@ from PyQt4.Qt import (Qt, QDialog, QDialogButtonBox, QSyntaxHighlighter, QFont, from calibre import sanitize_file_name_unicode from calibre.constants import config_dir +from calibre.gui2 import gprefs from calibre.gui2.dialogs.template_dialog_ui import Ui_TemplateDialog -from calibre.utils.config_base import tweaks from calibre.utils.formatter_functions import formatter_functions from calibre.utils.icu import sort_key from calibre.ebooks.metadata.book.base import Metadata @@ -88,11 +88,9 @@ class TemplateHighlighter(QSyntaxHighlighter): Config["%sfontcolor" % name] = color Config["%sfontbold" % name] = bold Config["%sfontitalic" % name] = italic - baseFormat = QTextCharFormat() baseFormat.setFontFamily(Config["fontfamily"]) - Config["fontsize"] = (baseFormat.font().pointSize() + - tweaks['change_template_editor_font_size_by']) + Config["fontsize"] = gprefs['gpm_template_editor_font_size'] baseFormat.setFontPointSize(Config["fontsize"]) for name in ("normal", "keyword", "builtin", "comment", @@ -327,6 +325,14 @@ class TemplateDialog(QDialog, Ui_TemplateDialog): '' '%s'%tt) + self.font_size_box.setValue(gprefs['gpm_template_editor_font_size']) + self.font_size_box.valueChanged.connect(self.font_size_changed) + + def font_size_changed(self, toWhat): + gprefs['gpm_template_editor_font_size'] = toWhat + self.highlighter.initializeFormats() + self.highlighter.rehighlight() + def filename_button_clicked(self): try: path = choose_files(self, 'choose_category_icon', diff --git a/src/calibre/gui2/dialogs/template_dialog.ui b/src/calibre/gui2/dialogs/template_dialog.ui index 1cc9f29f66..26d29e4cfe 100644 --- a/src/calibre/gui2/dialogs/template_dialog.ui +++ b/src/calibre/gui2/dialogs/template_dialog.ui @@ -166,17 +166,51 @@ - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + Font size: - + + + + + + + + + Qt::Horizontal + + + + 0 + 0 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + QFrame::HLine + + + + Function &name: @@ -186,10 +220,10 @@ - + - + &Documentation: @@ -202,7 +236,7 @@ - + Python &code: @@ -215,7 +249,7 @@ - + @@ -225,17 +259,17 @@ - + - + true - + true